Terraform depends_on输出返回值



如果EKS集群启动并运行(ACTIVE),我想部署一些helm_release资源。在EKS模块中,我已经导出:cluster_status可以处于以下状态之一CREATING,ACTIVE,DELETING,FAILED

如何使用depends_on以实际值为基础?

depends_on = [module.eks-cluster.cluster_status.active]

的回报:

References in depends_on must be to a whole object (resource, etc), not to an attribute of an object.
输出配置:

output "cluster_status" {
value = module.eks-cluster.cluster_status
}

返回:

cluster_status = "ACTIVE"

!免责声明:此回答没有什么假设,如果没有帮助,需要更多的信息

如错误所示References in depends_on must be to a whole object (resource, etc), not to an attribute of an object.

output "cluster_status" {
value = module.eks-cluster.cluster_status
}

这似乎是在子/接口模块级别,不需要在EKS和Helm版本之间建立依赖关系。

我假设你的代码如下

module "eks-cluster" {
source = "path_to_modue"
[...]
}
resource helm_release some_release {
[..]
}

depends_on元参数适用于整个资源,而不是导出(输出)或提供(输入)的特定属性。

! !假设你正在为helm_release使用一个模块和资源(实际上,即使helm release是子模块也没关系)

depends_on应该是

resource "helm_release" "release" {
[....]
depends_on = [module.eks-cluster] # as this is the complete resource/module on which the helm release is dependent.
}

这将确保仅在EKS集群部署成功时才部署helm版本。

如果你想要非常具体,并且只希望在部署的EKS集群状态为ACTIVE时部署helm_release,你可能需要提出locals{}和count meta参数来控制部署。

这个方法是不推荐的,但是如果你的

  • 即使在成功部署后,状态有时也需要一些时间才能激活
locals {
## assuming that "cluster_status" is the https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_cluster#status output in the root module.
eks_status = module.eks-cluster.cluster_status
}
resource "helm_release" "some_release" {
count = local.eks_status == "ACTIVE" ? 1 : 0
[...] 
}

请注意,你必须用eks模块的输出配置你的helm提供者,以便授权和身份验证到各自的eks集群。

额外信息:

模块支持depends_on是在Terraform 0.13版本中添加的,以前的版本只能在资源中使用它。

最新更新