Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: only recompute metadata when the version in the metadata changes #1458

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1458.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
`resource/helm_release`: Fix: only recompute metadata when the version in the metadata changes
```
10 changes: 4 additions & 6 deletions helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,18 +930,16 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{})
}
if d.HasChanges(recomputeMetadataFields...) {
d.SetNewComputed("metadata")
}

if !useChartVersion(d.Get("chart").(string), d.Get("repository").(string)) {
if d.HasChange("version") {
} else if !useChartVersion(d.Get("chart").(string), d.Get("repository").(string)) {
if d.HasChange("metadata.0.version") {
// only recompute metadata if the version actually changes
// chart versioning is not consistent and some will add
// a `v` prefix to the chart version after installation
old, new := d.GetChange("version")
old, new := d.GetChange("metadata.0.version")
oldVersion := strings.TrimPrefix(old.(string), "v")
newVersion := strings.TrimPrefix(new.(string), "v")
debug("%s oldVersion: %s, newVersion: %s", logID, oldVersion, newVersion)
if oldVersion != newVersion && newVersion != "" {
if oldVersion != newVersion {
d.SetNewComputed("metadata")
}
}
Expand Down
42 changes: 42 additions & 0 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,48 @@ func TestAccResourceRelease_emptyVersion(t *testing.T) {
})
}

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

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: testAccHelmReleaseConfigBasic(testResourceName, namespace, name, "v1.2"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("helm_release.test", "version", "1.2.3"),
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.version", "1.2.3"),
),
},
{
Config: testAccHelmReleaseConfigBasic(testResourceName, namespace, name, "1.2"),
PlanOnly: true,
},
{
Config: testAccHelmReleaseConfigBasic(testResourceName, namespace, name, "v1.2.x"),
PlanOnly: true,
},
{
Config: testAccHelmReleaseConfigBasic(testResourceName, namespace, name, "1.2.x"),
PlanOnly: true,
},
{
Config: testAccHelmReleaseConfigBasic(testResourceName, namespace, name, "~1.2.2"),
PlanOnly: true,
},
},
})
}

// "upgrade_install" without a previously installed release (effectively equivalent to TestAccResourceRelease_basic)
func TestAccResourceRelease_upgrade_with_install_coldstart(t *testing.T) {
name := randName("basic")
Expand Down
Loading