Skip to content

Commit

Permalink
add support for helm literal values
Browse files Browse the repository at this point in the history
  • Loading branch information
rjinski committed Oct 24, 2024
1 parent 24ec7ae commit 049e6ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions helm/data_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func dataTemplate() *schema.Resource {
// TODO: use ValidateDiagFunc once an SDK v2 version of StringInSlice exists.
// https://github.com/hashicorp/terraform-plugin-sdk/issues/534
ValidateFunc: validation.StringInSlice([]string{
"auto", "string",
"auto", "string", "literal",
}, false),
},
},
Expand Down Expand Up @@ -167,7 +167,7 @@ func dataTemplate() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"auto", "string",
"auto", "string", "literal",
}, false),
},
},
Expand Down
8 changes: 6 additions & 2 deletions helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func resourceRelease() *schema.Resource {
// TODO: use ValidateDiagFunc once an SDK v2 version of StringInSlice exists.
// https://github.com/hashicorp/terraform-plugin-sdk/issues/534
ValidateFunc: validation.StringInSlice([]string{
"auto", "string",
"auto", "string", "literal",
}, false),
},
},
Expand Down Expand Up @@ -204,7 +204,7 @@ func resourceRelease() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"auto", "string",
"auto", "string", "literal",
}, false),
},
},
Expand Down Expand Up @@ -1394,6 +1394,10 @@ func getValue(base, set map[string]interface{}) error {
if err := strvals.ParseIntoString(fmt.Sprintf("%s=%s", name, value), base); err != nil {
return fmt.Errorf("failed parsing key %q with value %s, %s", name, value, err)
}
case "literal":
if err := strvals.ParseLiteralInto(fmt.Sprintf("%s=%s", name, value), base); err != nil {
return fmt.Errorf("failed parsing key %q with value %s, %s", name, value, err)
}
default:
return fmt.Errorf("unexpected type: %s", valueType)
}
Expand Down
21 changes: 21 additions & 0 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,27 @@ func TestGetValuesString(t *testing.T) {
}
}

func TestGetValuesLiteral(t *testing.T) {
d := resourceRelease().Data(nil)
err := d.Set("set", []interface{}{
map[string]interface{}{"name": "foo", "value": "{[]_who", "type": "literal"},
})
if err != nil {
t.Fatalf("error setting values: %s", err)
return
}

values, err := getValues(d)
if err != nil {
t.Fatalf("error getValues: %s", err)
return
}

if values["foo"] != "{[]_who" {
t.Fatalf("error merging values, expected %q, got %s", "{[]_who", values["foo"])
}
}

func TestUseChartVersion(t *testing.T) {

type test struct {
Expand Down

0 comments on commit 049e6ef

Please sign in to comment.