Skip to content

Commit

Permalink
Support disabling validation for manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
Léon Rodenburg authored and bonifaido committed Jan 28, 2020
1 parent 7bb8793 commit 60e90fa
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func resourceManifest() *schema.Resource {
Required: true,
Sensitive: false,
},
"validate": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
}
}
Expand Down Expand Up @@ -171,15 +176,20 @@ func resourceManifestCreate(d *schema.ResourceData, m interface{}) error {
defer cleanup()

namespace, isNamespace := d.GetOk("namespace")
shouldValidate := d.Get("validate")

var cmd *exec.Cmd

err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
args := []string{"apply", "-f", "-"}
if isNamespace {
cmd = kubectl(m, kubeconfig, "apply", "-n", namespace.(string), "-f", "-")
} else {
cmd = kubectl(m, kubeconfig, "apply", "-f", "-")
args = append(args, "-n", namespace.(string))
}
if !shouldValidate.(bool) {
args = append(args, "--validate=false")
}

cmd = kubectl(m, kubeconfig, args...)
cmd.Stdin = strings.NewReader(d.Get("content").(string))
if err := run(cmd); err != nil {
return resource.RetryableError(err)
Expand Down Expand Up @@ -237,8 +247,14 @@ func resourceManifestUpdate(d *schema.ResourceData, m interface{}) error {
}
defer cleanup()

shouldValidate := d.Get("validate")

return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
cmd := kubectl(m, kubeconfig, "apply", "-f", "-")
args := []string{"apply", "-f", "-"}
if !shouldValidate.(bool) {
args = append(args, "--validate=false")
}
cmd := kubectl(m, kubeconfig, args...)
cmd.Stdin = strings.NewReader(d.Get("content").(string))
if err := run(cmd); err != nil {
return resource.RetryableError(err)
Expand Down

0 comments on commit 60e90fa

Please sign in to comment.