Skip to content

Commit

Permalink
Merge pull request #38685 from bodgit/issue-38650
Browse files Browse the repository at this point in the history
fix: Allow ROOT as a Repository Creation Template prefix
  • Loading branch information
ewbankkit authored Aug 5, 2024
2 parents 58323bb + 0fed311 commit 179a398
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changelog/38685.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_ecr_repository_creation_template: Support `ROOT` as a valid value for `prefix`
```

```release-note:bug
data-source/aws_ecr_repository_creation_template: Support `ROOT` as a valid value for `prefix`
```
4 changes: 2 additions & 2 deletions internal/service/ecr/repository_creation_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func resourceRepositoryCreationTemplate() *schema.Resource {
ValidateFunc: validation.All(
validation.StringLenBetween(2, 30),
validation.StringMatch(
regexache.MustCompile(`(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*`),
"must only include alphanumeric, underscore, period, hyphen, or slash characters"),
regexache.MustCompile(`(?:ROOT|(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*)`),
"must only include alphanumeric, underscore, period, hyphen, or slash characters, or be the string `ROOT`"),
),
},
"registry_id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func dataSourceRepositoryCreationTemplate() *schema.Resource {
ValidateFunc: validation.All(
validation.StringLenBetween(2, 30),
validation.StringMatch(
regexache.MustCompile(`(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*`),
"must only include alphanumeric, underscore, period, hyphen, or slash characters"),
regexache.MustCompile(`(?:ROOT|(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*)`),
"must only include alphanumeric, underscore, period, hyphen, or slash characters, or be the string `ROOT`"),
),
},
"registry_id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ func TestAccECRRepositoryCreationTemplateDataSource_basic(t *testing.T) {
})
}

func TestAccECRRepositoryCreationTemplateDataSource_root(t *testing.T) {
ctx := acctest.Context(t)
dataSource := "data.aws_ecr_repository_creation_template.root"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.ECRServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccRepositoryCreationTemplateDataSourceConfig_root(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSource, names.AttrPrefix, "ROOT"),
),
},
},
})
}

func testAccRepositoryCreationTemplateDataSourceConfig_basic(repositoryPrefix string) string {
return fmt.Sprintf(`
resource "aws_ecr_repository_creation_template" "test" {
Expand All @@ -66,3 +85,19 @@ data "aws_ecr_repository_creation_template" "test" {
}
`, repositoryPrefix)
}

func testAccRepositoryCreationTemplateDataSourceConfig_root() string {
return `
resource "aws_ecr_repository_creation_template" "root" {
prefix = "ROOT"
applied_for = [
"PULL_THROUGH_CACHE",
]
}
data "aws_ecr_repository_creation_template" "root" {
prefix = aws_ecr_repository_creation_template.root.prefix
}
`
}
32 changes: 32 additions & 0 deletions internal/service/ecr/repository_creation_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ func TestAccECRRepositoryCreationTemplate_repository(t *testing.T) {
})
}

func TestAccECRRepositoryCreationTemplate_root(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_ecr_repository_creation_template.root"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.ECRServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryCreationTemplateDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccRepositoryCreationTemplateConfig_root(),
Check: resource.ComposeTestCheckFunc(
testAccCheckRepositoryCreationTemplateExists(ctx, resourceName),
),
},
},
})
}

func testAccCheckRepositoryCreationTemplateDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx)
Expand Down Expand Up @@ -394,3 +414,15 @@ resource "aws_ecr_repository_creation_template" "test" {
}
`, repositoryPrefix)
}

func testAccRepositoryCreationTemplateConfig_root() string {
return `
resource "aws_ecr_repository_creation_template" "root" {
prefix = "ROOT"
applied_for = [
"PULL_THROUGH_CACHE",
]
}
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ EOT

This resource supports the following arguments:

* `prefix` - (Required, Forces new resource) The repository name prefix to match against.
* `prefix` - (Required, Forces new resource) The repository name prefix to match against. Use `ROOT` to match any prefix that doesn't explicitly match another template.
* `applied_for` - (Required) Which features this template applies to. Must contain one or more of `PULL_THROUGH_CACHE` or `REPLICATION`.
* `custom_role_arn` - (Optional) A custom IAM role to use for repository creation. Required if using repository tags or KMS encryption.
* `description` - (Optional) The description for this template.
Expand Down

0 comments on commit 179a398

Please sign in to comment.