terraform: Testing failed apply with create_before_destroy

This commit is contained in:
Armon Dadgar 2014-09-23 10:53:29 -07:00
parent f248ae3aee
commit 59b7cb171a
3 changed files with 61 additions and 0 deletions

View File

@ -935,6 +935,55 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) {
} }
} }
func TestContextApply_error_createBeforeDestroy(t *testing.T) {
c := testConfig(t, "apply-error-create-before")
p := testProvider("aws")
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{
"require_new": "abc",
},
},
},
},
},
},
}
ctx := testContext(t, &ContextOpts{
Config: c,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: state,
})
p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) {
return nil, fmt.Errorf("error")
}
p.DiffFn = testDiffFn
if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}
state, err := ctx.Apply()
if err == nil {
t.Fatal("should have error")
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyErrorCreateBeforeDestroyStr)
if actual != expected {
t.Fatalf("bad: \n%s\n\n\n%s", actual, expected)
}
}
func TestContextApply_provisionerResourceRef(t *testing.T) { func TestContextApply_provisionerResourceRef(t *testing.T) {
m := testModule(t, "apply-provisioner-resource-ref") m := testModule(t, "apply-provisioner-resource-ref")
p := testProvider("aws") p := testProvider("aws")

View File

@ -254,6 +254,12 @@ aws_instance.foo:
num = 2 num = 2
` `
const testTerraformApplyErrorCreateBeforeDestroyStr = `
aws_instance.bar:
ID = bar
require_new = abc
`
const testTerraformApplyErrorPartialStr = ` const testTerraformApplyErrorPartialStr = `
aws_instance.bar: aws_instance.bar:
ID = bar ID = bar

View File

@ -0,0 +1,6 @@
resource "aws_instance" "bar" {
require_new = "xyz"
lifecycle {
create_before_destroy = true
}
}