![](/img/trans.png)
[英]Terraform config isn't using output from other file for already created resource, instead tries to recreate it and fails (security group id)
[英]Terraform isn't reading security group IDs from remote state
如果我使用插值,我的 terraform 模块不会读取远程状态数据源。
这有效:
security_group_ids = [data.terraform_remote_state.sg.outputs.sg_paris_id]
当我运行 terragrunt apply 时,它会列出 SG ID,但这会使模块变得毫无意义,因为我必须为要创建的每个 VPCE 创建一个模块
这不起作用:
security_group_ids = ["data.terraform_remote_state.sg.outputs.sg_${local.city}_id"]
Terragrunt 在新计划中打印“data.terraform_remote_state.sg.outputs.sg_${local.city}_id”,并在我申请时返回一个错误,说它需要“sg-something”。
我认为这是因为 security_group_ids 期望的是集合而不是字符串,但 'toset' 没有任何影响。
我正在使用 TF 0.12.28 和 TG 0.23.24
您没有正确使用字符串插值。 您实际上只是在创建一个值为: "data.terraform_remote_state.sg.outputs.sg_paris.id"
的字符串。 您绝不会告诉 Terraform 实际获取该字符串并查找具有该名称的数据源表示的值。
您将需要使用 Terraform查找功能来完成您正在尝试做的事情。 在 Terraform 1 中可能有更简洁的方法来执行此操作,但在您正在运行的旧 0.12 版本中没有。
security_group_ids = [lookup(data.terraform_remote_state.sg.outputs, "sg_${local.city}_id", null)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.