Loading...
Loading...
Even though I am aware that the `environment` keyword is being deprecated, the fact that existing code using it is silently failing cost us quite a bit of time troubleshooting. It should be either upgraded to an error, or fixed to resume working as before. ### Terraform Version ``` $ terraform --version Terraform v0.11.3 ``` ### Terraform Configuration Files ```hcl # test_remote_state/terraform.tf terraform { backend "s3" { key = "dev/test_remote_state" bucket = "our-s3-bucket-terraform" region = "us-west-2" profile = "infrastructure" } } output "test_output" { value = "moo" } ``` ```hcl # test/terraform.tf data "terraform_remote_state" "remote_output" { backend = "s3" environment = "infrastructure.us-west-2" config { bucket = "our-s3-bucket-terraform" key = "dev/test_remote_state" region = "us-west-2" profile = "infrastructure" } } output "remote_output" { value = "${data.terraform_remote_state.remote_output.test_output}" } ``` ### Debug Output ### Crash Output When running `terraform apply` in `test`: ``` Error: Error running plan: 1 error(s) occurred: * output.remote_output: Resource 'data.terraform_remote_state.remote_output' does not have attribute 'test_output' for variable 'data.terraform_remote_state.remote_output.test_output' ``` ### Expected Behavior In `test`, Terraform should successfully run. The output `remote_output` should then show `moo`, as read from remote state. ### Actual Behavior Terraform instead errors out, which indicates that Terraform is unable to locate the remote state, or that the remote state data is empty and does not contain the attribute we expect (`test_output`). Interestingly, if you remove the `output` section from `test/terraform.tf`, and run `terraform apply`, it will succeed. Then, running `terraform show` will show that: ``` data.terraform_remote_state.remote_output: Refreshing state... Apply complete! Resources: 0 added, 0 changed, 0 destroyed. $ terraform show data.terraform_remote_state.remote_output: id = 2018-03-08 06:34:29.967167934 +0000 UTC backend = s3 config.% = 4 config.bucket = our-s3-bucket-terraform config.key = dev/test_remote_state config.profile = infrastructure config.region = us-west-2 environment = infrastructure.us-west-2 workspace = default ``` Note that both `environment` and `workspace` keys appear, and `workspace` is set to `default`, which is clearly the wrong value (it should be set to what `environment` is set to.) I suspect this is where the bug is. ### Steps to Reproduce 1. Make a directory `test_remote_state` 2. Copy and paste the contents of the matching file above into `test_remote_state/terraform.tf` 3. Make an S3 bucket named `our-s3-bucket-terraform` for example (if using a different name, please update all of the references accordingly) 4. Inside `test_remote_state`, please run `terraform init` 5. Switch to the `infrastructure.us-west-2` workspace by running `terraform workspace new infrastructure.us-west-2`. You should now be in this new workspace. 6. Run `terraform apply` 7. confirm the output is as follows: ``` Apply complete! Resources: 0 added, 0 changed, 0 destroyed. Outputs: test_output = moo ``` 6. Make a directory `test` 7. Copy and paste the contents of the matching file above into `test/terraform.tf` 8. Inside `test`, run `terraform init` followed by `terraform apply` 9. Confirm that the error above occurs ### Additional Context N.A. ### References Commit where we deprecate `environment` for `terraform_remote_state` data resource: https://github.com/hashicorp/terraform/commit/5c58ef16f7b57784e1be810364566ae4236ccf48#diff-5bb530affc03447353d6a5daeee76f9cL112
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.