terraform: Fix and test provisioner configs

This commit is contained in:
Armon Dadgar 2014-07-09 15:49:57 -07:00
parent c8bc5658ab
commit 83c1ed438f
2 changed files with 9 additions and 4 deletions

View File

@ -532,12 +532,12 @@ func (c *Context) applyProvisioners(r *Resource, rs *ResourceState) (*ResourceSt
for _, prov := range r.Provisioners { for _, prov := range r.Provisioners {
// Interpolate since we may have variables that depend on the // Interpolate since we may have variables that depend on the
// local resource. // local resource.
if err := r.Config.interpolate(c); err != nil { if err := prov.Config.interpolate(c); err != nil {
return rs, err return rs, err
} }
// Invoke the Provisioner // Invoke the Provisioner
rs, err = prov.Provisioner.Apply(rs, r.Config) rs, err = prov.Provisioner.Apply(rs, prov.Config)
if err != nil { if err != nil {
return rs, err return rs, err
} }

View File

@ -352,6 +352,10 @@ func TestContextApply_Provisioner_compute(t *testing.T) {
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
pr.ApplyFn = func(rs *ResourceState, c *ResourceConfig) (*ResourceState, error) { pr.ApplyFn = func(rs *ResourceState, c *ResourceConfig) (*ResourceState, error) {
val, ok := c.Config["foo"]
if !ok || val != "computed_dynamical" {
t.Fatalf("bad value for foo: %v %#v", val, c)
}
return rs, nil return rs, nil
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
@ -362,14 +366,15 @@ func TestContextApply_Provisioner_compute(t *testing.T) {
Provisioners: map[string]ResourceProvisionerFactory{ Provisioners: map[string]ResourceProvisionerFactory{
"shell": testProvisionerFuncFixed(pr), "shell": testProvisionerFuncFixed(pr),
}, },
Variables: map[string]string{
"value": "1",
},
}) })
if _, err := ctx.Plan(nil); err != nil { if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
ctx.variables = map[string]string{"value": "1"}
state, err := ctx.Apply() state, err := ctx.Apply()
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)