Merge pull request #2206 from svanharmelen/b-provisioner-chef

provisioner/chef: improve the decoding logic to prevent parameter not found errors
This commit is contained in:
Sander van Harmelen 2015-06-04 15:50:47 +02:00
commit 01f101f0e1
2 changed files with 19 additions and 1 deletions

View File

@ -45,7 +45,7 @@ func Provider() terraform.ResourceProvider {
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
settingsFile, err := homedir.Expand(d.Get("settings_file").(string))
if err != nil {
return nil, err
return nil, fmt.Errorf("Error expanding the settings file path: %s", err)
}
config := Config{

View File

@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform/communicator"
"github.com/hashicorp/terraform/communicator/remote"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-linereader"
"github.com/mitchellh/mapstructure"
)
@ -182,6 +183,15 @@ func (r *ResourceProvisioner) decodeConfig(c *terraform.ResourceConfig) (*Provis
return nil, err
}
// We need to decode this twice. Once for the Raw config and once
// for the parsed Config. This makes sure that all values are there
// even if some still need to be interpolated later on.
// Without this the validation will fail when using a variable for
// a required parameter (the node_name for example).
if err := dec.Decode(c.Raw); err != nil {
return nil, err
}
if err := dec.Decode(c.Config); err != nil {
return nil, err
}
@ -190,6 +200,14 @@ func (r *ResourceProvisioner) decodeConfig(c *terraform.ResourceConfig) (*Provis
p.Environment = defaultEnv
}
if p.ValidationKeyPath != "" {
keyPath, err := homedir.Expand(p.ValidationKeyPath)
if err != nil {
return nil, fmt.Errorf("Error expanding the validation key path: %v", err)
}
p.ValidationKeyPath = keyPath
}
if attrs, ok := c.Config["attributes"]; ok {
p.Attributes, err = rawToJSON(attrs)
if err != nil {