Merge pull request #17147 from jeremiahsnapp/fix-chef-provisioner-validateFn

Fix chef provisioner validateFn
This commit is contained in:
Sander van Harmelen 2018-01-25 16:28:33 +01:00 committed by GitHub
commit 129fdb3553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import (
"os" "os"
"path" "path"
"regexp" "regexp"
"strconv"
"strings" "strings"
"sync" "sync"
"text/template" "text/template"
@ -370,18 +371,29 @@ func applyFn(ctx context.Context) error {
} }
func validateFn(c *terraform.ResourceConfig) (ws []string, es []error) { func validateFn(c *terraform.ResourceConfig) (ws []string, es []error) {
usePolicyFile, ok := c.Get("use_policyfile") usePolicyFile := false
if !ok { if usePolicyFileRaw, ok := c.Get("use_policyfile"); ok {
usePolicyFile = false switch usePolicyFileRaw := usePolicyFileRaw.(type) {
case bool:
usePolicyFile = usePolicyFileRaw
case string:
usePolicyFileBool, err := strconv.ParseBool(usePolicyFileRaw)
if err != nil {
return ws, append(es, errors.New("\"use_policyfile\" must be a boolean"))
}
usePolicyFile = usePolicyFileBool
default:
return ws, append(es, errors.New("\"use_policyfile\" must be a boolean"))
}
} }
if !usePolicyFile.(bool) && !c.IsSet("run_list") { if !usePolicyFile && !c.IsSet("run_list") {
es = append(es, errors.New("\"run_list\": required field is not set")) es = append(es, errors.New("\"run_list\": required field is not set"))
} }
if usePolicyFile.(bool) && !c.IsSet("policy_name") { if usePolicyFile && !c.IsSet("policy_name") {
es = append(es, errors.New("using policyfile, but \"policy_name\" not set")) es = append(es, errors.New("using policyfile, but \"policy_name\" not set"))
} }
if usePolicyFile.(bool) && !c.IsSet("policy_group") { if usePolicyFile && !c.IsSet("policy_group") {
es = append(es, errors.New("using policyfile, but \"policy_group\" not set")) es = append(es, errors.New("using policyfile, but \"policy_group\" not set"))
} }