FG
☁️ Cloud & DevOps

count parameter needs to be able to interpolate variables from modules.

Freshabout 9 years ago
Mar 14, 20260 views
Confidence Score89%
89%

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

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: count parameter needs to be able to interpolate variables from modules.

Low Risk

:+1: Surprised to see I can't do `count = ${var.az_count}` here.

84

Trust Score

1 verification

100% success
  1. 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

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

terraformiacawsenhancementcore