0

My terraform module does not read a remote state data source if I use interpolation.

This works:

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

This does not work:

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.

I think it's because security_group_ids is expecting a set not a string, but 'toset' doesn't have any impact.

I'm using TF 0.12.28 and TG 0.23.24

Dave
  • 29
  • 4

1 Answers1

0

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". At no point are you telling Terraform to actually take that string and lookup the value represented by the data source with that name.

You're going to need to use the Terraform lookup function to accomplish what you are trying to do. There might be a cleaner way to do this in Terraform 1, but not in the old 0.12 version you are running.

security_group_ids = [lookup(data.terraform_remote_state.sg.outputs, "sg_${local.city}_id", null)]
Mark B
  • 183,023
  • 24
  • 297
  • 295