diff --git a/.changelog/38685.txt b/.changelog/38685.txt new file mode 100644 index 00000000000..1b3512799cd --- /dev/null +++ b/.changelog/38685.txt @@ -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` +``` \ No newline at end of file diff --git a/internal/service/ecr/repository_creation_template.go b/internal/service/ecr/repository_creation_template.go index 6eddd12ff79..257de1ad917 100644 --- a/internal/service/ecr/repository_creation_template.go +++ b/internal/service/ecr/repository_creation_template.go @@ -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": { diff --git a/internal/service/ecr/repository_creation_template_data_source.go b/internal/service/ecr/repository_creation_template_data_source.go index 9512067ad5c..1355751500a 100644 --- a/internal/service/ecr/repository_creation_template_data_source.go +++ b/internal/service/ecr/repository_creation_template_data_source.go @@ -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": { diff --git a/internal/service/ecr/repository_creation_template_data_source_test.go b/internal/service/ecr/repository_creation_template_data_source_test.go index ee357c869ee..824b95aa721 100644 --- a/internal/service/ecr/repository_creation_template_data_source_test.go +++ b/internal/service/ecr/repository_creation_template_data_source_test.go @@ -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" { @@ -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 +} +` +} diff --git a/internal/service/ecr/repository_creation_template_test.go b/internal/service/ecr/repository_creation_template_test.go index 1ff2097956e..87542e22cb5 100644 --- a/internal/service/ecr/repository_creation_template_test.go +++ b/internal/service/ecr/repository_creation_template_test.go @@ -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) @@ -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", + ] +} +` +} diff --git a/website/docs/r/ecr_repository_creation_template.html.markdown b/website/docs/r/ecr_repository_creation_template.html.markdown index 1766f18cba6..67f4b1c4947 100644 --- a/website/docs/r/ecr_repository_creation_template.html.markdown +++ b/website/docs/r/ecr_repository_creation_template.html.markdown @@ -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.