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 {
// Interpolate since we may have variables that depend on the
// local resource.
if err := r.Config.interpolate(c); err != nil {
if err := prov.Config.interpolate(c); err != nil {
return rs, err
}
// Invoke the Provisioner
rs, err = prov.Provisioner.Apply(rs, r.Config)
rs, err = prov.Provisioner.Apply(rs, prov.Config)
if err != nil {
return rs, err
}

View File

@ -352,6 +352,10 @@ func TestContextApply_Provisioner_compute(t *testing.T) {
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
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
}
ctx := testContext(t, &ContextOpts{
@ -362,14 +366,15 @@ func TestContextApply_Provisioner_compute(t *testing.T) {
Provisioners: map[string]ResourceProvisionerFactory{
"shell": testProvisionerFuncFixed(pr),
},
Variables: map[string]string{
"value": "1",
},
})
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)