Skip to content

Commit

Permalink
Add 'name' field validation to be limited to 53 characters (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
arybolovlev authored Aug 17, 2023
1 parent 1739e71 commit 7015b80
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/1228.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
`resource/helm_release`: add `name` field validation to be limited to 53 characters.
```
9 changes: 5 additions & 4 deletions helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ func resourceRelease() *schema.Resource {
CustomizeDiff: resourceDiff,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Release name.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 53),
Description: "Release name. The length must not be longer than 53 characters.",
},
"repository": {
Type: schema.TypeString,
Expand Down
22 changes: 22 additions & 0 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,28 @@ func TestAccResourceRelease_updateSetValue(t *testing.T) {
})
}

func TestAccResourceRelease_validation(t *testing.T) {
invalidName := "this-helm-release-name-is-longer-than-53-characters-long"
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, invalidName, "1.2.3"),
ExpectError: regexp.MustCompile("expected length of name to be in the range.*"),
},
},
})
}

func checkResourceAttrExists(name, key string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/release.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ resource "helm_release" "example" {

The following arguments are supported:

* `name` - (Required) Release name.
* `name` - (Required) Release name. The length must not be longer than 53 characters.
* `chart` - (Required) Chart name to be installed. The chart name can be local path, a URL to a chart, or the name of the chart if `repository` is specified. It is also possible to use the `<repository>/<chart>` format here if you are running Terraform on a system that the repository has been added to with `helm repo add` but this is not recommended.
* `repository` - (Optional) Repository URL where to locate the requested chart.
* `repository_key_file` - (Optional) The repositories cert key file
Expand Down

0 comments on commit 7015b80

Please sign in to comment.