Skip to content

Commit

Permalink
Fix missed postrender binary path arguments parsing (#1534)
Browse files Browse the repository at this point in the history
  • Loading branch information
arybolovlev authored Nov 14, 2024
1 parent 91a5cd1 commit 1156a26
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/1534.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
`resoure/helm_release`: fix an issue where `postrender.args` is not parsed correctly.
```
22 changes: 20 additions & 2 deletions helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,16 @@ func resourceReleaseCreate(ctx context.Context, d *schema.ResourceData, meta int
upgradeClient.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)
}
Expand Down Expand Up @@ -699,7 +708,16 @@ func resourceReleaseCreate(ctx context.Context, d *schema.ResourceData, meta int
instClient.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)
}
Expand Down
12 changes: 9 additions & 3 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,11 @@ func TestAccResourceRelease_postrender(t *testing.T) {
),
},
{
Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "echo", "this will not work!", "Wrong", "Code"),
Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "echo", "invalid arguments"),
ExpectError: regexp.MustCompile("error validating data"),
},
{
Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "foobardoesnotexist"),
Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "binNotFound", ""),
ExpectError: regexp.MustCompile("unable to find binary"),
},
{
Expand All @@ -874,6 +874,12 @@ func TestAccResourceRelease_postrender(t *testing.T) {
resource.TestCheckResourceAttr("helm_release.test", "status", release.StatusDeployed.String()),
),
},
{
Config: testAccHelmReleaseConfigPostrender(testResourceName, namespace, testResourceName, "testdata/postrender.sh", "this", "that"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("helm_release.test", "status", release.StatusDeployed.String()),
),
},
},
})
}
Expand Down Expand Up @@ -1534,7 +1540,7 @@ func testAccHelmReleaseConfigPostrender(resource, ns, name, binaryPath string, a
value = 1337
}
}
`, resource, name, ns, testRepositoryURL, binaryPath, fmt.Sprintf(`["%s"]`, strings.Join(args, `","`)))
`, resource, name, ns, testRepositoryURL, binaryPath, fmt.Sprintf(`["%s"]`, strings.Join(args, `","`)))
}

func TestAccResourceRelease_LintFailValues(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions helm/testdata/postrender.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

if [ $# -ne 2 ]
then
echo "Usage: $0 <arg1> <arg2>" >&2
exit 1
fi

0 comments on commit 1156a26

Please sign in to comment.