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

New DataSource: aws_ecr_repositories #34446

Merged
merged 21 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
af96ad4
go get github.com/aws/aws-sdk-go-v2
brittandeyoung Nov 16, 2023
30a5852
names: Amend names_data.csv, enable sdkv2 client for ecr
brittandeyoung Nov 16, 2023
26b456f
conns: Amend awsclient_gen.go, generate ecr_sdkv2
brittandeyoung Nov 16, 2023
11f48da
Merge remote-tracking branch 'upstream/main' into f-aws_ecr_repositories
brittandeyoung Nov 16, 2023
a5ad02d
ecr: Add repositories_data_source
brittandeyoung Nov 16, 2023
bd58695
ecr: Add repositories_data_source_test
brittandeyoung Nov 16, 2023
23847c0
ecr: Amend service_package_gen, add repositories_data_source
brittandeyoung Nov 16, 2023
fc9f637
website: Add ecr_repositories
brittandeyoung Nov 16, 2023
d4827e3
Revert "go get github.com/aws/aws-sdk-go-v2"
brittandeyoung Nov 16, 2023
d3fa6ab
go get github.com/aws/aws-sdk-go-v2/service/ecr@v1.21
brittandeyoung Nov 16, 2023
e0271f7
ecr: Amend consts, add ServiceID as it does not exist in sdkv2
brittandeyoung Nov 16, 2023
cbc78e9
ecr: Amend repositories_data_source_test, resolve region checks
brittandeyoung Nov 16, 2023
0e7dff5
website: Amend ecr_repositories, update with correct information
brittandeyoung Nov 16, 2023
a07225a
Merge remote-tracking branch 'upstream/main' into f-aws_ecr_repositories
brittandeyoung Nov 16, 2023
0308f1e
changelog: Add 34446
brittandeyoung Nov 16, 2023
0a473bc
make copyright
brittandeyoung Nov 16, 2023
abda96b
ecr: Amend repositories_data_source_test, make testacc-lint-fix
brittandeyoung Nov 16, 2023
cef15f0
website: Amend ecr_repositories, add final new line
brittandeyoung Nov 16, 2023
16b7709
Merge branch 'main' into HEAD
ewbankkit Dec 5, 2023
07dbf79
Add 'names.ECREndpointID'.
ewbankkit Dec 5, 2023
c55235b
d/aws_ecr_repositories: Cosmetics.
ewbankkit Dec 5, 2023
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
3 changes: 3 additions & 0 deletions .changelog/34446.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_ecr_repositories
``
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/directoryservice v1.22.2
github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.6.2
github.com/aws/aws-sdk-go-v2/service/ec2 v1.138.2
github.com/aws/aws-sdk-go-v2/service/ecr v1.24.2
github.com/aws/aws-sdk-go-v2/service/eks v1.35.2
github.com/aws/aws-sdk-go-v2/service/emr v1.35.2
github.com/aws/aws-sdk-go-v2/service/emrserverless v1.14.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.2 h1:IPMh5Selz3UKr1rY8FaNTv4
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.2/go.mod h1:Mj372IvfZ9ftME7Kdo74stz3KAjMA+WC7Fzzry9uCDI=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.138.2 h1:e3Imv1oXz+W3Tfclflkh72t5TUPUwWdkHP7ctQGk8Dc=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.138.2/go.mod h1:d1hAqgLDOPaSO1Piy/0bBmj6oAplFwv6p0cquHntNHM=
github.com/aws/aws-sdk-go-v2/service/ecr v1.24.2 h1:ETo/9bTM+fp1Gf6l04jhoA8emIjZNDRu1qoNRBd419g=
github.com/aws/aws-sdk-go-v2/service/ecr v1.24.2/go.mod h1:/m9MiYl5Ds0cZqy/bbeSUWxKLwTarGugjXxSgiXNQFc=
github.com/aws/aws-sdk-go-v2/service/eks v1.35.2 h1:G1gPnbhGBEKedQLoSI71u3+IMJ+uIPxCNB0ZPmv6dpk=
github.com/aws/aws-sdk-go-v2/service/eks v1.35.2/go.mod h1:HZ5xGhvvZEs7iBPbwhLWZWvAxWezzOFn/HrepDivCgQ=
github.com/aws/aws-sdk-go-v2/service/emr v1.35.2 h1:Q4nxzsfd61L/d83LDDD/UhDk1Tktd4+8QPhRLyRUVIs=
Expand Down
5 changes: 5 additions & 0 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions internal/service/ecr/repositories_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ecr

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
fwtypes "github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/framework"
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
)

// @FrameworkDataSource(name="Repositories")
func newRepositoriesDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
return &repositoriesDataSource{}, nil
}

type repositoriesDataSource struct {
framework.DataSourceWithConfigure
}

func (d *repositoriesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
resp.TypeName = "aws_ecr_repositories"
}

