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

Larger diff than expected when updating helm_release 'set' 'value' #916

Merged
merged 2 commits into from
Oct 18, 2022
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
1 change: 1 addition & 0 deletions helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func resourceRelease() *schema.Resource {
"type": {
Type: schema.TypeString,
Optional: true,
Default: "",
// TODO: use ValidateDiagFunc once an SDK v2 version of StringInSlice exists.
// https://github.com/hashicorp/terraform-plugin-sdk/issues/534
ValidateFunc: validation.StringInSlice([]string{
Expand Down
78 changes: 78 additions & 0 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,61 @@ func TestAccResourceRelease_updateExistingFailed(t *testing.T) {
})
}

func TestAccResourceRelease_updateSetValue(t *testing.T) {
name := randName("test-update-set-value")
namespace := createRandomNamespace(t)
defer deleteNamespace(t, namespace)

// Ensure that 'set' 'type' arguments don't disappear when updating a 'set' 'value' argument.
// use checkResourceAttrExists rather than testCheckResourceAttrSet as the latter also checks if the value is not ""
// and the default for 'type' is an empty string when not explicitly set.
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckHelmReleaseDestroy(namespace),
Steps: []resource.TestStep{
{
Config: testAccHelmReleaseConfigSet(
testResourceName, namespace, name, "1.2.3", "initial",
),
Check: resource.ComposeAggregateTestCheckFunc(
checkResourceAttrExists("helm_release.test", "set.0.type"),
checkResourceAttrExists("helm_release.test", "set.1.type"),
),
},
{
Config: testAccHelmReleaseConfigSet(
testResourceName, namespace, name, "1.2.3", "updated",
),
Check: resource.ComposeAggregateTestCheckFunc(
checkResourceAttrExists("helm_release.test", "set.0.type"),
checkResourceAttrExists("helm_release.test", "set.1.type"),
),
},
},
})
}

func checkResourceAttrExists(name, key string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
rs, ok := ms.Resources[name]
if !ok {
return fmt.Errorf("Not found: %s in %s", name, ms.Path)
}

is := rs.Primary
if is == nil {
return fmt.Errorf("No primary instance: %s in %s", name, ms.Path)
}

if _, ok := is.Attributes[key]; ok {
return nil
}
return fmt.Errorf("%s: Attribute '%s' expected to be set", name, key)
}
}

func TestAccResourceRelease_postrender(t *testing.T) {
// TODO: Add Test Fixture to return real YAML here

Expand Down Expand Up @@ -676,6 +731,29 @@ func testAccHelmReleaseConfigSensitiveValue(resource, ns, name, chart, version s
`, resource, name, ns, testRepositoryURL, chart, version, key, value)
}

func testAccHelmReleaseConfigSet(resource, ns, name, version, setValue string) string {
return fmt.Sprintf(`
resource "helm_release" "%s" {
name = %q
namespace = %q
description = "Test"
repository = %q
chart = "test-chart"
version = %q

set {
name = "foo"
value = %q
}

set {
name = "fizz"
value = 1337
}
}
`, resource, name, ns, testRepositoryURL, version, setValue)
}

func TestGetValues(t *testing.T) {
d := resourceRelease().Data(nil)
err := d.Set("values", []string{
Expand Down