{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/18573","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/18573/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/18573/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/18573/events","html_url":"https://github.com/hashicorp/terraform/issues/18573","id":346097668,"node_id":"MDU6SXNzdWUzNDYwOTc2Njg=","number":18573,"title":"Duplicate Keys in Maps Get De-Duplicated During Count","user":{"login":"afrazkhan","id":1099710,"node_id":"MDQ6VXNlcjEwOTk3MTA=","avatar_url":"https://avatars0.githubusercontent.com/u/1099710?v=4","gravatar_id":"","url":"https://api.github.com/users/afrazkhan","html_url":"https://github.com/afrazkhan","followers_url":"https://api.github.com/users/afrazkhan/followers","following_url":"https://api.github.com/users/afrazkhan/following{/other_user}","gists_url":"https://api.github.com/users/afrazkhan/gists{/gist_id}","starred_url":"https://api.github.com/users/afrazkhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afrazkhan/subscriptions","organizations_url":"https://api.github.com/users/afrazkhan/orgs","repos_url":"https://api.github.com/users/afrazkhan/repos","events_url":"https://api.github.com/users/afrazkhan/events{/privacy}","received_events_url":"https://api.github.com/users/afrazkhan/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},{"id":85946961,"node_id":"MDU6TGFiZWw4NTk0Njk2MQ==","url":"https://api.github.com/repos/hashicorp/terraform/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-31T09:03:15Z","updated_at":"2018-07-31T19:54:12Z","closed_at":null,"author_association":"NONE","body":"### Terraform Version\r\n```\r\nTerraform v0.11.7\r\n```\r\n\r\n### Terraform Configuration Files\r\nGiven the following as part of a larger module called `dns`:\r\n```hcl\r\n...\r\nresource \"digitalocean_record\" \"this_a_record\" {\r\n  count  = \"${length(var.a_records)}\"\r\n\r\n  domain = \"${var.domain}\"\r\n  type   = \"A\"\r\n  name   = \"${element(keys(var.a_records), count.index)}\"\r\n  value  = \"${lookup(var.a_records, element(keys(var.a_records), count.index))}\"\r\n}\r\n...\r\n```\r\n\r\nBeing used like this:\r\n```hcl\r\nmodule \"example_com_dns\" {\r\n  source = \"./modules/dns\"\r\n\r\n  domain  = \"example.com\"\r\n  main_ip = \"1.2.3.4\"\r\n\r\n  a_records = {\r\n    \"@\" = \"1.2.3.4\"\r\n    \"@\" = \"5.6.7.8\"\r\n    \"@\" = \"9.10.11.12\"\r\n    \"foo\" = \"13.14.15.16\"\r\n    \"bar\" = \"17.18.19.20\"\r\n}\r\n```\r\n\r\n### Actual Behavior\r\nThe `foo` and `bar` records are created as expected; `A` records pointing to `13.14.15.16` and `17.18.19.20` respectively, but `@` is de-duplicated, and only a single `@` record is created. This would be true for any duplicate keys, i.e. if there were 2 `foo` keys in there, then only the last one would survive.\r\n\r\nEither the `keys()` function is de-deplicating keys in the map, or applying one create function over the other. This might seem sensical, but I'll explain below why (when) you wouldn't want this behaviour.\r\n\r\n### Expected Behavior\r\nMultiple records are created for each key, irrespective of whether or not it's a duplicate. This can be achieved by running the code in the module outside of a loop instead, i.e. multiple blocks like this:\r\n\r\n```\r\nresource \"digitalocean_record\" \"at3\" {\r\n  domain = \"example.com\"\r\n  type   = \"A\"\r\n  name   = \"@\"\r\n  value  = \"1.2.3.4\"\r\n}\r\n```\r\n\r\nwill result in multiple `@` records with the correct values.\r\n\r\nYou would want this behaviour in situations where the same key can have multiple values, such as with multiple `@` records."},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/409347037","html_url":"https://github.com/hashicorp/terraform/issues/18573#issuecomment-409347037","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/18573","id":409347037,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTM0NzAzNw==","user":{"login":"afrazkhan","id":1099710,"node_id":"MDQ6VXNlcjEwOTk3MTA=","avatar_url":"https://avatars0.githubusercontent.com/u/1099710?v=4","gravatar_id":"","url":"https://api.github.com/users/afrazkhan","html_url":"https://github.com/afrazkhan","followers_url":"https://api.github.com/users/afrazkhan/followers","following_url":"https://api.github.com/users/afrazkhan/following{/other_user}","gists_url":"https://api.github.com/users/afrazkhan/gists{/gist_id}","starred_url":"https://api.github.com/users/afrazkhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afrazkhan/subscriptions","organizations_url":"https://api.github.com/users/afrazkhan/orgs","repos_url":"https://api.github.com/users/afrazkhan/repos","events_url":"https://api.github.com/users/afrazkhan/events{/privacy}","received_events_url":"https://api.github.com/users/afrazkhan/received_events","type":"User","site_admin":false},"created_at":"2018-07-31T19:54:12Z","updated_at":"2018-07-31T19:54:12Z","author_association":"NONE","body":"Yup, I've been reading about 0.12 for a while, and am looking forward to it.\r\n\r\nI don't think that map is valid though? There's no assignment from a key to a value.\r\n\r\n```\r\n  a_records = {\r\n    [\"@\", \"1.2.3.4\"],\r\n    [\"@\", \"5.6.7.8\"],\r\n    [\"@\", \"9.10.11.12\"],\r\n    [\"foo\", \"13.14.15.16\"],\r\n    [\"bar\", \"17.18.19.20\"],\r\n  }\r\n```\r\n\r\nThat's not a valid map, is it? Running it gives me `expected: IDENT | STRING | ASSIGN | LBRACE got: LBRACK`.\r\n\r\nI thought maybe you meant a list of a lists:\r\n\r\n```\r\n  new_a_records = [\r\n    [\"@\", \"1.2.3.4\"],\r\n    [\"@\", \"5.6.7.8\"],\r\n    [\"@\", \"9.10.11.12\"],\r\n    [\"foo\", \"13.14.15.16\"],\r\n    [\"bar\", \"17.18.19.20\"],\r\n  ]\r\n```\r\n\r\nBut that gives me `element: argument 1 should be type list, got type string`"}}
{"actor":{"display_login":"afrazkhan"}}