terraform: test happy path create-before-destroy

This commit is contained in:
Armon Dadgar 2014-09-23 11:13:50 -07:00
parent 465f3f2676
commit bce9b664d8
3 changed files with 65 additions and 0 deletions

View File

@ -582,6 +582,58 @@ func TestContextApply(t *testing.T) {
}
}
func TestContextApply_createBeforeDestroy(t *testing.T) {
c := testConfig(t, "apply-good-create-before")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
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,
})
if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
mod := state.RootModule()
if len(mod.Resources) != 1 {
t.Fatalf("bad: %#v", mod.Resources)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyCreateBeforeStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
func TestContextApply_Minimal(t *testing.T) {
m := testModule(t, "apply-minimal")
p := testProvider("aws")

View File

@ -150,6 +150,13 @@ aws_instance.foo:
type = aws_instance
`
const testTerraformApplyCreateBeforeStr = `
aws_instance.bar:
ID = foo
require_new = xyz
type = aws_instance
`
const testTerraformApplyCancelStr = `
aws_instance.foo:
ID = foo

View File

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