Hello, I’m new joiner in this community, before I never had a logical problems with HCL, however recently I faced an issue.
I have a resource which should be created only if parent resource is created, I know how to do it with count, but in my case, I have to use for_each
resource "aws_ec2_tag" "tgw_rtbl" {
depends_on = [ aws_ec2_transit_gateway.tgw ]
resource_id = var.create_tgw_gateway ? aws_ec2_transit_gateway.tgw[0].association_default_route_table_id : ""
key = each.key
value = each.value
lifecycle {
create_before_destroy = true
ignore_changes = [ resource_id ]
}
for_each = {
"Name" : local.tag_default_rtbl
"Zone" : upper(var.region)
... omitted ...
}
}
FYI var.create_tgw_gateway = false
How can I implement a condition to skip creation of resource
P.S. Please do not judge my english very strong