From 4f6e610ff98b5bab9df936d90598612b96ac5d84 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Wed, 3 Jun 2015 14:45:30 +0200 Subject: [PATCH] Improve the decoding logic to prevent parameter not found errors We need to decode both the Raw config and the parsed Config to make sure all set keys are visible. Otherwise keys that will need to be interpolated later, will be missing causing the validation to fail. --- builtin/providers/azure/provider.go | 2 +- .../provisioners/chef/resource_provisioner.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azure/provider.go b/builtin/providers/azure/provider.go index beafc35870..eef0ca49c3 100644 --- a/builtin/providers/azure/provider.go +++ b/builtin/providers/azure/provider.go @@ -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{ diff --git a/builtin/provisioners/chef/resource_provisioner.go b/builtin/provisioners/chef/resource_provisioner.go index 2a8e0def63..cb5f5d6ea2 100644 --- a/builtin/provisioners/chef/resource_provisioner.go +++ b/builtin/provisioners/chef/resource_provisioner.go @@ -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 {