Skip to content

Commit

Permalink
Fix perpetual diff when setting version to empty string (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston committed Sep 6, 2023
1 parent 6bf6c4d commit 7aacef7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/1246.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
`helm_release`: Fix perpetual diff when version attribute is an empty string
```

2 changes: 1 addition & 1 deletion helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{})
old, new := d.GetChange("version")
oldVersion := strings.TrimPrefix(old.(string), "v")
newVersion := strings.TrimPrefix(new.(string), "v")
if oldVersion != newVersion {
if oldVersion != newVersion && newVersion != "" {
d.SetNewComputed("metadata")
}
}
Expand Down
44 changes: 44 additions & 0 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ func TestAccResourceRelease_basic(t *testing.T) {
})
}

// NOTE this is a regression test for: https://github.com/hashicorp/terraform-provider-helm/issues/1236
func TestAccResourceRelease_emptyVersion(t *testing.T) {
name := randName("basic")
namespace := createRandomNamespace(t)
defer deleteNamespace(t, namespace)

resourceName := "helm_release.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: map[string]func() (*schema.Provider, error){
"helm": func() (*schema.Provider, error) {
return Provider(), nil
},
},
CheckDestroy: testAccCheckHelmReleaseDestroy(namespace),
Steps: []resource.TestStep{
{
Config: testAccHelmReleaseConfigEmptyVersion(testResourceName, namespace, name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name),
resource.TestCheckResourceAttr(resourceName, "metadata.0.namespace", namespace),
resource.TestCheckResourceAttr(resourceName, "metadata.0.revision", "1"),
resource.TestCheckResourceAttr(resourceName, "status", release.StatusDeployed.String()),
resource.TestCheckResourceAttr(resourceName, "metadata.0.chart", "test-chart"),
resource.TestCheckResourceAttr(resourceName, "metadata.0.version", "2.0.0"),
resource.TestCheckResourceAttr(resourceName, "metadata.0.app_version", "1.19.5"),
),
},
},
})
}

func TestAccResourceRelease_import(t *testing.T) {
name := randName("import")
namespace := createRandomNamespace(t)
Expand Down Expand Up @@ -875,6 +907,18 @@ func testAccHelmReleaseConfigBasic(resource, ns, name, version string) string {
`, resource, name, ns, testRepositoryURL, version)
}

func testAccHelmReleaseConfigEmptyVersion(resource, ns, name string) string {
return fmt.Sprintf(`
resource "helm_release" "%s" {
name = %q
namespace = %q
repository = %q
chart = "test-chart"
version = ""
}
`, resource, name, ns, testRepositoryURL)
}

func testAccHelmReleaseConfigValues(resource, ns, name, chart, version string, values []string) string {
vals := make([]string, len(values))
for i, v := range values {
Expand Down

0 comments on commit 7aacef7

Please sign in to comment.