diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 9c0216c1b..e12f5e7b4 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -4891,7 +4891,7 @@ func TestContext2Apply_provisionerDestroy(t *testing.T) { p.DiffFn = testDiffFn pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { val, ok := c.Config["command"] - if !ok || val != "destroy a" { + if !ok || val != "destroy a bar" { t.Fatalf("bad value for foo: %v %#v", val, c) } @@ -4904,7 +4904,7 @@ func TestContext2Apply_provisionerDestroy(t *testing.T) { mustResourceInstanceAddr(`aws_instance.foo["a"]`).Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar"}`), + AttrsJSON: []byte(`{"id":"bar","foo":"bar"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4955,7 +4955,7 @@ func TestContext2Apply_provisionerDestroyFail(t *testing.T) { mustResourceInstanceAddr(`aws_instance.foo["a"]`).Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar"}`), + AttrsJSON: []byte(`{"id":"bar","foo":"bar"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4985,6 +4985,7 @@ func TestContext2Apply_provisionerDestroyFail(t *testing.T) { aws_instance.foo["a"]: ID = bar provider = provider["registry.terraform.io/hashicorp/aws"] + foo = bar `) // Verify apply was invoked diff --git a/terraform/evaluate.go b/terraform/evaluate.go index b3ed53116..9e25bf6f7 100644 --- a/terraform/evaluate.go +++ b/terraform/evaluate.go @@ -664,9 +664,11 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc if change.Action == plans.Delete { // FIXME: we should not be evaluating resources that are going // to be destroyed, but this needs to happen always since - // providers need to evaluate their configuration during a full - // destroy, even of they depend on resources being destroyed. - + // destroy-time provisioners need to reference their self + // value, and providers need to evaluate their configuration + // during a full destroy, even of they depend on resources + // being destroyed. + // // Since this requires a special transformer to try and fixup // the order of evaluation when possible, reference it here to // ensure that we remove the transformer when this is fixed. diff --git a/terraform/testdata/apply-provisioner-destroy/main.tf b/terraform/testdata/apply-provisioner-destroy/main.tf index d5fc54e12..8804f6495 100644 --- a/terraform/testdata/apply-provisioner-destroy/main.tf +++ b/terraform/testdata/apply-provisioner-destroy/main.tf @@ -8,7 +8,7 @@ resource "aws_instance" "foo" { provisioner "shell" { when = "destroy" - command = "destroy ${each.key}" + command = "destroy ${each.key} ${self.foo}" } }