{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/18923","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/18923/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/18923/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/18923/events","html_url":"https://github.com/hashicorp/terraform/issues/18923","id":362662438,"node_id":"MDU6SXNzdWUzNjI2NjI0Mzg=","number":18923,"title":"'count' cannot be computed for resource within module based on list of interpolated values","user":{"login":"sgsiebers","id":6051117,"node_id":"MDQ6VXNlcjYwNTExMTc=","avatar_url":"https://avatars0.githubusercontent.com/u/6051117?v=4","gravatar_id":"","url":"https://api.github.com/users/sgsiebers","html_url":"https://github.com/sgsiebers","followers_url":"https://api.github.com/users/sgsiebers/followers","following_url":"https://api.github.com/users/sgsiebers/following{/other_user}","gists_url":"https://api.github.com/users/sgsiebers/gists{/gist_id}","starred_url":"https://api.github.com/users/sgsiebers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgsiebers/subscriptions","organizations_url":"https://api.github.com/users/sgsiebers/orgs","repos_url":"https://api.github.com/users/sgsiebers/repos","events_url":"https://api.github.com/users/sgsiebers/events{/privacy}","received_events_url":"https://api.github.com/users/sgsiebers/received_events","type":"User","site_admin":false},"labels":[{"id":608979767,"node_id":"MDU6TGFiZWw2MDg5Nzk3Njc=","url":"https://api.github.com/repos/hashicorp/terraform/labels/config","name":"config","color":"0e8a16","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-21T15:17:07Z","updated_at":"2018-11-01T01:33:47Z","closed_at":"2018-11-01T01:33:47Z","author_association":"NONE","body":"### Terraform Version\r\n\r\n```\r\nTerraform v0.11.8\r\n```\r\n\r\n### Terraform Configuration Files\r\n\r\n\r\nI have a root module where I'm creating New Relic alert channels to be reused across multiple modules:\r\n```hcl\r\n\r\n## main.tf\r\n\r\nvariable api_key {\r\n    type = \"string\"\r\n}\r\n\r\nprovider \"newrelic\"{\r\n    api_key = \"${var.api_key}\"\r\n}\r\n\r\nresource \"newrelic_alert_channel\" \"SomeEmail\" {\r\n    name = \"Some Email\"\r\n    type = \"email\"\r\n    configuration = {\r\n        recipients              = \"some_email@domain.com\"\r\n        include_json_attachment = \"true\"\r\n    }\r\n}\r\n \r\nresource \"newrelic_alert_channel\" \"SomeEmail2\" {\r\n    name = \"Some Email2\"\r\n    type = \"email\"\r\n    configuration = {\r\n        recipients              = \"some_email2@domain.com\"\r\n        include_json_attachment = \"true\"\r\n    }\r\n} \r\n \r\nmodule \"MyModuleInstance\" {\r\n    api_key = \"${var.api_key}\"\r\n    channelIds = [\"${newrelic_alert_channel.SomeEmail.id}\",\"${newrelic_alert_channel.SomeEmail2.id}\"]\r\n    source = \"./MyModule\"\r\n}\r\n\r\n```\r\n\r\nI need to pass the newrelic_alert_channel resource ID's into a several different modules that will create alert policies and tie them to these channels by ID:\r\n\r\n```hcl\r\n\r\n### MyModule/main.tf\r\nvariable api_key {\r\n    type = \"string\"\r\n    default = \"\"\r\n}\r\n\r\nvariable channelIds{\r\n    type = \"list\"\r\n    default = []\r\n}\r\n\r\nprovider \"newrelic\" {\r\n    api_key = \"${var.api_key}\"\r\n}\r\n\r\nresource \"newrelic_alert_policy\" \"TestPolicy\" {\r\n    name = \"My Alert Policy\"\r\n    incident_preference = \"PER_POLICY\"\r\n}\r\n\r\nresource \"newrelic_alert_policy_channel\" \"TestPolicyChannel\" {\r\n   count = \"${length(var.channelIds)}\"\r\n   policy_id  = \"${newrelic_alert_policy.TestPolicy.id}\"\r\n   channel_id = \"${var.channelIds[count.index]}\"\r\n}\r\n```\r\n\r\n\r\n### Debug Output\r\nhttps://gist.github.com/sgsiebers/932c6afaab82239142942b6de3000b2d\r\n\r\n### Crash Output\r\nNone\r\n\r\n### Expected Behavior\r\n\r\nWhen I pass a list of known fixed size to a module, it should be able to use the length of that list as a count variable on a resource within the module.\r\n\r\n### Actual Behavior\r\n\r\nInstead I get the following error:\r\n\r\n```\r\nError: Error running plan: 1 error(s) occurred:\r\n\r\n* module.MyModuleInstance.newrelic_alert_policy_channel.TestPolicyChannel: newrelic_alert_policy_channel.TestPolicyChannel: value of 'count' cannot be computed\r\n```\r\n\r\nOddly enough, if I change the module instantiation to not use interpolated values within the channel ID list variable, and instead hard code some random numbers, it works just fine.  \r\n\r\n```hcl\r\n## main.tf\r\n...\r\nmodule \"MyModuleInstance\" {\r\n    api_key = \"${var.api_key}\"\r\n    channelIds = [\"123\", \"456\"]\r\n    source = \"./MyModule\"\r\n}\r\n```\r\n\r\nThis tells me that passing a list to the module shouldn't be a problem as it's perfectly able to use the list length to determine the resource count value.  Likewise, I can pass the interpolated channel IDs in the list along with a length variable to use for the count value, and everything works just fine.  So it doesn't appear to be having a problem interpolating the alert channel resource IDs in the root module and creating the channel ID list. Yet when I use the combination of interpolated values in a list, and compute resource count off the list length, it errors out on me.\r\n\r\n\r\n### Steps to Reproduce\r\nSetup code as above\r\n```\r\n.\r\n├── main.tf\r\n└── MyModule\r\n          └── main.tf\r\n\r\nterraform init\r\nterraform apply -var 'api_key=foo'\r\n```\r\n\r\n### Additional Context\r\nNone\r\n\r\n### References\r\nNone"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/434901762","html_url":"https://github.com/hashicorp/terraform/issues/18923#issuecomment-434901762","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/18923","id":434901762,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNDkwMTc2Mg==","user":{"login":"apparentlymart","id":20180,"node_id":"MDQ6VXNlcjIwMTgw","avatar_url":"https://avatars1.githubusercontent.com/u/20180?v=4","gravatar_id":"","url":"https://api.github.com/users/apparentlymart","html_url":"https://github.com/apparentlymart","followers_url":"https://api.github.com/users/apparentlymart/followers","following_url":"https://api.github.com/users/apparentlymart/following{/other_user}","gists_url":"https://api.github.com/users/apparentlymart/gists{/gist_id}","starred_url":"https://api.github.com/users/apparentlymart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apparentlymart/subscriptions","organizations_url":"https://api.github.com/users/apparentlymart/orgs","repos_url":"https://api.github.com/users/apparentlymart/repos","events_url":"https://api.github.com/users/apparentlymart/events{/privacy}","received_events_url":"https://api.github.com/users/apparentlymart/received_events","type":"User","site_admin":false},"created_at":"2018-11-01T01:33:47Z","updated_at":"2018-11-01T01:33:47Z","author_association":"CONTRIBUTOR","body":"Hi @sgsiebers! Sorry for this annoying issue, and for this late response.\r\n\r\nAs @osterman pointed out, this is the same problem as being discussed over in #12570. We've made some progress on it during the v0.12.0 development cycle, but there is still some further work to do as you can see in my comment over there.\r\n\r\nI'm going to close this one just to consolidate the discussion over in #12570. Thanks for reporting this!"}}
{"actor":{"display_login":"apparentlymart"}}