{"action":"closed","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/1998","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/1998/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/1998/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/1998/events","html_url":"https://github.com/hashicorp/terraform/issues/1998","id":77200445,"number":1998,"title":"Template Files as User Data don't seem to render the same from plan to apply/from one apply to another","user":{"login":"mlrobinson","id":5481655,"avatar_url":"https://avatars.githubusercontent.com/u/5481655?v=3","gravatar_id":"","url":"https://api.github.com/users/mlrobinson","html_url":"https://github.com/mlrobinson","followers_url":"https://api.github.com/users/mlrobinson/followers","following_url":"https://api.github.com/users/mlrobinson/following{/other_user}","gists_url":"https://api.github.com/users/mlrobinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mlrobinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlrobinson/subscriptions","organizations_url":"https://api.github.com/users/mlrobinson/orgs","repos_url":"https://api.github.com/users/mlrobinson/repos","events_url":"https://api.github.com/users/mlrobinson/events{/privacy}","received_events_url":"https://api.github.com/users/mlrobinson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hashicorp/terraform/labels/bug","name":"bug","color":"f7c6c7"},{"url":"https://api.github.com/repos/hashicorp/terraform/labels/provider/template","name":"provider/template","color":"bfdadc"},{"url":"https://api.github.com/repos/hashicorp/terraform/labels/waiting-response","name":"waiting-response","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-17T03:46:46Z","updated_at":"2015-05-18T14:41:00Z","closed_at":"2015-05-18T14:41:00Z","body":"I was testing using the new template resource with creating a user-data script for AWS, when I noticed that even when I don't change the template/vars from one run to the next, Terraform still wants to reprovision any instances I defined because the user_data hash/checksum appears to be different.\r\n\r\nHere is my `example.tf`:\r\n```\r\nprovider \"aws\" {\r\n    access_key = \"ACCESS_KEY\"\r\n    secret_key = \"SECRET_KEY\"\r\n    region = \"us-east-1\"\r\n}\r\n\r\nvariable \"key\" {\r\n    default = \"hello\"\r\n}\r\n\r\nvariable \"filename\" {\r\n    default = \"template.txt\"\r\n}\r\n\r\nresource \"template_file\" \"sample\" {\r\n    filename = \"${var.filename}\"\r\n    vars {\r\n        hello = \"${var.key}\"\r\n        world = \"${replace(var.key, \"ello\", \"i\")}\"\r\n    }\r\n}\r\n\r\n# AMI is for Debian 7.8, latest from Debian Wiki\r\nresource \"aws_instance\" \"example\" {\r\n    ami = \"ami-e0efab88\"\r\n    instance_type = \"t2.micro\"\r\n    user_data = \"${template_file.sample.rendered}\"\r\n}\r\n\r\noutput \"rendered\" {\r\n    value = \"${template_file.sample.rendered}\"\r\n}\r\n\r\n```\r\nand my `template.txt`:\r\n```\r\nHello: ${hello}\r\nWorld: ${world}\r\nAddition: ${1+2+3}\r\n```\r\n\r\nHere is the results of running plan, apply, and then another plan:\r\n```\r\n$ terraform plan\r\nvar.filename\r\n  Default: template.txt\r\n  Enter a value: \r\n\r\nvar.key\r\n  Default: hello\r\n  Enter a value: \r\n\r\nRefreshing Terraform state prior to plan...\r\n\r\n\r\nThe Terraform execution plan has been generated and is shown below.\r\nResources are shown in alphabetical order for quick scanning. Green resources\r\nwill be created (or destroyed and then created if an existing resource\r\nexists), yellow resources are being changed in-place, and red resources\r\nwill be destroyed.\r\n\r\nNote: You didn't specify an \"-out\" parameter to save this plan, so when\r\n\"apply\" is called, Terraform can't guarantee this is what will execute.\r\n\r\n+ aws_instance.example\r\n    ami:                      \"\" => \"ami-e0efab88\"\r\n...\r\n    user_data:                \"\" => \"894115c5b5247d5425ec8090e4dd6ba9f15d9d49\"\r\n\r\n+ template_file.sample\r\n    filename:   \"\" => \"template.txt\"\r\n    rendered:   \"\" => \"<computed>\"\r\n    vars.#:     \"0\" => \"2\"\r\n    vars.hello: \"\" => \"hello\"\r\n    vars.world: \"\" => \"hi\"\r\n\r\n\r\n$ terraform apply\r\nvar.filename\r\n  Default: template.txt\r\n  Enter a value: \r\n\r\nvar.key\r\n  Default: hello\r\n  Enter a value: \r\n\r\ntemplate_file.sample: Refreshing state... (ID: 81d5caf6b8aee37211d2)\r\ntemplate_file.sample: Creating...\r\n  filename:   \"\" => \"template.txt\"\r\n  rendered:   \"\" => \"<computed>\"\r\n  vars.#:     \"0\" => \"2\"\r\n  vars.hello: \"\" => \"hello\"\r\n  vars.world: \"\" => \"hi\"\r\ntemplate_file.sample: Creation complete\r\naws_instance.example: Creating...\r\n  ami:                      \"\" => \"ami-e0efab88\"\r\n...\r\n  user_data:                \"\" => \"e0fa0ca27ad2cc328d30df5a6dd0c736d45de147\"\r\naws_instance.example: Creation complete\r\n\r\nApply complete! Resources: 2 added, 0 changed, 0 destroyed.\r\n\r\nThe state of your infrastructure has been saved to the path\r\nbelow. This state is required to modify and destroy your\r\ninfrastructure, so keep it safe. To inspect the complete state\r\nuse the `terraform show` command.\r\n\r\nState path: terraform.tfstate\r\n\r\nOutputs:\r\n\r\n  rendered = Hello: hello\r\nWorld: hi\r\nAddition: 6\r\n\r\n\r\n$ terraform plan\r\nvar.filename\r\n  Default: template.txt\r\n  Enter a value: \r\n\r\nvar.key\r\n  Default: hello\r\n  Enter a value: \r\n\r\nRefreshing Terraform state prior to plan...\r\n\r\ntemplate_file.sample: Refreshing state... (ID: 81d5caf6b8aee37211d2)\r\naws_instance.example: Refreshing state... (ID: i-1a404c35)\r\n\r\nThe Terraform execution plan has been generated and is shown below.\r\nResources are shown in alphabetical order for quick scanning. Green resources\r\nwill be created (or destroyed and then created if an existing resource\r\nexists), yellow resources are being changed in-place, and red resources\r\nwill be destroyed.\r\n\r\nNote: You didn't specify an \"-out\" parameter to save this plan, so when\r\n\"apply\" is called, Terraform can't guarantee this is what will execute.\r\n\r\n-/+ aws_instance.example\r\n    ami:                      \"ami-e0efab88\" => \"ami-e0efab88\"\r\n...\r\n    user_data:                \"e0fa0ca27ad2cc328d30df5a6dd0c736d45de147\" => \"894115c5b5247d5425ec8090e4dd6ba9f15d9d49\" (forces new resource)\r\n    vpc_security_group_ids.#: \"1\" => \"<computed>\"\r\n\r\n+ template_file.sample\r\n    filename:   \"\" => \"template.txt\"\r\n    rendered:   \"\" => \"<computed>\"\r\n    vars.#:     \"0\" => \"2\"\r\n    vars.hello: \"\" => \"hello\"\r\n    vars.world: \"\" => \"hi\"\r\n\r\n\r\n```\r\n\r\nI haven't dug into the code too much, but I am thinking the plan command should render the templates just as the apply command does, which may be difficult if the template uses data from other resources that haven't been built yet. Perhaps when things are refreshed/read from the state file, that could be used, if it's not already?"}}