Skip to content

Commit

Permalink
d/aws_ecr_repositories: Cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Dec 5, 2023
1 parent 07dbf79 commit c55235b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
33 changes: 13 additions & 20 deletions internal/service/ecr/repositories_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@ import (
)

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

const (
DSNameRepositories = "Repositories Data Source"
)

type dataSourceRepositories struct {
type repositoriesDataSource struct {
framework.DataSourceWithConfigure
}

func (d *dataSourceRepositories) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
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 *dataSourceRepositories) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
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(),
Expand All @@ -43,26 +39,23 @@ func (d *dataSourceRepositories) Schema(ctx context.Context, req datasource.Sche
},
}
}
func (d *dataSourceRepositories) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *repositoriesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
conn := d.Meta().ECRClient(ctx)

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

var names []string

paginator := ecr.NewDescribeRepositoriesPaginator(conn, &ecr.DescribeRepositoriesInput{}, func(o *ecr.DescribeRepositoriesPaginatorOptions) {
o.StopOnDuplicateToken = true
})

for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
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())
resp.Diagnostics.AddError("reading ECR Repositories", err.Error())
return
}

Expand All @@ -72,12 +65,12 @@ func (d *dataSourceRepositories) Read(ctx context.Context, req datasource.ReadRe
}

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

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

type dataSourceRepositoriesData struct {
type repositoriesDataSourceModel struct {
ID fwtypes.String `tfsdk:"id"`
Names fwtypes.Set `tfsdk:"names"`
}
2 changes: 1 addition & 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.

0 comments on commit c55235b

Please sign in to comment.