terraform: don't execute provisioners on destroy

This commit is contained in:
Mitchell Hashimoto 2014-10-18 11:37:26 -07:00
parent b2d674b431
commit f03ab178bf
4 changed files with 72 additions and 1 deletions

View File

@ -11,6 +11,7 @@ BUG FIXES:
marked as tainted. [GH-434]
* core: Set types are validated to be sets. [GH-413]
* core: Fix crash case when destroying with tainted resources. [GH-412]
* core: Don't execute provisioners in some cases on destroy.
* providers/aws: Refresh of launch configs and autoscale groups load
the correct data and don't incorrectly recreate themselves. [GH-425]
* providers/aws: Fix case where ELB would incorrectly plan to modify

View File

@ -700,7 +700,7 @@ func (c *walkContext) applyWalkFn() depgraph.WalkFunc {
// We create a new instance if there was no ID
// previously or the diff requires re-creating the
// underlying instance
createNew := is.ID == "" || diff.RequiresNew()
createNew := (is.ID == "" && !diff.Destroy) || diff.RequiresNew()
// With the completed diff, apply!
log.Printf("[DEBUG] %s: Executing Apply", r.Id)

View File

@ -2067,6 +2067,71 @@ func TestContextApply_destroyOrphan(t *testing.T) {
}
}
func TestContextApply_destroyTaintedProvisioner(t *testing.T) {
m := testModule(t, "apply-destroy-provisioner")
p := testProvider("aws")
pr := testProvisioner()
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
called := false
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
called = true
return nil
}
s := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Tainted: []*InstanceState{
&InstanceState{
ID: "bar",
Attributes: map[string]string{
"id": "bar",
},
},
},
},
},
},
},
}
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Provisioners: map[string]ResourceProvisionerFactory{
"shell": testProvisionerFuncFixed(pr),
},
State: s,
})
if _, err := ctx.Plan(&PlanOpts{Destroy: true}); err != nil {
t.Fatalf("err: %s", err)
}
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
if called {
t.Fatal("provisioner should not be called")
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace("<no state>")
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
func TestContextApply_error(t *testing.T) {
errored := false

View File

@ -0,0 +1,5 @@
resource "aws_instance" "foo" {
id = "foo"
provisioner "shell" {}
}