diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f4b85c142..6f8c1f2cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.6.0 * Upgrade helm to 3.9.0 +* Add args attribute in post-render block ## 2.5.1 (April 11, 2022) diff --git a/helm/resource_release.go b/helm/resource_release.go index 92c9a6eae2..9e1153e4be 100644 --- a/helm/resource_release.go +++ b/helm/resource_release.go @@ -335,6 +335,12 @@ func resourceRelease() *schema.Resource { Required: true, Description: "The command binary path.", }, + "args": { + Type: schema.TypeList, + Optional: true, + Description: "an argument to the post-renderer (can specify multiple)", + Elem: &schema.Schema{Type: schema.TypeString}, + }, }, }, }, @@ -535,9 +541,18 @@ func resourceReleaseCreate(ctx context.Context, d *schema.ResourceData, meta int client.Replace = d.Get("replace").(bool) client.Description = d.Get("description").(string) client.CreateNamespace = d.Get("create_namespace").(bool) - + if cmd := d.Get("postrender.0.binary_path").(string); cmd != "" { - pr, err := postrender.NewExec(cmd) + av := d.Get("postrender.0.args") + var args []string + for _, arg := range av.([]interface{}) { + if arg == nil { + continue + } + args = append(args, arg.(string)) + } + + pr, err := postrender.NewExec(cmd, args...) if err != nil { return diag.FromErr(err) @@ -646,7 +661,16 @@ func resourceReleaseUpdate(ctx context.Context, d *schema.ResourceData, meta int client.Description = d.Get("description").(string) if cmd := d.Get("postrender.0.binary_path").(string); cmd != "" { - pr, err := postrender.NewExec(cmd) + av := d.Get("postrender.0.args") + var args []string + for _, arg := range av.([]interface{}) { + if arg == nil { + continue + } + args = append(args, arg.(string)) + } + + pr, err := postrender.NewExec(cmd, args...) if err != nil { return diag.FromErr(err) @@ -795,7 +819,17 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) client.Description = d.Get("description").(string) if cmd := d.Get("postrender.0.binary_path").(string); cmd != "" { - pr, err := postrender.NewExec(cmd) + av := d.Get("postrender.0.args") + var args []string + for _, arg := range av.([]interface{}) { + if arg == nil { + continue + } + args = append(args, arg.(string)) + } + + pr, err := postrender.NewExec(cmd, args...) + if err != nil { return err } diff --git a/helm/resource_release_test.go b/helm/resource_release_test.go index 69371eea92..f8fbfb61e7 100644 --- a/helm/resource_release_test.go +++ b/helm/resource_release_test.go @@ -488,6 +488,8 @@ func TestAccResourceRelease_updateExistingFailed(t *testing.T) { } func TestAccResourceRelease_postrender(t *testing.T) { + // TODO: Add Test Fixture to return real YAML here + namespace := createRandomNamespace(t) defer deleteNamespace(t, namespace) @@ -497,19 +499,25 @@ func TestAccResourceRelease_postrender(t *testing.T) { CheckDestroy: testAccCheckHelmReleaseDestroy(namespace), Steps: []resource.TestStep{ { - Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "cat"), + Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "echo"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("helm_release.test", "status", release.StatusDeployed.String()), ), }, { - Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "date"), + Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "echo", "this will not work!", "Wrong", "Code"), ExpectError: regexp.MustCompile("error validating data"), }, { Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "foobardoesnotexist"), ExpectError: regexp.MustCompile("unable to find binary"), }, + { + Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "true", "Hello", "World", "!"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("helm_release.test", "status", release.StatusDeployed.String()), + ), + }, }, }) } @@ -917,7 +925,7 @@ func testAccCheckHelmReleaseDestroy(namespace string) resource.TestCheckFunc { } } -func testAccHelmReleaseConfigPostrender(resource, ns, name, binaryPath string) string { +func testAccHelmReleaseConfigPostrender(resource, ns, name, binaryPath string, args ...string) string { return fmt.Sprintf(` resource "helm_release" "%s" { name = %q @@ -928,6 +936,7 @@ func testAccHelmReleaseConfigPostrender(resource, ns, name, binaryPath string) s postrender { binary_path = %q + args = %s } set { @@ -939,7 +948,7 @@ func testAccHelmReleaseConfigPostrender(resource, ns, name, binaryPath string) s value = 1337 } } - `, resource, name, ns, testRepositoryURL, binaryPath) + `, resource, name, ns, testRepositoryURL, binaryPath, fmt.Sprintf(`["%s"]`, strings.Join(args, `","`))) } func TestAccResourceRelease_LintFailValues(t *testing.T) { diff --git a/website/docs/r/release.html.markdown b/website/docs/r/release.html.markdown index d262c62aec..6e303b84d0 100644 --- a/website/docs/r/release.html.markdown +++ b/website/docs/r/release.html.markdown @@ -129,9 +129,11 @@ The `set` and `set_sensitive` blocks support: * `value` - (Required) value of the variable to be set. * `type` - (Optional) type of the variable to be set. Valid options are `auto` and `string`. -The `postrender` block supports a single attribute: +The `postrender` block supports two attributes: * `binary_path` - (Required) relative or full path to command binary. +* `args` - (Optional) a list of arguments to supply to the post-renderer. + ## Attributes Reference