我正在使用列表(对象)(水名称配置)格式的变量部署 AWS Glue 作业列表(水名称)。当 Terraforms 检查部署计划时,即使变量没有更改,它总是会出现差异。我怀疑它默认实现动态变量。
我的实现代码如下:
resource "aws_glue_job" "water-name" {
count = length(var.funny-name-configs)
name = "water-name-${var.water-name-configs[count.index].table_name}"
description = "water-name-${var.water-name-configs[count.index].table_name}"
你能检查一下我哪里出错了吗?
我确实尝试向作业添加依赖项。
depends_on = [var.water_name]
我希望能够避免重做所有 terrafrom 代码,为数组 water-name 的每个元素声明一个变量。
我测试了您的代码,组成了变量的内容和其余代码:
variable "funny-name-configs" {
default = ["a", "b"]
}
variable "water-name-configs" {
default = [{table_name:"a"},{table_name:"b"}]
}
resource "aws_glue_job" "water-name" {
count = length(var.funny-name-configs)
name = "water-name-${var.water-name-configs[count.index].table_name}"
description = "water-name-${var.water-name-configs[count.index].table_name}"
role_arn = "arn:aws:iam::621655500000:role/aws-service-role/support/AX"
command {
script_location = "s3://foo/example.py"
}
}
如果我运行多个应用,我们可以看到它第一次创建资源,并且以下应用看不到任何变化
Plan: 2 to add, 0 to change, 0 to destroy.
aws_glue_job.water-name[0]: Creating...
aws_glue_job.water-name[1]: Creating...
aws_glue_job.water-name[1]: Creation complete after 0s [id=water-name-b]
aws_glue_job.water-name[0]: Creation complete after 0s [id=water-name-a]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
heldersepu@bat: terraform apply
aws_glue_job.water-name[1]: Refreshing state... [id=water-name-b]
aws_glue_job.water-name[0]: Refreshing state... [id=water-name-a]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
heldersepu@bat: terraform apply
aws_glue_job.water-name[0]: Refreshing state... [id=water-name-a]
aws_glue_job.water-name[1]: Refreshing state... [id=water-name-b]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
您的示例中一定还有其他内容未提供