func (d *repositoriesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": framework.IDAttribute(),
"names": schema.SetAttribute{
ElementType: fwtypes.StringType,
Computed: true,
},
},
}
}
func (d *repositoriesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
conn := d.Meta().ECRClient(ctx)

var data repositoriesDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

var names []string

pages := ecr.NewDescribeRepositoriesPaginator(conn, &ecr.DescribeRepositoriesInput{})
for pages.HasMorePages() {
output, err := pages.NextPage(ctx)

if err != nil {
resp.Diagnostics.AddError("reading ECR Repositories", err.Error())
return
}

for _, v := range output.Repositories {
names = append(names, aws.ToString(v.RepositoryName))
}
}

data.ID = flex.StringValueToFramework(ctx, d.Meta().Region)
data.Names = flex.FlattenFrameworkStringValueSet(ctx, names)

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

type repositoriesDataSourceModel struct {
ID fwtypes.String `tfsdk:"id"`
Names fwtypes.Set `tfsdk:"names"`
}
67 changes: 67 additions & 0 deletions internal/service/ecr/repositories_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ecr_test

import (
"encoding/json"
"fmt"
"strings"
"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"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccECRRepositoriesDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
var rNames []string
for i := 1; i < 6; i++ {
rNames = append(rNames, sdkacctest.RandomWithPrefix(acctest.ResourcePrefix))
}
dataSourceName := "data.aws_ecr_repositories.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.ECREndpointID)
},
ErrorCheck: acctest.ErrorCheck(t, strings.ToLower(ecr.ServiceID)),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccRepositoriesDataSourceConfig_basic(rNames),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "names.#", "5"),
resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[0]),
resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[1]),
resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[2]),
resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[3]),
resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[4]),
),
},
},
})
}

func testAccRepositoriesDataSourceConfig_basic(rNames []string) string {
rNameJson, _ := json.Marshal(rNames)
rNameString := string(rNameJson)
return fmt.Sprintf(`
locals {
repo_list = %[1]s
}

resource "aws_ecr_repository" "test" {
count = length(local.repo_list)
name = local.repo_list[count.index]
}

data "aws_ecr_repositories" "test" {
depends_on = [aws_ecr_repository.test]
}
`, rNameString)
}
20 changes: 19 additions & 1 deletion internal/service/ecr/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions names/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
DocDBElasticEndpointID = "docdb-elastic"
ControlTowerEndpointID = "controltower"
DSEndpointID = "ds"
ECREndpointID = "api.ecr"
EKSEndpointID = "eks"
EMREndpointID = "elasticmapreduce"
EMRServerlessEndpointID = "emrserverless"
Expand Down
2 changes: 1 addition & 1 deletion names/names_data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ebs,ebs,ebs,ebs,,ebs,,,EBS,EBS,,1,,,aws_ebs_,,changewhenimplemented,EBS (Elastic
ec2,ec2,ec2,ec2,,ec2,ec2,,EC2,EC2,,1,2,aws_(ami|availability_zone|ec2_(availability|capacity|fleet|host|instance|public_ipv4_pool|serial|spot|tag)|eip|instance|key_pair|launch_template|placement_group|spot),aws_ec2_,ec2_,ami;availability_zone;ec2_availability_;ec2_capacity_;ec2_fleet;ec2_host;ec2_image_;ec2_instance_;ec2_public_ipv4_pool;ec2_serial_;ec2_spot_;ec2_tag;eip;instance;key_pair;launch_template;placement_group;spot_,EC2 (Elastic Compute Cloud),Amazon,,,,,,,
imagebuilder,imagebuilder,imagebuilder,imagebuilder,,imagebuilder,,,ImageBuilder,Imagebuilder,,1,,,aws_imagebuilder_,,imagebuilder_,EC2 Image Builder,Amazon,,,,,,,
ec2-instance-connect,ec2instanceconnect,ec2instanceconnect,ec2instanceconnect,,ec2instanceconnect,,,EC2InstanceConnect,EC2InstanceConnect,,1,,,aws_ec2instanceconnect_,,ec2instanceconnect_,EC2 Instance Connect,AWS,,x,,,,,
ecr,ecr,ecr,ecr,,ecr,,,ECR,ECR,,1,,,aws_ecr_,,ecr_,ECR (Elastic Container Registry),Amazon,,,,,,,
ecr,ecr,ecr,ecr,,ecr,,,ECR,ECR,,1,2,,aws_ecr_,,ecr_,ECR (Elastic Container Registry),Amazon,,,,,,,
ecr-public,ecrpublic,ecrpublic,ecrpublic,,ecrpublic,,,ECRPublic,ECRPublic,,1,,,aws_ecrpublic_,,ecrpublic_,ECR Public,Amazon,,,,,,,
ecs,ecs,ecs,ecs,,ecs,,,ECS,ECS,,1,,,aws_ecs_,,ecs_,ECS (Elastic Container),Amazon,,,,,,,
efs,efs,efs,efs,,efs,,,EFS,EFS,,1,,,aws_efs_,,efs_,EFS (Elastic File System),Amazon,,,,,,,
Expand Down
30 changes: 30 additions & 0 deletions website/docs/d/ecr_repositories.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
subcategory: "ECR (Elastic Container Registry)"
layout: "aws"
page_title: "AWS: aws_ecr_repositories"
description: |-
Terraform data source for providing information on AWS ECR (Elastic Container Registry) Repositories.
---

# Data Source: aws_ecr_repositories

Terraform data source for providing information on AWS ECR (Elastic Container Registry) Repositories.

## Example Usage

### Basic Usage

```terraform
data "aws_ecr_repositories" "example" {}
```

## Argument Reference

There are no arguments available for this data source.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `id` - AWS Region.
* `names` - A list if AWS Elastic Container Registries for the region.
Loading