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 ecr_repository_prefix validation in aws_ecr_pull_through_cache_rule #34716

Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions .changelog/34716.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_ecr_pull_through_cache_rule: Fix plan time validation for `ecr_repository_prefix`
```

```release-note:bug
data-source/aws_ecr_pull_through_cache_rule: Fix plan time validation for `ecr_repository_prefix`
```
6 changes: 3 additions & 3 deletions internal/service/ecr/pull_through_cache_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func ResourcePullThroughCacheRule() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(2, 20),
validation.StringLenBetween(2, 30),
validation.StringMatch(
regexache.MustCompile(`^[0-9a-z]+(?:[._-][0-9a-z]+)*$`),
"must only include alphanumeric, underscore, period, or hyphen characters"),
regexache.MustCompile(`(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*`),
"must only include alphanumeric, underscore, period, hyphen, or slash characters"),
),
},
"registry_id": {
Expand Down
6 changes: 3 additions & 3 deletions internal/service/ecr/pull_through_cache_rule_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func DataSourcePullThroughCacheRule() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(2, 20),
validation.StringLenBetween(2, 30),
validation.StringMatch(
regexache.MustCompile(`^[0-9a-z]+(?:[._-][0-9a-z]+)*$`),
"must only include alphanumeric, underscore, period, or hyphen characters"),
regexache.MustCompile(`(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*`),
"must only include alphanumeric, underscore, period, hyphen, or slash characters"),
),
},
"registry_id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package ecr_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/ecr"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)
Expand All @@ -31,6 +33,28 @@ func TestAccECRPullThroughCacheRuleDataSource_basic(t *testing.T) {
})
}

func TestAccECRPullThroughCacheRuleDataSource_ecrRepositoryPrefixWithSlash(t *testing.T) {
ctx := acctest.Context(t)
repositoryPrefix := "tf-test/" + sdkacctest.RandString(22)
dataSource := "data.aws_ecr_pull_through_cache_rule.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ecr.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckPullThroughCacheRuleDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccPullThroughCacheRuleDataSourceConfig_ecrRepositoryPrefixWithSlash(repositoryPrefix),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSource, "upstream_registry_url", "public.ecr.aws"),
acctest.CheckResourceAttrAccountID(dataSource, "registry_id"),
),
},
},
})
}

func testAccPullThroughCacheRuleDataSourceConfig_basic() string {
return `
resource "aws_ecr_pull_through_cache_rule" "test" {
Expand All @@ -43,3 +67,16 @@ data "aws_ecr_pull_through_cache_rule" "test" {
}
`
}

func testAccPullThroughCacheRuleDataSourceConfig_ecrRepositoryPrefixWithSlash(repositoryPrefix string) string {
return fmt.Sprintf(`
resource "aws_ecr_pull_through_cache_rule" "test" {
ecr_repository_prefix = %[1]q
upstream_registry_url = "public.ecr.aws"
}

data "aws_ecr_pull_through_cache_rule" "test" {
ecr_repository_prefix = aws_ecr_pull_through_cache_rule.test.ecr_repository_prefix
}
`, repositoryPrefix)
}
24 changes: 24 additions & 0 deletions internal/service/ecr/pull_through_cache_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ func TestAccECRPullThroughCacheRule_failWhenAlreadyExists(t *testing.T) {
})
}

func TestAccECRPullThroughCacheRule_ecrRepositoryPrefixWithSlash(t *testing.T) {
ctx := acctest.Context(t)
repositoryPrefix := "tf-test/" + sdkacctest.RandString(22)
resourceName := "aws_ecr_pull_through_cache_rule.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ecr.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckPullThroughCacheRuleDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccPullThroughCacheRuleConfig_basic(repositoryPrefix),
Check: resource.ComposeTestCheckFunc(
testAccCheckPullThroughCacheRuleExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "ecr_repository_prefix", repositoryPrefix),
testAccCheckPullThroughCacheRuleRegistryID(resourceName),
resource.TestCheckResourceAttr(resourceName, "upstream_registry_url", "public.ecr.aws"),
),
},
},
})
}

func testAccCheckPullThroughCacheRuleDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx)
Expand Down
Loading