Hey all,
Want to be able to get remote state output ( instance ids )and use that in a custom module that creates an ALB .
Existing code works - I can add multiple members with multiple data blocks defined
data “terraform_remote_state” “mydata” {
backend = “s3”
config = {
region = var.region
bucket = “abc-{var.region}-{xxx}-tf-states”
key = “env:/${var.environment}-abc/terraform.tfstate”
}
}module “mymodule” {
members = [
data.terraform_remote_state.mydata.outputs.instance-id]
}
Refactored code throws an error on plan - This object does not have an attribute named instance-id .
locals {
members = {
default = [“env:/{var.environment}-xxx/terraform.tfstate", "env:/{var.environment}-xxy/terraform.tfstate”,]
dev = [“env:/{var.environment}-xxx/terraform.tfstate", "env:/{var.env2}-xxc/terraform.tfstate”]}
}data “terraform_remote_state” “mydata” {
for_each = lookup(local.members, var.env2, “default”)
backend = “s3”
config = {
region = var.region
bucket = “abc-{var.region}-{xxx}-tf-states”
key = each.value
}
}module “mymodule” {
members = [for outputs in data.terraform_remote_state.mydata : outputs.instance-id ]
}