{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/1497","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/1497/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/1497/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/1497/events","html_url":"https://github.com/hashicorp/terraform/issues/1497","id":67924888,"number":1497,"title":"count parameter needs to be able to interpolate variables from modules.","user":{"login":"bobtfish","id":42338,"avatar_url":"https://avatars.githubusercontent.com/u/42338?v=3","gravatar_id":"","url":"https://api.github.com/users/bobtfish","html_url":"https://github.com/bobtfish","followers_url":"https://api.github.com/users/bobtfish/followers","following_url":"https://api.github.com/users/bobtfish/following{/other_user}","gists_url":"https://api.github.com/users/bobtfish/gists{/gist_id}","starred_url":"https://api.github.com/users/bobtfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobtfish/subscriptions","organizations_url":"https://api.github.com/users/bobtfish/orgs","repos_url":"https://api.github.com/users/bobtfish/repos","events_url":"https://api.github.com/users/bobtfish/events{/privacy}","received_events_url":"https://api.github.com/users/bobtfish/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc"},{"url":"https://api.github.com/repos/hashicorp/terraform/labels/enhancement","name":"enhancement","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-12T14:58:03Z","updated_at":"2015-05-27T11:20:29Z","closed_at":null,"body":"I've been trying to extend my Terraform examples to support multiple AZs by default.\r\n\r\nAs such, I have an _az_count_ variable output by my module to detect the AZs you have available:\r\n\r\nhttps://github.com/terraform-community-modules/tf_aws_availability_zones#outputs\r\n\r\nAnd I then want to reuse it for instances, for example here:\r\n\r\nhttps://github.com/bobtfish/terraform-vpc/blob/master/main.tf#L37\r\n\r\nMy example (https://github.com/bobtfish/terraform-example-vpc/tree/master/eucentral1-demo) crashes out with the error:\r\n\r\n* aws_instance.nat: resource count can't reference module variable: module.vpc.az_count\r\n\r\nand if I remove this error from the source (hope springs eternal!), I run into:\r\n\r\n* strconv.ParseInt: parsing \"${module.azs.az_count}\": invalid syntax\r\n\r\nThis 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:\r\n\r\n    module \"azs\" {\r\n        source = \"github.com/terraform-community-modules/tf_aws_availability_zones\"\r\n        account = \"${var.account}\"\r\n        region = \"${var.region}\"\r\n    }\r\n\r\n    resource \"aws_subnet\" \"front\" {\r\n         count = \"${module.vpcs.az_count}\"\r\n         ...\r\n     }     \r\n\r\nEven better, I'd like to be able to interpolate variables out of one module, and into the user variables of another, for example:\r\n\r\n    module \"azs\" {\r\n        source = \"github.com/terraform-community-modules/tf_aws_availability_zones\"\r\n        account = \"${var.account}\"\r\n        region = \"${var.region}\"\r\n    }\r\n\r\n    variable \"az_count\" {\r\n        default = \"${module.azs.az_count}\"\r\n    }\r\n\r\n    resource \"aws_subnet\" \"front\" {\r\n         count = \"${var.az_count}\"\r\n         ...\r\n    }"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/105874601","html_url":"https://github.com/hashicorp/terraform/issues/1497#issuecomment-105874601","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/1497","id":105874601,"user":{"login":"phinze","id":37534,"avatar_url":"https://avatars.githubusercontent.com/u/37534?v=3","gravatar_id":"","url":"https://api.github.com/users/phinze","html_url":"https://github.com/phinze","followers_url":"https://api.github.com/users/phinze/followers","following_url":"https://api.github.com/users/phinze/following{/other_user}","gists_url":"https://api.github.com/users/phinze/gists{/gist_id}","starred_url":"https://api.github.com/users/phinze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phinze/subscriptions","organizations_url":"https://api.github.com/users/phinze/orgs","repos_url":"https://api.github.com/users/phinze/repos","events_url":"https://api.github.com/users/phinze/events{/privacy}","received_events_url":"https://api.github.com/users/phinze/received_events","type":"User","site_admin":false},"created_at":"2015-05-27T11:20:29Z","updated_at":"2015-05-27T11:20:29Z","body":"We should definitely do this, the tricky part comes from the fact that count expansion is currently done statically, before the primary graph walk, which means we can't support \"computed\" counts right now. (A \"computed\" value in TF is one that's flagged as not known until all its dependencies are calculated.)\r\n\r\nRelated: https://github.com/hashicorp/terraform/pull/354 \r\n\r\nSo we'd need to rework resource count expansion to occur \"just in time\" to support this. Probably the right thing to do in the long run, but that's what makes this nontrivial to fix."}}