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: Allow ROOT as a Repository Creation Template prefix #38685

Merged
merged 2 commits into from
Aug 5, 2024
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
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
Loading