I’m trying to output a resource that has been created conditionally using count
.
The code is:
resource "aws_route53_zone" "private" {
count = (terraform.workspace == "prod") ? 1 : 0
name = "prod.example-infra.com"
vpc {
vpc_id = var.vpc_id
}
lifecycle {
ignore_changes = [vpc]
}
}
output "route53_private_prod" {
value = aws_route53_zone.private[count.index].zone_id
}
So that I can refer to that output
in another module: module.route53.route53_private_prod
.
However, when applying those changes I get the following error:
Error: Reference to "count" in non-counted context
│
│ on modules/route53/outputs.tf line 2, in output "route53_private_prod":
│ 2: value = aws_route53_zone.private[count.index].zone_id
│
│ The "count" object can only be used in "module", "resource", and "data" blocks, and only when the "count" argument is set.
I’ve been trying to find a workaround for this but haven’t had any luck. Would appreciate it if you guys could help me out.