From 8e8da82915b1789ce6da6868f20928a53df64cc3 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Wed, 1 Jun 2022 17:50:28 -0700 Subject: [PATCH 1/6] add args attribute to postrender block --- helm/resource_release.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/helm/resource_release.go b/helm/resource_release.go index 92c9a6eae2..d0977ad06e 100644 --- a/helm/resource_release.go +++ b/helm/resource_release.go @@ -537,7 +537,14 @@ func resourceReleaseCreate(ctx context.Context, d *schema.ResourceData, meta int 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").([]interface{}) + var args []string + for _,arg := range av { + args = append(args, arg.(string)) + } + + pr, err := postrender.NewExec(cmd, args...) + if err != nil { return diag.FromErr(err) @@ -646,7 +653,14 @@ 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").([]interface{}) + var args []string + for _,arg := range av { + args = append(args, arg.(string)) + } + + pr, err := postrender.NewExec(cmd, args...) + if err != nil { return diag.FromErr(err) @@ -795,7 +809,14 @@ 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").([]interface{}) + var args []string + for _,arg := range av { + args = append(args, arg.(string)) + } + + pr, err := postrender.NewExec(cmd, args...) + if err != nil { return err } From 400811519668b0d5dcee4c5b7811f789bb2e8ae6 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 2 Jun 2022 15:41:37 -0700 Subject: [PATCH 2/6] add test for args / fix nil edge case --- helm/resource_release.go | 31 +++++++++++++++++++++------- helm/resource_release_test.go | 17 +++++++++++---- website/docs/r/release.html.markdown | 2 ++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/helm/resource_release.go b/helm/resource_release.go index d0977ad06e..6eae859e99 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}, + }, }, }, }, @@ -537,15 +543,19 @@ func resourceReleaseCreate(ctx context.Context, d *schema.ResourceData, meta int client.CreateNamespace = d.Get("create_namespace").(bool) if cmd := d.Get("postrender.0.binary_path").(string); cmd != "" { - av := d.Get("postrender.0.args").([]interface{}) + av := d.Get("postrender.0.args") + var args []string - for _,arg := range av { + + 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) } @@ -653,15 +663,17 @@ 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 != "" { - av := d.Get("postrender.0.args").([]interface{}) + av := d.Get("postrender.0.args") var args []string - for _,arg := range av { + 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) } @@ -809,9 +821,12 @@ 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 != "" { - av := d.Get("postrender.0.args").([]interface{}) + av := d.Get("postrender.0.args") var args []string - for _,arg := range av { + for _, arg := range av.([]interface{}) { + if arg == nil { + continue + } args = append(args, arg.(string)) } 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..bbb6e7aade 100644 --- a/website/docs/r/release.html.markdown +++ b/website/docs/r/release.html.markdown @@ -132,6 +132,8 @@ The `set` and `set_sensitive` blocks support: The `postrender` block supports a single attribute: * `binary_path` - (Required) relative or full path to command binary. +* `args` - (Optional) an argument to the post-renderer (can specify multiple) + ## Attributes Reference From 741be9c235e178fc29aa8ac04d38617248506970 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 2 Jun 2022 15:47:21 -0700 Subject: [PATCH 3/6] add to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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) From 0bb994c6cd67094582d4fd4e428ff52b03dda73d Mon Sep 17 00:00:00 2001 From: BBBmau Date: Thu, 2 Jun 2022 16:11:09 -0700 Subject: [PATCH 4/6] fixed typo --- website/docs/r/release.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/release.html.markdown b/website/docs/r/release.html.markdown index bbb6e7aade..1ba226a011 100644 --- a/website/docs/r/release.html.markdown +++ b/website/docs/r/release.html.markdown @@ -129,7 +129,7 @@ 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) an argument to the post-renderer (can specify multiple) From 331cbd05e97bfb23dac0d7014b2022b9053c581f Mon Sep 17 00:00:00 2001 From: Mauricio Alvarez Leon <65101411+BBBmau@users.noreply.github.com> Date: Mon, 6 Jun 2022 20:51:01 -0700 Subject: [PATCH 5/6] Update release.html.markdown update to args description --- website/docs/r/release.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/release.html.markdown b/website/docs/r/release.html.markdown index 1ba226a011..6e303b84d0 100644 --- a/website/docs/r/release.html.markdown +++ b/website/docs/r/release.html.markdown @@ -132,7 +132,7 @@ The `set` and `set_sensitive` blocks support: The `postrender` block supports two attributes: * `binary_path` - (Required) relative or full path to command binary. -* `args` - (Optional) an argument to the post-renderer (can specify multiple) +* `args` - (Optional) a list of arguments to supply to the post-renderer. From d4dda46f7311990e09ad3a53f708a56a072736f8 Mon Sep 17 00:00:00 2001 From: Mauricio Alvarez Leon <65101411+BBBmau@users.noreply.github.com> Date: Mon, 6 Jun 2022 20:57:05 -0700 Subject: [PATCH 6/6] Update resource_release.go format to match other similar lines --- helm/resource_release.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/helm/resource_release.go b/helm/resource_release.go index 6eae859e99..9e1153e4be 100644 --- a/helm/resource_release.go +++ b/helm/resource_release.go @@ -541,12 +541,10 @@ 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 != "" { av := d.Get("postrender.0.args") - var args []string - for _, arg := range av.([]interface{}) { if arg == nil { continue