简体   繁体   English

Terraform 没有从远程状态读取安全组 ID

[英]Terraform isn't reading security group IDs from remote state

My terraform module does not read a remote state data source if I use interpolation.如果我使用插值,我的 terraform 模块不会读取远程状态数据源。

This works:这有效:

security_group_ids = [data.terraform_remote_state.sg.outputs.sg_paris_id] security_group_ids = [data.terraform_remote_state.sg.outputs.sg_paris_id]

And when I run terragrunt apply it lists the SG ID but it makes the module pointless as I have to make a module for each VPCE I want to create当我运行 terragrunt apply 时,它会列出 SG ID,但这会使模块变得毫无意义,因为我必须为要创建的每个 VPCE 创建一个模块

This does not work:这不起作用:

security_group_ids = ["data.terraform_remote_state.sg.outputs.sg_${local.city}_id"] security_group_ids = ["data.terraform_remote_state.sg.outputs.sg_${local.city}_id"]

Terragrunt prints "data.terraform_remote_state.sg.outputs.sg_${local.city}_id" in the new plan and returns an error saying it expects 'sg- something' when I apply. Terragrunt 在新计划中打印“data.terraform_remote_state.sg.outputs.sg_${local.city}_id”,并在我申请时返回一个错误,说它需要“sg-something”。

I think it's because security_group_ids is expecting a set not a string, but 'toset' doesn't have any impact.我认为这是因为 security_group_ids 期望的是集合而不是字符串,但 'toset' 没有任何影响。

I'm using TF 0.12.28 and TG 0.23.24我正在使用 TF 0.12.28 和 TG 0.23.24

You aren't using string interpolation correctly.您没有正确使用字符串插值。 You are really just creating a string with the value: "data.terraform_remote_state.sg.outputs.sg_paris.id" .您实际上只是在创建一个值为: "data.terraform_remote_state.sg.outputs.sg_paris.id"的字符串。 At no point are you telling Terraform to actually take that string and lookup the value represented by the data source with that name.您绝不会告诉 Terraform 实际获取该字符串并查找具有该名称的数据源表示的值。

You're going to need to use the Terraform lookup function to accomplish what you are trying to do.您将需要使用 Terraform查找功能来完成您正在尝试做的事情。 There might be a cleaner way to do this in Terraform 1, but not in the old 0.12 version you are running.在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM