Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy provisioners not working if resource is deleted manually #13097

Closed
akaspin opened this issue Mar 27, 2017 · 5 comments
Closed

Destroy provisioners not working if resource is deleted manually #13097

akaspin opened this issue Mar 27, 2017 · 5 comments

Comments

@akaspin
Copy link

akaspin commented Mar 27, 2017

Destroy provisioners only runs on terraform destroy or when resource is destroyed by count.
But destroy provisioners won't run if resource manually deleted from source file.

Terraform Version

Terraform v0.9.1

Affected Resource(s)

Provisioners

Terraform Configuration Files

resource "null_resource" "test" {
  count = 1
  provisioner "local-exec" {
    command = "echo create"
  }
  provisioner "local-exec" {
    when = "destroy"
    command = "echo destroy"
  }
}

Debug Output

$ TF_LOG=DEBUG terraform apply
2017/03/27 17:58:39 [INFO] Terraform version: 0.9.1  
2017/03/27 17:58:39 [INFO] Go runtime version: go1.8
2017/03/27 17:58:39 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.9.1_1/bin/terraform", "apply"}
2017/03/27 17:58:39 [DEBUG] Detected home directory from env var: /Users/spin
2017/03/27 17:58:39 [DEBUG] Detected home directory from env var: /Users/spin
2017/03/27 17:58:39 [DEBUG] Attempting to open CLI config file: /Users/spin/.terraformrc
2017/03/27 17:58:39 [DEBUG] Detected home directory from env var: /Users/spin
2017/03/27 17:58:39 [INFO] CLI command args: []string{"apply"}
2017/03/27 17:58:39 [DEBUG] command: loading backend config file: /Users/spin/Craft/applift/primer/site/test
2017/03/27 17:58:39 [DEBUG] command: no data state file found for backend config
2017/03/27 17:58:39 [DEBUG] New state was assigned lineage "e87943fc-3dfa-4e8d-a91b-6fb11e06b5d2"
2017/03/27 17:58:39 [INFO] command: backend initialized: <nil>
2017/03/27 17:58:39 [INFO] command: backend <nil> is not enhanced, wrapping in local
2017/03/27 17:58:39 [INFO] backend/local: starting Apply operation
2017/03/27 17:58:39 [INFO] terraform: building graph: GraphTypeInput
2017/03/27 17:58:39 [DEBUG] Attaching resource state to "null_resource.test": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4201cf450), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:39 [TRACE] Graph after step *terraform.AttachStateTransformer:

null_resource.test - *terraform.NodeAbstractResource
2017/03/27 17:58:39 [DEBUG] Starting graph walk: walkInput
2017/03/27 17:58:39 [DEBUG] dag/walk: added new vertex: "provider.null"
2017/03/27 17:58:39 [DEBUG] dag/walk: added new vertex: "null_resource.test"
2017/03/27 17:58:39 [DEBUG] dag/walk: added edge: "null_resource.test" waiting on "provider.null"
2017/03/27 17:58:39 [DEBUG] dag/walk: dependencies changed for "null_resource.test", sending new deps
2017/03/27 17:58:39 [DEBUG] dag/walk: walking "provider.null"
2017/03/27 17:58:39 [DEBUG] vertex 'root.provider.null': walking
2017/03/27 17:58:39 [DEBUG] vertex 'root.provider.null': evaluating
2017/03/27 17:58:39 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:39 [DEBUG] root: eval: *terraform.EvalInitProvider
2017/03/27 17:58:39 [DEBUG] plugin: starting plugin: /usr/local/Cellar/terraform/0.9.1_1/bin/terraform []string{"/usr/local/Cellar/terraform/0.9.1_1/bin/terraform", "internal-plugin", "provider", "null"}
2017/03/27 17:58:39 [DEBUG] plugin: waiting for RPC address for: /usr/local/Cellar/terraform/0.9.1_1/bin/terraform
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [INFO] Terraform version: 0.9.1
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [INFO] Go runtime version: go1.8
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.9.1_1/bin/terraform", "internal-plugin", "provider", "null"}
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [DEBUG] Detected home directory from env var: /Users/spin
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [DEBUG] Detected home directory from env var: /Users/spin
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [DEBUG] Attempting to open CLI config file: /Users/spin/.terraformrc
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [DEBUG] Detected home directory from env var: /Users/spin
2017/03/27 17:58:40 [DEBUG] plugin: terraform: 2017/03/27 17:58:40 [INFO] CLI command args: []string{"internal-plugin", "provider", "null"}
2017/03/27 17:58:40 [DEBUG] plugin: terraform: null-provider (internal) 2017/03/27 17:58:40 [INFO] Starting provider plugin null
2017/03/27 17:58:40 [DEBUG] plugin: terraform: null-provider (internal) 2017/03/27 17:58:40 [DEBUG] plugin: plugin address: unix /var/folders/n0/2m8gn9696y761syj71ncx4nm0000gn/T/plugin947608875
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalBuildProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInputProvider
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [TRACE] [walkInput] Exiting eval tree: provider.null
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "null_resource.test"
2017/03/27 17:58:40 [DEBUG] vertex 'root.null_resource.test': walking
2017/03/27 17:58:40 [INFO] terraform: building graph: GraphTypeValidate
2017/03/27 17:58:40 [TRACE] ConfigTransformer: Starting for path: []
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.ConfigTransformer:

2017/03/27 17:58:40 [TRACE] Graph after step *terraform.OutputTransformer:

2017/03/27 17:58:40 [TRACE] Graph after step *terraform.OrphanResourceTransformer:

null_resource.test - *terraform.NodeAbstractResource
2017/03/27 17:58:40 [TRACE] AttachResourceConfigTransformer: Beginning...
2017/03/27 17:58:40 [TRACE] AttachResourceConfigTransformer: Attach resource config request: null_resource.test
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.AttachResourceConfigTransformer:

null_resource.test - *terraform.NodeAbstractResource
2017/03/27 17:58:40 [DEBUG] Attaching resource state to "null_resource.test": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4201cf450), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.AttachStateTransformer:

null_resource.test - *terraform.NodeAbstractResource
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.RootVariableTransformer:

null_resource.test - *terraform.NodeAbstractResource
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "provider.null" references: []
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "null_resource.test" references: []
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: added edge: "null_resource.test" waiting on "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: dependencies changed for "null_resource.test", sending new deps
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "provider.null"
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': walking
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': evaluating
2017/03/27 17:58:40 [TRACE] [walkValidate] Entering eval tree: provider.null
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInitProvider
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalBuildProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalValidateProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSetProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [TRACE] [walkValidate] Exiting eval tree: provider.null
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "null_resource.test"
2017/03/27 17:58:40 [DEBUG] vertex 'root.null_resource.test': walking
2017/03/27 17:58:40 [INFO] backend/local: apply calling Refresh
2017/03/27 17:58:40 [INFO] terraform: building graph: GraphTypeRefresh
2017/03/27 17:58:40 [DEBUG] Attaching resource state to "null_resource.test": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4203e2a50), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "null_resource.test" references: []
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "null_resource.test"
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: added edge: "null_resource.test" waiting on "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: dependencies changed for "null_resource.test", sending new deps
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "provider.null"
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': walking
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': evaluating
2017/03/27 17:58:40 [TRACE] [walkRefresh] Entering eval tree: provider.null
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInitProvider
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalBuildProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSetProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalConfigProvider
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "null_resource.test"
2017/03/27 17:58:40 [DEBUG] vertex 'root.null_resource.test': walking
2017/03/27 17:58:40 [DEBUG] vertex 'root.null_resource.test': evaluating
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalReadState
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalRefresh
null_resource.test: Refreshing state... (ID: 1079585043260643836)
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalWriteState
2017/03/27 17:58:40 [INFO] backend/local: apply calling Plan
2017/03/27 17:58:40 [INFO] terraform: building graph: GraphTypePlan
2017/03/27 17:58:40 [TRACE] ConfigTransformer: Starting for path: []
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.ConfigTransformer:

2017/03/27 17:58:40 [TRACE] Graph after step *terraform.OutputTransformer:

2017/03/27 17:58:40 [TRACE] Graph after step *terraform.OrphanResourceTransformer:

null_resource.test (orphan) - *terraform.NodePlannableResourceOrphan
2017/03/27 17:58:40 [TRACE] AttachResourceConfigTransformer: Beginning...
2017/03/27 17:58:40 [TRACE] AttachResourceConfigTransformer: Attach resource config request: null_resource.test
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.AttachResourceConfigTransformer:

null_resource.test (orphan) - *terraform.NodePlannableResourceOrphan
2017/03/27 17:58:40 [DEBUG] Attaching resource state to "null_resource.test (orphan)": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4203e2fa0), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "null_resource.test (orphan)" references: []
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "provider.null" references: []
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.ReferenceTransformer:

null_resource.test (orphan) - *terraform.NodePlannableResourceOrphan
  provider.null - *terraform.NodeApplyableProvider
provider.null - *terraform.NodeApplyableProvider
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.TargetsTransformer:

null_resource.test (orphan) - *terraform.NodePlannableResourceOrphan
  provider.null - *terraform.NodeApplyableProvider
provider.null - *terraform.NodeApplyableProvider
2017/03/27 17:58:40 [TRACE] Graph after step *terraform.RootTransformer:

null_resource.test (orphan) - *terraform.NodePlannableResourceOrphan
  provider.null - *terraform.NodeApplyableProvider
provider.null - *terraform.NodeApplyableProvider
2017/03/27 17:58:40 [DEBUG] Starting graph walk: walkPlan
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "null_resource.test (orphan)"
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: added edge: "null_resource.test (orphan)" waiting on "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: dependencies changed for "null_resource.test (orphan)", sending new deps
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "provider.null"
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': walking
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': evaluating
2017/03/27 17:58:40 [TRACE] [walkPlan] Entering eval tree: provider.null
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInitProvider
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalBuildProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSetProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalConfigProvider
2017/03/27 17:58:40 [DEBUG] vertex 'root.null_resource.test (orphan)': evaluating
2017/03/27 17:58:40 [TRACE] [walkPlan] Entering eval tree: null_resource.test (orphan)
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalReadState
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalDiffDestroy
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalCheckPreventDestroy
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/03/27 17:58:40 [TRACE] [walkPlan] Exiting eval tree: null_resource.test (orphan)
2017/03/27 17:58:40 [INFO] terraform: building graph: GraphTypeApply
2017/03/27 17:58:40 [TRACE] DiffTransformer: starting
2017/03/27 17:58:40 [TRACE] DiffTransformer: Module: DESTROY: null_resource.test
2017/03/27 17:58:40 [TRACE] DiffTransformer: Resource "null_resource.test": *terraform.InstanceDiff{mu:sync.Mutex{state:0, sema:0x0}, Attributes:map[string]*terraform.ResourceAttrDiff(nil), Destroy:true, DestroyDeposed:false, DestroyTainted:false, Meta:map[string]interface {}(nil)}
2017/03/27 17:58:40 [DEBUG] Attaching resource state to "null_resource.test (destroy)": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4202a3130), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:40 [DEBUG] Attaching resource state to "null_resource.test": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4202a3130), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:40 [DEBUG] Attaching resource state to "null_resource.test (destroy)": &terraform.ResourceState{Type:"null_resource", Dependencies:[]string{}, Primary:(*terraform.InstanceState)(0xc4202a3130), Deposed:[]*terraform.InstanceState{}, Provider:"", mu:sync.Mutex{state:0, sema:0x0}}
2017/03/27 17:58:40 [TRACE] Attach provider request: []string{} null
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "null_resource.test" references: []
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "null_resource.test (destroy)" references: []
2017/03/27 17:58:40 [DEBUG] ReferenceTransformer: "provider.null" references: []
2017/03/27 17:58:40 [TRACE] DestroyEdgeTransformer: reference graph: null_resource.test
  provider.null
null_resource.test (destroy)
  provider.null
provider.null
nt-boundary (count boundary fixup) - *terraform.NodeCountBoundary
  null_resource.test (destroy) - *terraform.NodeDestroyResource
null_resource.test (destroy) - *terraform.NodeDestroyResource
  provider.null - *terraform.NodeApplyableProvider
provider.null - *terraform.NodeApplyableProvider
2017/03/27 17:58:40 [DEBUG] Starting graph walk: walkApply
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "null_resource.test (destroy)"
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "meta.count-boundary (count boundary fixup)"
2017/03/27 17:58:40 [DEBUG] dag/walk: added edge: "null_resource.test (destroy)" waiting on "provider.null"
2017/03/27 17:58:40 [DEBUG] dag/walk: added edge: "meta.count-boundary (count boundary fixup)" waiting on "null_resource.test (destroy)"
2017/03/27 17:58:40 [DEBUG] dag/walk: dependencies changed for "meta.count-boundary (count boundary fixup)", sending new deps
2017/03/27 17:58:40 [DEBUG] dag/walk: dependencies changed for "null_resource.test (destroy)", sending new deps
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "provider.null"
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': walking
2017/03/27 17:58:40 [DEBUG] vertex 'root.provider.null': evaluating
2017/03/27 17:58:40 [TRACE] [walkApply] Entering eval tree: provider.null
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInitProvider
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: terraform.EvalNoop
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalGetProvider
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalInterpolate
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalBuildProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSetProviderConfig
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalOpFilter
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalSequence
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalConfigProvider
null_resource.test: Destroying... (ID: 1079585043260643836)
2017/03/27 17:58:40 [DEBUG] plugin: terraform: null-provider (internal) 2017/03/27 17:58:40 [DEBUG] No meta timeoutkey found in Apply()
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalWriteState
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalUpdateStateHook
null_resource.test: Destruction complete
2017/03/27 17:58:40 [DEBUG] vertex 'root.null_resource.test (destroy)': expanding/walking dynamic subgraph
2017/03/27 17:58:40 [DEBUG] dag/walk: added new vertex: "root"
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "root"
2017/03/27 17:58:40 [DEBUG] vertex 'root.root': walking
2017/03/27 17:58:40 [DEBUG] dag/walk: walking "meta.count-boundary (count boundary fixup)"
2017/03/27 17:58:40 [DEBUG] vertex 'root.meta.count-boundary (count boundary fixup)': walking
2017/03/27 17:58:40 [DEBUG] vertex 'root.meta.count-boundary (count boundary fixup)': evaluating
2017/03/27 17:58:40 [TRACE] [walkApply] Entering eval tree: meta.count-boundary (count boundary fixup)
2017/03/27 17:58:40 [DEBUG] root: eval: *terraform.EvalCountFixZeroOneBoundaryGlobal
2017/03/27 17:58:40 [TRACE] [walkApply] Exiting eval tree: meta.count-boundary (count boundary fixup)

Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
2017/03/27 17:58:40 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/03/27 17:58:40 [DEBUG] plugin: terraform: null-provider (internal) 2017/03/27 17:58:40 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/03/27 17:58:40 [DEBUG] plugin: terraform: null-provider (internal) 2017/03/27 17:58:40 [ERR] plugin: plugin server: accept unix /var/folders/n0/2m8gn9696y761syj71ncx4nm0000gn/T/plugin947608875: use of closed network connection
2017/03/27 17:58:40 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.1_1/bin/terraform: plugin process exited

Expected Behavior

Destroy provisioner should run.

Actual Behavior

Destroy provisioner doesn't run.

Steps to Reproduce

  1. terraform apply
  2. Comment-out resource.
  3. terraform apply
@JouniRajalaComiq
Copy link

I am just wondering exactly same thing. I need to detach node from cluster before resource is recreated to prevent trashes left to cluster state.

@apparentlymart
Copy link
Contributor

Hi @akaspin and @JouniRajalaComiq! Sorry this didn't work out as expected.

I totally agree that this is non-ideal and counter-intuitive behavior. Unfortunately this is not a straightforward problem to fix since when the resource is removed from the configuration the configuration for its provisioner is removed too. In order to fix this properly we'd need to retain information in the state file about the set of destroy provisioners as it existed last time the configuration was applied, which we may be able to do in the long run but won't be an easy fix we can attack in the short term.

In the mean time I think the best we can do is to mention this explicitly in the documentation and include the following workaround: set count = 0 and run terraform apply once before removing the resource altogether, thus giving Terraform an opportunity to run the destroy provisioner before it is removed from the state altogether.


Design notes for future reference, for a potential enhancements to support this use-case better:

One unintended advantage of splitting out provisioner-like actions into separate top-level resources, as proposed in #6810, is that is then possible for them to "live on" after the resource is removed, thus mitigating this problem.

Another way to approach it would be to try to write the provisioner configuration into the state file, but doing that completely generically today is likely to be challenging since Terraform expects configuration to arrive in the shape the HCL decoder presents it, rather than how encoding/json presents it, and we'd additionally need to provide a way to skip running a destroy provisioner if it turns out that its configuration was broken in some way, or else the user would be permanently blocked.

apparentlymart added a commit that referenced this issue Apr 4, 2017
This addresses (via documentation) the issue raised in #13097.
apparentlymart added a commit that referenced this issue Apr 4, 2017
This addresses (via documentation) the issue raised in #13097.
@akaspin
Copy link
Author

akaspin commented Apr 4, 2017

For now I implemented very fast and dirty workaround https://github.com/akaspin/terraform-provider-generic. Just go get github.com/akaspin/terraform-provider-generic. Sorry. No docs. But works well and as bonus: no weird cycles on destroy.

@apparentlymart
Copy link
Contributor

Since we have found a few different cases of this similar issue now, I'm going to consolidate this into #13549 as an umbrella, since I expect the fix for all of these will be similar and tackled at the same time.

@ghost
Copy link

ghost commented Apr 14, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants