Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
Added validation to endure URL ends with /
Browse files Browse the repository at this point in the history
  • Loading branch information
terricain committed Apr 23, 2020
1 parent 7f54a47 commit baaade4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chef/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Provider() terraform.ResourceProvider {
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CHEF_SERVER_URL", nil),
Description: "URL of the root of the target Chef server or organization.",
ValidateFunc: validateServerURL,
},
"client_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -63,6 +64,14 @@ func Provider() terraform.ResourceProvider {
}
}

func validateServerURL(val interface{}, key string) (warns []string, errs []error) {
url := val.(string)
if !strings.HasSuffix(url, "/") {
errs = append(errs, fmt.Errorf("Chef Server URL %s must end with a slash", url))
}
return
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := &chefc.Config{
Name: d.Get("client_name").(string),
Expand Down

0 comments on commit baaade4

Please sign in to comment.