{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/17641","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/17641/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/17641/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/17641/events","html_url":"https://github.com/hashicorp/terraform/issues/17641","id":306856059,"number":17641,"title":"null_resource trigger with interpolated value used as an output fails","user":{"login":"tomelliff","id":4348646,"avatar_url":"https://avatars3.githubusercontent.com/u/4348646?v=4","gravatar_id":"","url":"https://api.github.com/users/tomelliff","html_url":"https://github.com/tomelliff","followers_url":"https://api.github.com/users/tomelliff/followers","following_url":"https://api.github.com/users/tomelliff/following{/other_user}","gists_url":"https://api.github.com/users/tomelliff/gists{/gist_id}","starred_url":"https://api.github.com/users/tomelliff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomelliff/subscriptions","organizations_url":"https://api.github.com/users/tomelliff/orgs","repos_url":"https://api.github.com/users/tomelliff/repos","events_url":"https://api.github.com/users/tomelliff/events{/privacy}","received_events_url":"https://api.github.com/users/tomelliff/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":127939292,"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-20T13:03:54Z","updated_at":"2018-05-21T23:57:51Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I'm finally getting around to moving from 0.10.8 to 0.11+ but am having issues with outputting the value of a trigger that is interpolated from another resource. I have an `aws_ecs_task_definition` that I pass to an `aws_ecs_service` resource and then I use a null resource with a local exec provisioner to wait for the deployment to finish using the AWS CLI (I need this until https://github.com/terraform-providers/terraform-provider-aws/pull/3485 is merged) so I know that the deployment is complete.\r\n\r\nThis is all wrapped in a shared module that we use for all of our ECS services but we also have a web facing service that has Cloudfront in front of it where we invalidate the cache after the deployment so the ECS service module needs to output something from the null resource so that I can have Terraform wait for the deploy to be complete before then running the Cloudfront cache invalidation.\r\n\r\nIt works fine as is (and has done for months of 0.10.8 usage now) but apparently it is failing the output interpolation check introduced in 0.10.8 (that quietly failed previously) and enforced in 0.11+. I'm not too sure why it seems to fail with triggers but specifically only interpolated ones and not statically defined trigger values (such as `triggers { foo = \"bar\" }}`. At first I thought Terraform was complaining because the null resource may not execute if there's no change to any of the triggers and so there's no guarantee that the null resource would be executed but I think that should also apply to statically defined trigger values. Am I misunderstanding something about the graph Terraform is building here or is this a bug one way or the other?\r\n\r\nI'm considering simply setting `TF_WARN_OUTPUT_ERRORS=1` in helper scripts for now and hoping that the above linked PR gets merged and released before 0.12 because I think this is the only case I need this but I'm curious as to the cause of this error before I suppress it.\r\n\r\n### Terraform Version\r\n```\r\nTerraform v0.11.4\r\n+ provider.aws v1.11.0\r\n+ provider.null v1.0.0\r\n```\r\n\r\n### Terraform Configuration Files\r\n#### task-def.json:\r\n```json\r\n[\r\n  {\r\n    \"name\": \"first\",\r\n    \"image\": \"service-first\",\r\n    \"cpu\": 10,\r\n    \"memory\": 512,\r\n    \"essential\": true,\r\n    \"portMappings\": [\r\n      {\r\n        \"containerPort\": 80,\r\n        \"hostPort\": 80\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"name\": \"second\",\r\n    \"image\": \"service-second\",\r\n    \"cpu\": 10,\r\n    \"memory\": 256,\r\n    \"essential\": true,\r\n    \"portMappings\": [\r\n      {\r\n        \"containerPort\": 443,\r\n        \"hostPort\": 443\r\n      }\r\n    ]\r\n  }\r\n]\r\n```\r\nThis plans fine:\r\n#### main.tf\r\n```hcl\r\nresource \"aws_ecs_task_definition\" \"task_def\" {\r\n  family                = \"foo\"\r\n  container_definitions = \"${file(\"task-def.json\")}\"\r\n}\r\n\r\nresource \"aws_ecs_service\" \"service\" {\r\n  name            = \"foo\"\r\n  cluster         = \"dev\"\r\n  task_definition = \"${aws_ecs_task_definition.task_def.arn}\"\r\n  desired_count   = \"1\"\r\n  iam_role        = \"ecsServiceRole\"\r\n}\r\n\r\nresource \"null_resource\" \"wait_for_service_deploy\" {\r\n  triggers {\r\n    # task_definition = \"${aws_ecs_service.service.task_definition}\"\r\n    static_trigger = \"foo\"\r\n  }\r\n\r\n  provisioner \"local-exec\" {\r\n    command = \"echo foo\"\r\n  }\r\n}\r\n\r\n# output \"null_resource_task_definition\" {\r\n#   value = \"${null_resource.wait_for_service_deploy.triggers.task_definition}\"\r\n# }\r\n\r\noutput \"null_resource_static_trigger\" {\r\n  value = \"${null_resource.wait_for_service_deploy.triggers.static_trigger}\"\r\n}\r\n```\r\nUncommenting the `task_definition` trigger and the `null_resource_task_definition` output and planning causes it to error:\r\n```\r\n* output.null_resource_task_definition: Resource 'null_resource.wait_for_service_deploy' does not have attribute 'triggers.task_definition' for variable 'null_resource.wait_for_service_deploy.triggers.task_definition'\r\n```\r\nRunning with `TF_WARN_OUTPUT_ERRORS=1 terraform plan` it plans okay but the above error message is written to the log.\r\n\r\nChecking 0.10.8 it also appears to be quietly erroring there as well (is there a way I can make warnings like this more visible when running much like the deprecation notices in resources? I've been sitting on this issue for a while apparently but didn't notice it in logs because I don't look at them unless something is broken) so it's not something new.\r\n\r\n### Expected Behavior\r\nIt should plan/apply fine\r\n\r\n### Actual Behavior\r\nIt fails\r\n\r\n### Steps to Reproduce\r\n```\r\nterraform init\r\nterraform plan\r\n```"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/390820410","html_url":"https://github.com/hashicorp/terraform/issues/17641#issuecomment-390820410","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/17641","id":390820410,"user":{"login":"bendrucker","id":808808,"avatar_url":"https://avatars0.githubusercontent.com/u/808808?v=4","gravatar_id":"","url":"https://api.github.com/users/bendrucker","html_url":"https://github.com/bendrucker","followers_url":"https://api.github.com/users/bendrucker/followers","following_url":"https://api.github.com/users/bendrucker/following{/other_user}","gists_url":"https://api.github.com/users/bendrucker/gists{/gist_id}","starred_url":"https://api.github.com/users/bendrucker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendrucker/subscriptions","organizations_url":"https://api.github.com/users/bendrucker/orgs","repos_url":"https://api.github.com/users/bendrucker/repos","events_url":"https://api.github.com/users/bendrucker/events{/privacy}","received_events_url":"https://api.github.com/users/bendrucker/received_events","type":"User","site_admin":false},"created_at":"2018-05-21T23:57:51Z","updated_at":"2018-05-21T23:57:51Z","author_association":"NONE","body":"I've also run into this issue and described my setup in detail in https://github.com/poseidon/typhoon/pull/224.\r\n\r\nI noticed that it's not the presence of interpolations that causes this error, but specifically interpolations that are asynchronous and happen in the apply phase instead of during a plan.\r\n\r\nIn the original example `${aws_ecs_service.service.task_definition}` meets that condition. Passing that value as an input to a module and then using that variable as a trigger also causes the same error. But triggers that can be resolved at plan time are available as exported attributes."}}
{"actor":{"display_login":"bendrucker"}}