terraform: Testing failed apply with create_before_destroy
This commit is contained in:
parent
f248ae3aee
commit
59b7cb171a
|
@ -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) {
|
||||
m := testModule(t, "apply-provisioner-resource-ref")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -254,6 +254,12 @@ aws_instance.foo:
|
|||
num = 2
|
||||
`
|
||||
|
||||
const testTerraformApplyErrorCreateBeforeDestroyStr = `
|
||||
aws_instance.bar:
|
||||
ID = bar
|
||||
require_new = abc
|
||||
`
|
||||
|
||||
const testTerraformApplyErrorPartialStr = `
|
||||
aws_instance.bar:
|
||||
ID = bar
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
resource "aws_instance" "bar" {
|
||||
require_new = "xyz"
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue