{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/9352","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/9352/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/9352/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/9352/events","html_url":"https://github.com/hashicorp/terraform/issues/9352","id":182789955,"number":9352,"title":"providers/consul: support setting ID on consul_service","user":{"login":"dmportella","id":676817,"avatar_url":"https://avatars.githubusercontent.com/u/676817?v=3","gravatar_id":"","url":"https://api.github.com/users/dmportella","html_url":"https://github.com/dmportella","followers_url":"https://api.github.com/users/dmportella/followers","following_url":"https://api.github.com/users/dmportella/following{/other_user}","gists_url":"https://api.github.com/users/dmportella/gists{/gist_id}","starred_url":"https://api.github.com/users/dmportella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmportella/subscriptions","organizations_url":"https://api.github.com/users/dmportella/orgs","repos_url":"https://api.github.com/users/dmportella/repos","events_url":"https://api.github.com/users/dmportella/events{/privacy}","received_events_url":"https://api.github.com/users/dmportella/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-13T13:30:17Z","updated_at":"2016-10-13T14:00:19Z","closed_at":null,"body":"Hi there,\r\n\r\nRight now the resource `consul_service` *does not* support the resource count features very well because since the consul record identifier is created from the name you give to the record ([Reference](https://www.terraform.io/docs/providers/consul/r/service.html#id)) you can't create record with the same `name` but different `identifiers` which allows you to use `consul` dns load balancer feature.\r\n\r\n### Terraform Version\r\n> Terraform v0.7.5\r\n\r\n### Affected Resource(s)\r\n- consul_service\r\n\r\n### Terraform Configuration Files\r\n```\r\n# Docker provider\r\nprovider \"docker\" {\r\n\thost = \"unix:///var/run/docker.sock\"\r\n}\r\n\r\n# Consul Provider\r\nprovider \"consul\" {\r\n\taddress\t= \"http://localhost:8500\"\r\n\tdatacenter = \"dc1\"\r\n\tscheme\t = \"http\"\r\n}\r\n\r\nvariable \"elastic_count\" {\r\n\ttype = \"string\"\r\n\tdefault = \"4\"\r\n}\r\n\r\nresource \"docker_image\" \"elastic\" {\r\n\tname = \"elasticsearch:2.4.1\"\r\n}\r\n\r\n# Create a container\r\nresource \"docker_container\" \"elastic\" {\r\n\tcount = \"${var.elastic_count}\"\r\n\timage = \"${docker_image.elastic.name}\"\r\n\tname = \"elastic-${format(\"%02d\", count.index+1)}\"\r\n\t\r\n\thostname = \"elastic-${format(\"%02d\", count.index+1)}\"\r\n\r\n\trestart = \"always\"\r\n\tmemory = 512\r\n\r\n\tdns = [\"172.17.0.1\"]\r\n\r\n\tlabels {\r\n\t\ttype = \"elastic\"\r\n\t}\r\n\r\n\tvolumes {\r\n\t\tcontainer_path  = \"/usr/share/elasticsearch/data\"\r\n\t\thost_path = \"/home/dmportella/_workspaces/terraform/consul/data/elastic/data.${format(\"%d\", count.index+1)}\"\r\n\t\tread_only = false\r\n\t}\r\n\r\n\tvolumes {\r\n\t\tcontainer_path  = \"/usr/share/elasticsearch/config\"\r\n\t\thost_path = \"/home/dmportella/_workspaces/terraform/consul/configs/elastic\"\r\n\t\tread_only = false\r\n\t}\r\n}\r\n\r\nresource \"consul_service\" \"elastic-single\" {\r\n    depends_on = [\"null_resource.consul_provisioned\"]\r\n    count = \"${var.elastic_count}\"\r\n\r\n    address = \"${element(docker_container.elastic.*.ip_address, count.index)}\"\r\n    name = \"elastic-${format(\"%02d\", count.index+1)}\"\r\n    port = 9200\r\n    tags = [\"elastic\"]\r\n}\r\n\r\nresource \"consul_service\" \"elastic-cluster\" {\r\n    depends_on = [\"null_resource.consul_provisioned\"]\r\n    count = \"${var.elastic_count}\"\r\n\r\n    id = \"elastic-cluster-${format(\"%02d\", count.index+1)}\"\r\n    address = \"${element(docker_container.elastic.*.ip_address, count.index)}\"\r\n\r\n    name = \"elastic\"\r\n    port = 9200\r\n    tags = [\"elastic\", \"cluster\"]\r\n}\r\n```\r\nThe resource `consul_service.elastic-cluster` should create 4 entries in consul all with the same name but with different `identifiers`. However it creates only one with the last address of the array of resources.\r\n\r\nSee below the consul `http://localhost:8500/v1/agent/services` http api request after the terraform apply is run.\r\n```\r\n{\r\n  \"consul\": {\r\n    \"ID\": \"consul\",\r\n    \"Service\": \"consul\",\r\n    \"Tags\": [],\r\n    \"Address\": \"\",\r\n    \"Port\": 8300,\r\n    \"EnableTagOverride\": false,\r\n    \"CreateIndex\": 0,\r\n    \"ModifyIndex\": 0\r\n  },\r\n  \"elastic\": {\r\n    \"ID\": \"elastic\",\r\n    \"Service\": \"elastic\",\r\n    \"Tags\": [\r\n      \"elastic\",\r\n      \"cluster\"\r\n    ],\r\n    \"Address\": \"172.17.0.9\",\r\n    \"Port\": 9200,\r\n    \"EnableTagOverride\": false,\r\n    \"CreateIndex\": 0,\r\n    \"ModifyIndex\": 0\r\n  },\r\n  \"elastic-01\": {\r\n    \"ID\": \"elastic-01\",\r\n    \"Service\": \"elastic-01\",\r\n    \"Tags\": [\r\n      \"elastic\"\r\n    ],\r\n    \"Address\": \"172.17.0.10\",\r\n    \"Port\": 9200,\r\n    \"EnableTagOverride\": false,\r\n    \"CreateIndex\": 0,\r\n    \"ModifyIndex\": 0\r\n  },\r\n  \"elastic-02\": {\r\n    \"ID\": \"elastic-02\",\r\n    \"Service\": \"elastic-02\",\r\n    \"Tags\": [\r\n      \"elastic\"\r\n    ],\r\n    \"Address\": \"172.17.0.8\",\r\n    \"Port\": 9200,\r\n    \"EnableTagOverride\": false,\r\n    \"CreateIndex\": 0,\r\n    \"ModifyIndex\": 0\r\n  },\r\n  \"elastic-03\": {\r\n    \"ID\": \"elastic-03\",\r\n    \"Service\": \"elastic-03\",\r\n    \"Tags\": [\r\n      \"elastic\"\r\n    ],\r\n    \"Address\": \"172.17.0.7\",\r\n    \"Port\": 9200,\r\n    \"EnableTagOverride\": false,\r\n    \"CreateIndex\": 0,\r\n    \"ModifyIndex\": 0\r\n  },\r\n  \"elastic-04\": {\r\n    \"ID\": \"elastic-04\",\r\n    \"Service\": \"elastic-04\",\r\n    \"Tags\": [\r\n      \"elastic\"\r\n    ],\r\n    \"Address\": \"172.17.0.9\",\r\n    \"Port\": 9200,\r\n    \"EnableTagOverride\": false,\r\n    \"CreateIndex\": 0,\r\n    \"ModifyIndex\": 0\r\n  }\r\n}\r\n```\r\n\r\n### Debug Output\r\nApplication errors on validation no debug logs.\r\n\r\n### Panic Output\r\nApplication errors on validation no panic logs.\r\n\r\n### Expected Behavior\r\nWhat should have happened?\r\n\r\nIt should create 4 entries in consul each with different `identifiers` but with the same `name`\r\n\r\n### Actual Behavior\r\nWhat actually happened?\r\n\r\nApplication errors on validation with: \r\n\r\n```\r\nThere are warnings and/or errors related to your configuration. Please\r\nfix these before continuing.\r\n\r\nErrors:\r\n\r\n  * consul_service.elastic-cluster #0: \"id\": this field cannot be set\r\n  * consul_service.elastic-cluster #1: \"id\": this field cannot be set\r\n  * consul_service.elastic-cluster #2: \"id\": this field cannot be set\r\n  * consul_service.elastic-cluster #3: \"id\": this field cannot be set\r\n\r\n```\r\n\r\n### Steps to Reproduce\r\n\r\nYou need a consul cluster available I have used docker to test my setups so the consul docker image is very a very good start. Once it is there use terraform apply to see the error.\r\n\r\n### Important Factoids\r\n\r\nThis is a feature request but could be considered a design issue as one would expect it be able to support the dns load balancing feature of consul which requires the user to pass in records with the same `name` but different `identifiers`.\r\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/253521392","html_url":"https://github.com/hashicorp/terraform/issues/9352#issuecomment-253521392","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/9352","id":253521392,"user":{"login":"dmportella","id":676817,"avatar_url":"https://avatars.githubusercontent.com/u/676817?v=3","gravatar_id":"","url":"https://api.github.com/users/dmportella","html_url":"https://github.com/dmportella","followers_url":"https://api.github.com/users/dmportella/followers","following_url":"https://api.github.com/users/dmportella/following{/other_user}","gists_url":"https://api.github.com/users/dmportella/gists{/gist_id}","starred_url":"https://api.github.com/users/dmportella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmportella/subscriptions","organizations_url":"https://api.github.com/users/dmportella/orgs","repos_url":"https://api.github.com/users/dmportella/repos","events_url":"https://api.github.com/users/dmportella/events{/privacy}","received_events_url":"https://api.github.com/users/dmportella/received_events","type":"User","site_admin":false},"created_at":"2016-10-13T14:00:19Z","updated_at":"2016-10-13T14:00:19Z","body":"I would be happy to make the changes to the source code just wanted to raise the issue so it could be discussed."}}
{"actor":{"display_login":"dmportella"}}