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"
"path"
"regexp"
"strconv"
"strings"
"sync"
"text/template"
@ -370,18 +371,29 @@ func applyFn(ctx context.Context) error {
}
func validateFn(c *terraform.ResourceConfig) (ws []string, es []error) {
usePolicyFile, ok := c.Get("use_policyfile")
if !ok {
usePolicyFile = false
usePolicyFile := false
if usePolicyFileRaw, ok := c.Get("use_policyfile"); ok {
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"))
}
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"))
}
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"))
}