destroy provisioner test

Ensure that we have destroy provisioner test that reference self
This commit is contained in:
James Bardin 2020-07-20 15:35:31 -04:00
parent 3223e352ea
commit 5b8e5ec276
3 changed files with 10 additions and 7 deletions

View File

@ -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

View File

@ -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.

View File

@ -8,7 +8,7 @@ resource "aws_instance" "foo" {
provisioner "shell" {
when = "destroy"
command = "destroy ${each.key}"
command = "destroy ${each.key} ${self.foo}"
}
}