{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/10074","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/10074/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/10074/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/10074/events","html_url":"https://github.com/hashicorp/terraform/issues/10074","id":188899702,"number":10074,"title":"data source aws_subnet forces new resource with each run of terrafrom apply","user":{"login":"dmatthis-sm","id":18469475,"avatar_url":"https://avatars.githubusercontent.com/u/18469475?v=3","gravatar_id":"","url":"https://api.github.com/users/dmatthis-sm","html_url":"https://github.com/dmatthis-sm","followers_url":"https://api.github.com/users/dmatthis-sm/followers","following_url":"https://api.github.com/users/dmatthis-sm/following{/other_user}","gists_url":"https://api.github.com/users/dmatthis-sm/gists{/gist_id}","starred_url":"https://api.github.com/users/dmatthis-sm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmatthis-sm/subscriptions","organizations_url":"https://api.github.com/users/dmatthis-sm/orgs","repos_url":"https://api.github.com/users/dmatthis-sm/repos","events_url":"https://api.github.com/users/dmatthis-sm/events{/privacy}","received_events_url":"https://api.github.com/users/dmatthis-sm/received_events","type":"User","site_admin":false},"labels":[{"id":85946957,"url":"https://api.github.com/repos/hashicorp/terraform/labels/bug","name":"bug","color":"f7c6c7","default":true},{"id":127939518,"url":"https://api.github.com/repos/hashicorp/terraform/labels/provider/aws","name":"provider/aws","color":"bfdadc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-12T08:10:51Z","updated_at":"2016-11-15T06:53:28Z","closed_at":null,"body":"### Terraform Version\r\nTerraform v0.7.9\r\n\r\n### Affected Resource(s)\r\n- data source aws_subnet\r\n- resource aws_instance\r\n\r\n### Terraform Configuration Files\r\n```hcl\r\n\r\n## Resource will be destroyed and rebuilt each time terraform apply is ran.\r\nresource \"aws_instance\" \"test-a\" {\r\n  count                       = 2\r\n  ami                         = \"${data.aws_ami.ubuntu16.id}\"\r\n  instance_type               = \"t2.micro\"\r\n  vpc_security_group_ids      = [ \"sg-somegroup\" ]\r\n  associate_public_ip_address = false\r\n  subnet_id                   = \"${data.aws_subnet.publicb.id}\"\r\n}\r\n\r\n## Resource will not be destroyed and rebuilt with each run.\r\nresource \"aws_instance\" \"test-b\" {\r\n  count                       = 2\r\n  ami                        = \"${data.aws_ami.ubuntu16.id}\"\r\n  instance_type               = \"t2.micro\"\r\n  vpc_security_group_ids      = [ \"sg-somegroup\" ]\r\n  associate_public_ip_address = false\r\n  subnet_id                   = \"subnet-1234abcd\"\r\n}\r\n\r\n```\r\n### Expected Behavior\r\nIf the subnet id is the same each run, even with a calculated value, then it should not destroy and rebuild the instance for each \"terraform apply\"\r\n\r\n### Actual Behavior\r\nInstance resource that has subnet_id set with a calculated value based off data resource is destroyed and rebuilt with each run of \"terraform apply\"\r\n\r\n```\r\n-/+ aws_instance.test-a.0\r\n.\r\n.\r\n.\r\n  subnet_id:                                         \"subnet-1234abcd\" => \"<computed>\" (forces new resource)\r\n```\r\n### Steps to Reproduce\r\n1. `terraform apply`\r\n2. Run `terraform apply` again. (It does not matter if you run terraform plan before hand or not\r\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/260562099","html_url":"https://github.com/hashicorp/terraform/issues/10074#issuecomment-260562099","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/10074","id":260562099,"user":{"login":"dmatthis-sm","id":18469475,"avatar_url":"https://avatars.githubusercontent.com/u/18469475?v=3","gravatar_id":"","url":"https://api.github.com/users/dmatthis-sm","html_url":"https://github.com/dmatthis-sm","followers_url":"https://api.github.com/users/dmatthis-sm/followers","following_url":"https://api.github.com/users/dmatthis-sm/following{/other_user}","gists_url":"https://api.github.com/users/dmatthis-sm/gists{/gist_id}","starred_url":"https://api.github.com/users/dmatthis-sm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmatthis-sm/subscriptions","organizations_url":"https://api.github.com/users/dmatthis-sm/orgs","repos_url":"https://api.github.com/users/dmatthis-sm/repos","events_url":"https://api.github.com/users/dmatthis-sm/events{/privacy}","received_events_url":"https://api.github.com/users/dmatthis-sm/received_events","type":"User","site_admin":false},"created_at":"2016-11-15T06:53:28Z","updated_at":"2016-11-15T06:53:28Z","body":"I think I found my problem I have two sets of data resource lookups as I have been trying various things our trying to work with modules and commented out large blocks of code.\r\n\r\nThe active one right now is on that doesn't have `vpc_id = \"${aws_vpc.vpc.id}\"` it is actually `vpc_id = \"${inf_vpc_id}\"`\r\n\r\ninf_vpc_id is an output variable from a vpc module. Because output from the module is not calculated until run time there is actually no data there, but instead of throwing an error for null value, from what I can tell it just sends and empty string. \r\n\r\nThis gets at the original problem I am trying to work around. It seems counter productive to put the VPC and subnets in a module as you cannot reference the generated data in other modules. In my case I was trying to figure out how to make an instance module that could put the nodes in the correct subnet and AZ by passing an output variable from the VPC. \r\n\r\nWhent his failed I thought I would see if the data_source option would let me get what I needed but I apparently forgot that I am trying to use it in a lookup in the data call in order to find the vpc_id and apparently \"inf_vpc_id\" is empty when the data resource runs.\r\n\r\nSo I guess to your point @apparentlymart I am trying to populate vpc_id with a resource that doesn't have a value at the run time. Sorry for the wrong text grab. \r\n\r\nThat said do you know of any docs or pages that give a good design pattern for dealing with VPC modules and generating instances based on the subnets that are part of those VPCs?"}}
{"actor":{"display_login":"dmatthis-sm"}}