I have a similiar question getting the error:
" The “for_each” map includes keys derived from resource attributes that
cannot be determined until apply, and so Terraform cannot determine the
full set of keys that will identify the instances of this resource.
When working with unknown values in for_each, it’s better to define the map
keys statically in your configuration and place apply-time results only in
the map values.
"
I have code that’s going to conditionally assign an IPv6 CIDR to an AWS VPC based on a Boolean key/value pair in tfvars. That’s all fine and works. I’m passing this variable to the subnets module, and get the error above when testing with terraform plan. How could I possibly get around this, based on this resource block in tf subnets.tf
From parent module:
module "subnets" {
source = "../subnets"
vpc_id = aws_vpc.this.id
vpc = var.vpc
v6_cidr_block = aws_vpc.this.ipv6_cidr_block
#vpc_resource = aws_vpc.this
#account = var.account
}
in subnets. Module
resource "aws_subnet" "ipv6_subnets" {
for_each = { for index, subnet in local.subnets_extrapolated : subnet["name"] =>
subnet if var.v6_cidr_block != "" && length(regexall("internet_facing", subnet["name"])) > 0
}
vpc_id = var.vpc_id
availability_zone = each.value.az
ipv6_cidr_block = cidrsubnet(var.v6_cidr_block, 8, each.value.azindex)
assign_ipv6_address_on_creation = true
}
Assuming the only issue is with var.v6_cidr_block …if that is removed, plan builds without error? Any ideas of how I might be able to get around this, since the value of v6_cidr_block (which is the v6 VPC cidr block which will only get assigned conditionally on the tfvars.json Boolean being set to true, and then only on specific public subnets, identified via the regexall) Thanks in advance…