count parameter needs to be able to interpolate variables from modules.
Problem
I've been trying to extend my Terraform examples to support multiple AZs by default. As such, I have an _az_count_ variable output by my module to detect the AZs you have available: https://github.com/terraform-community-modules/tf_aws_availability_zones#outputs And I then want to reuse it for instances, for example here: https://github.com/bobtfish/terraform-vpc/blob/master/main.tf#L37 My example (https://github.com/bobtfish/terraform-example-vpc/tree/master/eucentral1-demo) crashes out with the error: - aws_instance.nat: resource count can't reference module variable: module.vpc.az_count and if I remove this error from the source (hope springs eternal!), I run into: - strconv.ParseInt: parsing "${module.azs.az_count}": invalid syntax This inability to interpolate count variables is a blocker for me being able to write region independent modules - as (for example) I want to be able to allocate one subnet per AZ, writing code like: [code block] Even better, I'd like to be able to interpolate variables out of one module, and into the user variables of another, for example: [code block]
Error Output
error: - aws_instance.nat: resource count can't reference module variable: module.vpc.az_count
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: count parameter needs to be able to interpolate variables from modules.
:+1: Surprised to see I can't do `count = ${var.az_count}` here.
Trust Score
1 verification
- 1
Surprised to see I can't do `count = ${var.az_count}` here.
Surprised to see I can't do `count = ${var.az_count}` here.
Validation
Resolved in hashicorp/terraform GitHub issue #1497. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep