I have this terraform code...
// Route53 Zone
module "zones" {
source = "terraform-aws-modules/route53/aws//modules/zones"
version = "~> 1.2.0"
create = var.environment == "PRO" ? true : false
zones = {
"example.com" = {
comment = "example.com (production)"
tags = merge(var.global_tags, { environment = var.environment})
}
}
}
// Route53 Records
module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "~> 1.2.0"
create = var.environment == "PRO" ? true : false
zone_name = keys(module.zones.this_route53_zone_zone_id)[0]
records = [
{
name = "ci"
type = "A"
ttl = 300
records = [
"34.24.14.04",
]
},
]
depends_on = [module.zones]
}
I select a environment different than PRO, so this modules don't create anything but... After run terraform plan I get...
Error: Invalid index
on main.tf line 287, in module "records":
287: zone_name = keys(module.zones.this_route53_zone_zone_id)[0]
|----------------
| module.zones.this_route53_zone_zone_id is object with no attributes
The given key does not identify an element in this collection value.
How can I deal with this? I want to use my code with any value into de variable environment.