terraform: Test provisioner apply

This commit is contained in:
Armon Dadgar 2014-07-09 10:36:49 -07:00
parent 03a20f072e
commit cfc7b69bb1
3 changed files with 63 additions and 0 deletions

View File

@ -339,6 +339,48 @@ func TestContextApply_compute(t *testing.T) {
}
}
func TestContextApply_Provisioner_compute(t *testing.T) {
c := testConfig(t, "apply-provisioner-compute")
p := testProvider("aws")
pr := testProvisioner()
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
pr.ApplyFn = func(rs *ResourceState, c *ResourceConfig) (*ResourceState, error) {
return rs, nil
}
ctx := testContext(t, &ContextOpts{
Config: c,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Provisioners: map[string]ResourceProvisionerFactory{
"shell": testProvisionerFuncFixed(pr),
},
})
if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}
ctx.variables = map[string]string{"value": "1"}
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyProvisionerStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
// Verify apply was invoked
if !pr.ApplyCalled {
t.Fatalf("provisioner not invoked")
}
}
func TestContextApply_destroy(t *testing.T) {
c := testConfig(t, "apply-destroy")
h := new(HookRecordApplyOrder)

View File

@ -120,6 +120,16 @@ aws_instance.foo:
ID = foo
`
const testTerraformApplyProvisionerStr = `
aws_instance.bar:
ID = foo
aws_instance.foo:
ID = foo
dynamical = computed_dynamical
num = 2
type = aws_instance
`
const testTerraformApplyDestroyStr = `
<no state>
`

View File

@ -0,0 +1,11 @@
resource "aws_instance" "foo" {
num = "2"
compute = "dynamical"
compute_value = "${var.value}"
}
resource "aws_instance" "bar" {
provisioner "shell" {
foo = "${aws_instance.foo.dynamical}"
}
}