diff --git a/aws/data_source_aws_ecr_repository.go b/aws/data_source_aws_ecr_repository.go index 8e7ab3f621c3..b99c91adba80 100644 --- a/aws/data_source_aws_ecr_repository.go +++ b/aws/data_source_aws_ecr_repository.go @@ -25,12 +25,29 @@ func dataSourceAwsEcrRepository() *schema.Resource { }, "registry_id": { Type: schema.TypeString, + Optional: true, Computed: true, }, "repository_url": { Type: schema.TypeString, Computed: true, }, + "image_tag_mutability": { + Type: schema.TypeString, + Computed: true, + }, + "image_scanning_configuration": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "scan_on_push": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, "tags": tagsSchemaComputed(), }, } @@ -44,7 +61,12 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er params := &ecr.DescribeRepositoriesInput{ RepositoryNames: aws.StringSlice([]string{name}), } - log.Printf("[DEBUG] Reading ECR repository: %s", params) + + if v, ok := d.GetOk("registry_id"); ok { + params.RegistryId = aws.String(v.(string)) + } + + log.Printf("[DEBUG] Reading ECR repository: %#v", params) out, err := conn.DescribeRepositories(params) if err != nil { if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") { @@ -61,6 +83,7 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er d.Set("registry_id", repository.RegistryId) d.Set("name", repository.RepositoryName) d.Set("repository_url", repository.RepositoryUri) + d.Set("image_tag_mutability", repository.ImageTagMutability) tags, err := keyvaluetags.EcrListTags(conn, arn) @@ -72,5 +95,9 @@ func dataSourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("error setting tags: %w", err) } + if err := d.Set("image_scanning_configuration", flattenImageScanningConfiguration(repository.ImageScanningConfiguration)); err != nil { + return fmt.Errorf("error setting image_scanning_configuration: %s", err) + } + return nil } diff --git a/aws/data_source_aws_ecr_repository_test.go b/aws/data_source_aws_ecr_repository_test.go index 4af5f0489bb3..1e48c2467962 100644 --- a/aws/data_source_aws_ecr_repository_test.go +++ b/aws/data_source_aws_ecr_repository_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccAWSEcrDataSource_ecrRepository(t *testing.T) { +func TestAccAWSEcrRepositoryDataSource_basic(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_ecr_repository.test" dataSourceName := "data.aws_ecr_repository.test" @@ -25,13 +25,15 @@ func TestAccAWSEcrDataSource_ecrRepository(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "registry_id", dataSourceName, "registry_id"), resource.TestCheckResourceAttrPair(resourceName, "repository_url", dataSourceName, "repository_url"), resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"), + resource.TestCheckResourceAttrPair(resourceName, "image_scanning_configuration.#", dataSourceName, "image_scanning_configuration.#"), + resource.TestCheckResourceAttrPair(resourceName, "image_tag_mutability", dataSourceName, "image_tag_mutability"), ), }, }, }) } -func TestAccAWSEcrDataSource_nonExistent(t *testing.T) { +func TestAccAWSEcrRepositoryDataSource_nonExistent(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/website/docs/d/ecr_repository.html.markdown b/website/docs/d/ecr_repository.html.markdown index 8f7f97f8b7b8..ead90cd0fb66 100644 --- a/website/docs/d/ecr_repository.html.markdown +++ b/website/docs/d/ecr_repository.html.markdown @@ -23,12 +23,19 @@ data "aws_ecr_repository" "service" { The following arguments are supported: * `name` - (Required) The name of the ECR Repository. +* `registry_id` - (Optional) The registry ID where the repository was created. ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `arn` - Full ARN of the repository. -* `registry_id` - The registry ID where the repository was created. * `repository_url` - The URL of the repository (in the form `aws_account_id.dkr.ecr.region.amazonaws.com/repositoryName`). +* `image_tag_mutability` - The tag mutability setting for the repository. +* `image_scanning_configuration` - Configuration block that defines image scanning configuration for the repository. see [Image Scanning Configuration](#image-scanning-configuration) * `tags` - A map of tags assigned to the resource. + +### Image Scanning Configuration + +* `scan_on_push` - Indicates whether images are scanned after being pushed to the repository. +