From a92b24037fd04d3b2e06c0ff1beddffc8558c8f5 Mon Sep 17 00:00:00 2001 From: alexknez Date: Wed, 20 Mar 2024 21:50:54 +0000 Subject: [PATCH] migrated ecr --- internal/conns/awsclient_gen.go | 5 - internal/generate/listpages/v2/function.tmpl | 1 + .../ecr/authorization_token_data_source.go | 18 ++- internal/service/ecr/generate.go | 3 +- internal/service/ecr/image_data_source.go | 42 +++---- internal/service/ecr/lifecycle_policy.go | 49 ++++---- internal/service/ecr/lifecycle_policy_test.go | 20 ++-- internal/service/ecr/list_pages_gen.go | 43 +++++++ .../service/ecr/pull_through_cache_rule.go | 39 ++++--- .../pull_through_cache_rule_data_source.go | 6 +- .../ecr/pull_through_cache_rule_test.go | 4 +- internal/service/ecr/registry_policy.go | 27 ++--- internal/service/ecr/registry_policy_test.go | 17 +-- .../ecr/registry_scanning_configuration.go | 72 ++++++------ .../registry_scanning_configuration_test.go | 10 +- .../service/ecr/replication_configuration.go | 69 ++++++------ .../ecr/replication_configuration_test.go | 10 +- .../ecr/repositories_data_source_test.go | 15 ++- internal/service/ecr/repository.go | 106 +++++++++--------- .../service/ecr/repository_data_source.go | 23 ++-- internal/service/ecr/repository_policy.go | 47 ++++---- .../service/ecr/repository_policy_test.go | 15 +-- internal/service/ecr/repository_test.go | 41 ++++--- .../service/ecr/service_endpoints_gen_test.go | 41 ++----- internal/service/ecr/service_package_gen.go | 10 -- internal/service/ecr/sweep.go | 25 +++-- internal/service/ecr/tags_gen.go | 38 +++---- names/data/names_data.csv | 2 +- 28 files changed, 406 insertions(+), 392 deletions(-) create mode 100644 internal/service/ecr/list_pages_gen.go diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 9ee9450d11f..b1e0829fc53 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -178,7 +178,6 @@ import ( docdb_sdkv1 "github.com/aws/aws-sdk-go/service/docdb" dynamodb_sdkv1 "github.com/aws/aws-sdk-go/service/dynamodb" ec2_sdkv1 "github.com/aws/aws-sdk-go/service/ec2" - ecr_sdkv1 "github.com/aws/aws-sdk-go/service/ecr" ecs_sdkv1 "github.com/aws/aws-sdk-go/service/ecs" efs_sdkv1 "github.com/aws/aws-sdk-go/service/efs" elasticache_sdkv1 "github.com/aws/aws-sdk-go/service/elasticache" @@ -584,10 +583,6 @@ func (c *AWSClient) EC2Client(ctx context.Context) *ec2_sdkv2.Client { return errs.Must(client[*ec2_sdkv2.Client](ctx, c, names.EC2, make(map[string]any))) } -func (c *AWSClient) ECRConn(ctx context.Context) *ecr_sdkv1.ECR { - return errs.Must(conn[*ecr_sdkv1.ECR](ctx, c, names.ECR, make(map[string]any))) -} - func (c *AWSClient) ECRClient(ctx context.Context) *ecr_sdkv2.Client { return errs.Must(client[*ecr_sdkv2.Client](ctx, c, names.ECR, make(map[string]any))) } diff --git a/internal/generate/listpages/v2/function.tmpl b/internal/generate/listpages/v2/function.tmpl index 2b2add79faa..64e76190d89 100644 --- a/internal/generate/listpages/v2/function.tmpl +++ b/internal/generate/listpages/v2/function.tmpl @@ -1,3 +1,4 @@ + func {{ .Name }}Pages(ctx context.Context, conn {{ .RecvType }}, input {{ .ParamType }}, fn func({{ .ResultType }}, bool) bool) error { for { output, err := conn.{{ .AWSName }}(ctx, input) diff --git a/internal/service/ecr/authorization_token_data_source.go b/internal/service/ecr/authorization_token_data_source.go index 9b51cc32319..b0969031144 100644 --- a/internal/service/ecr/authorization_token_data_source.go +++ b/internal/service/ecr/authorization_token_data_source.go @@ -9,8 +9,8 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -56,21 +56,19 @@ func DataSourceAuthorizationToken() *schema.Resource { func dataSourceAuthorizationTokenRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) params := &ecr.GetAuthorizationTokenInput{} - if v, ok := d.GetOk("registry_id"); ok { - params.RegistryIds = []*string{aws.String(v.(string))} - } + log.Printf("[DEBUG] Getting ECR authorization token") - out, err := conn.GetAuthorizationTokenWithContext(ctx, params) + out, err := conn.GetAuthorizationToken(ctx, params) if err != nil { return sdkdiag.AppendErrorf(diags, "getting ECR authorization token: %s", err) } log.Printf("[DEBUG] Received ECR AuthorizationData %v", out.AuthorizationData) authorizationData := out.AuthorizationData[0] - authorizationToken := aws.StringValue(authorizationData.AuthorizationToken) - expiresAt := aws.TimeValue(authorizationData.ExpiresAt).Format(time.RFC3339) - proxyEndpoint := aws.StringValue(authorizationData.ProxyEndpoint) + authorizationToken := aws.ToString(authorizationData.AuthorizationToken) + expiresAt := aws.ToTime(authorizationData.ExpiresAt).Format(time.RFC3339) + proxyEndpoint := aws.ToString(authorizationData.ProxyEndpoint) authBytes, err := itypes.Base64Decode(authorizationToken) if err != nil { d.SetId("") diff --git a/internal/service/ecr/generate.go b/internal/service/ecr/generate.go index c56b40a0d16..53fdcd7ec66 100644 --- a/internal/service/ecr/generate.go +++ b/internal/service/ecr/generate.go @@ -1,7 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsSlice -UpdateTags -CreateTags +//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsSlice -UpdateTags -CreateTags -AWSSDKVersion=2 +//go:generate go run ../../generate/listpages/main.go -AWSSDKVersion=2 -ListOps=DescribeImages,DescribeRepositories //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/ecr/image_data_source.go b/internal/service/ecr/image_data_source.go index 44690f933f0..53ce2b78fae 100644 --- a/internal/service/ecr/image_data_source.go +++ b/internal/service/ecr/image_data_source.go @@ -8,14 +8,15 @@ import ( "fmt" "slices" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) @@ -76,14 +77,14 @@ func DataSourceImage() *schema.Resource { func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := &ecr.DescribeImagesInput{ RepositoryName: aws.String(d.Get("repository_name").(string)), } if v, ok := d.GetOk("image_digest"); ok { - input.ImageIds = []*ecr.ImageIdentifier{ + input.ImageIds = []awstypes.ImageIdentifier{ { ImageDigest: aws.String(v.(string)), }, @@ -92,7 +93,7 @@ func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, meta inter if v, ok := d.GetOk("image_tag"); ok { if len(input.ImageIds) == 0 { - input.ImageIds = []*ecr.ImageIdentifier{ + input.ImageIds = []awstypes.ImageIdentifier{ { ImageTag: aws.String(v.(string)), }, @@ -121,11 +122,11 @@ func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "Your query returned more than one result. Please try a more specific search criteria, or set `most_recent` attribute to true.") } - slices.SortFunc(imageDetails, func(a, b *ecr.ImageDetail) int { - if aws.TimeValue(a.ImagePushedAt).After(aws.TimeValue(b.ImagePushedAt)) { + slices.SortFunc(imageDetails, func(a, b *awstypes.ImageDetail) int { + if aws.ToTime(a.ImagePushedAt).After(aws.ToTime(b.ImagePushedAt)) { return -1 } - if aws.TimeValue(a.ImagePushedAt).Before(aws.TimeValue(b.ImagePushedAt)) { + if aws.ToTime(a.ImagePushedAt).Before(aws.ToTime(b.ImagePushedAt)) { return 1 } return 0 @@ -134,9 +135,9 @@ func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, meta inter imageDetail := imageDetails[0] - repositoryName := aws.StringValue(imageDetail.RepositoryName) + repositoryName := aws.ToString(imageDetail.RepositoryName) repositoryInput := &ecr.DescribeRepositoriesInput{ - RepositoryNames: aws.StringSlice([]string{repositoryName}), + RepositoryNames: []string{repositoryName}, RegistryId: imageDetail.RegistryId, } @@ -146,36 +147,35 @@ func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "reading ECR Images: %s", err) } - d.SetId(aws.StringValue(imageDetail.ImageDigest)) + d.SetId(aws.ToString(imageDetail.ImageDigest)) d.Set("image_digest", imageDetail.ImageDigest) d.Set("image_pushed_at", imageDetail.ImagePushedAt.Unix()) d.Set("image_size_in_bytes", imageDetail.ImageSizeInBytes) - d.Set("image_tags", aws.StringValueSlice(imageDetail.ImageTags)) - d.Set("image_uri", fmt.Sprintf("%s@%s", aws.StringValue(repository.RepositoryUri), aws.StringValue(imageDetail.ImageDigest))) + d.Set("image_tags", imageDetail.ImageTags) + d.Set("image_uri", fmt.Sprintf("%s@%s", aws.ToString(repository.RepositoryUri), aws.ToString(imageDetail.ImageDigest))) d.Set("registry_id", imageDetail.RegistryId) d.Set("repository_name", imageDetail.RepositoryName) return diags } -func FindImageDetails(ctx context.Context, conn *ecr.ECR, input *ecr.DescribeImagesInput) ([]*ecr.ImageDetail, error) { - var output []*ecr.ImageDetail +func FindImageDetails(ctx context.Context, conn *ecr.Client, input *ecr.DescribeImagesInput) ([]*awstypes.ImageDetail, error) { + var output []*awstypes.ImageDetail - err := conn.DescribeImagesPagesWithContext(ctx, input, func(page *ecr.DescribeImagesOutput, lastPage bool) bool { + err := describeImagesPages(ctx, conn, input, func(page *ecr.DescribeImagesOutput, lastPage bool) bool { if page == nil { return !lastPage } for _, v := range page.ImageDetails { - if v != nil { - output = append(output, v) - } + imageDetail := v + output = append(output, &imageDetail) } return !lastPage }) - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/ecr/lifecycle_policy.go b/internal/service/ecr/lifecycle_policy.go index 9e9c9e9c44a..f5165453da6 100644 --- a/internal/service/ecr/lifecycle_policy.go +++ b/internal/service/ecr/lifecycle_policy.go @@ -11,16 +11,17 @@ import ( "sort" "strings" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/aws/aws-sdk-go/private/protocol/json/jsonutil" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -67,7 +68,7 @@ func ResourceLifecyclePolicy() *schema.Resource { func resourceLifecyclePolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) @@ -80,18 +81,18 @@ func resourceLifecyclePolicyCreate(ctx context.Context, d *schema.ResourceData, LifecyclePolicyText: aws.String(policy), } - resp, err := conn.PutLifecyclePolicyWithContext(ctx, input) + resp, err := conn.PutLifecyclePolicy(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Lifecycle Policy (%s): %s", d.Get("repository").(string), err) } - d.SetId(aws.StringValue(resp.RepositoryName)) + d.SetId(aws.ToString(resp.RepositoryName)) d.Set("registry_id", resp.RegistryId) return append(diags, resourceLifecyclePolicyRead(ctx, d, meta)...) } func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := &ecr.GetLifecyclePolicyInput{ RepositoryName: aws.String(d.Id()), @@ -102,13 +103,9 @@ func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, me err := retry.RetryContext(ctx, propagationTimeout, func() *retry.RetryError { var err error - resp, err = conn.GetLifecyclePolicyWithContext(ctx, input) + resp, err = conn.GetLifecyclePolicy(ctx, input) - if d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeLifecyclePolicyNotFoundException) { - return retry.RetryableError(err) - } - - if d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if d.IsNewResource() && (errs.IsA[*awstypes.LifecyclePolicyNotFoundException](err) || errs.IsA[*awstypes.RepositoryNotFoundException](err)) { return retry.RetryableError(err) } @@ -120,16 +117,16 @@ func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, me }) if tfresource.TimedOut(err) { - resp, err = conn.GetLifecyclePolicyWithContext(ctx, input) + resp, err = conn.GetLifecyclePolicy(ctx, input) } - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeLifecyclePolicyNotFoundException) { + if d.IsNewResource() && errs.IsA[*awstypes.LifecyclePolicyNotFoundException](err) { log.Printf("[WARN] ECR Lifecycle Policy (%s) not found, removing from state", d.Id()) d.SetId("") return diags } - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if d.IsNewResource() && errs.IsA[*awstypes.RepositoryNotFoundException](err) { log.Printf("[WARN] ECR Lifecycle Policy (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -146,14 +143,14 @@ func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, me d.Set("repository", resp.RepositoryName) d.Set("registry_id", resp.RegistryId) - equivalent, err := equivalentLifecyclePolicyJSON(d.Get("policy").(string), aws.StringValue(resp.LifecyclePolicyText)) + equivalent, err := equivalentLifecyclePolicyJSON(d.Get("policy").(string), aws.ToString(resp.LifecyclePolicyText)) if err != nil { - return sdkdiag.AppendErrorf(diags, "while comparing policy (state: %s) (from AWS: %s), encountered: %s", d.Get("policy").(string), aws.StringValue(resp.LifecyclePolicyText), err) + return sdkdiag.AppendErrorf(diags, "while comparing policy (state: %s) (from AWS: %s), encountered: %s", d.Get("policy").(string), aws.ToString(resp.LifecyclePolicyText), err) } if !equivalent { - policyToSet, err := structure.NormalizeJsonString(aws.StringValue(resp.LifecyclePolicyText)) + policyToSet, err := structure.NormalizeJsonString(aws.ToString(resp.LifecyclePolicyText)) if err != nil { return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", policyToSet, err) @@ -167,20 +164,18 @@ func resourceLifecyclePolicyRead(ctx context.Context, d *schema.ResourceData, me func resourceLifecyclePolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := &ecr.DeleteLifecyclePolicyInput{ RepositoryName: aws.String(d.Id()), } - _, err := conn.DeleteLifecyclePolicyWithContext(ctx, input) + _, err := conn.DeleteLifecyclePolicy(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { - return diags - } - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeLifecyclePolicyNotFoundException) { + if d.IsNewResource() && (errs.IsA[*awstypes.LifecyclePolicyNotFoundException](err) || errs.IsA[*awstypes.RepositoryNotFoundException](err)) { return diags } + return sdkdiag.AppendErrorf(diags, "deleting ECR Lifecycle Policy (%s): %s", d.Id(), err) } @@ -212,7 +207,7 @@ type lifecyclePolicy struct { func (lp *lifecyclePolicy) reduce() { sort.Slice(lp.Rules, func(i, j int) bool { - return aws.Int64Value(lp.Rules[i].RulePriority) < aws.Int64Value(lp.Rules[j].RulePriority) + return aws.ToInt64(lp.Rules[i].RulePriority) < aws.ToInt64(lp.Rules[j].RulePriority) }) for _, rule := range lp.Rules { @@ -222,7 +217,7 @@ func (lp *lifecyclePolicy) reduce() { func (lprs *lifecyclePolicyRuleSelection) reduce() { sort.Slice(lprs.TagPrefixList, func(i, j int) bool { - return aws.StringValue(lprs.TagPrefixList[i]) < aws.StringValue(lprs.TagPrefixList[j]) + return aws.ToString(lprs.TagPrefixList[i]) < aws.ToString(lprs.TagPrefixList[j]) }) if len(lprs.TagPrefixList) == 0 { diff --git a/internal/service/ecr/lifecycle_policy_test.go b/internal/service/ecr/lifecycle_policy_test.go index 75795404d09..9ee406d1298 100644 --- a/internal/service/ecr/lifecycle_policy_test.go +++ b/internal/service/ecr/lifecycle_policy_test.go @@ -8,14 +8,15 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -99,7 +100,7 @@ func TestAccECRLifecyclePolicy_detectDiff(t *testing.T) { func testAccCheckLifecyclePolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_lifecycle_policy" { @@ -110,12 +111,9 @@ func testAccCheckLifecyclePolicyDestroy(ctx context.Context) resource.TestCheckF RepositoryName: aws.String(rs.Primary.ID), } - _, err := conn.GetLifecyclePolicyWithContext(ctx, input) + _, err := conn.GetLifecyclePolicy(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { - return nil - } - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeLifecyclePolicyNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) || errs.IsA[*awstypes.LifecyclePolicyNotFoundException](err) { return nil } return err @@ -133,13 +131,13 @@ func testAccCheckLifecyclePolicyExists(ctx context.Context, name string) resourc return fmt.Errorf("Not found: %s", name) } - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) input := &ecr.GetLifecyclePolicyInput{ RepositoryName: aws.String(rs.Primary.ID), } - _, err := conn.GetLifecyclePolicyWithContext(ctx, input) + _, err := conn.GetLifecyclePolicy(ctx, input) return err } } diff --git a/internal/service/ecr/list_pages_gen.go b/internal/service/ecr/list_pages_gen.go new file mode 100644 index 00000000000..2ba28830f3c --- /dev/null +++ b/internal/service/ecr/list_pages_gen.go @@ -0,0 +1,43 @@ +// Code generated by "internal/generate/listpages/main.go -AWSSDKVersion=2 -ListOps=DescribeImages,DescribeRepositories"; DO NOT EDIT. + +package ecr + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" +) + +func describeImagesPages(ctx context.Context, conn *ecr.Client, input *ecr.DescribeImagesInput, fn func(*ecr.DescribeImagesOutput, bool) bool) error { + for { + output, err := conn.DescribeImages(ctx, input) + if err != nil { + return err + } + + lastPage := aws.ToString(output.NextToken) == "" + if !fn(output, lastPage) || lastPage { + break + } + + input.NextToken = output.NextToken + } + return nil +} +func describeRepositoriesPages(ctx context.Context, conn *ecr.Client, input *ecr.DescribeRepositoriesInput, fn func(*ecr.DescribeRepositoriesOutput, bool) bool) error { + for { + output, err := conn.DescribeRepositories(ctx, input) + if err != nil { + return err + } + + lastPage := aws.ToString(output.NextToken) == "" + if !fn(output, lastPage) || lastPage { + break + } + + input.NextToken = output.NextToken + } + return nil +} diff --git a/internal/service/ecr/pull_through_cache_rule.go b/internal/service/ecr/pull_through_cache_rule.go index 92072567750..4fc1042ab93 100644 --- a/internal/service/ecr/pull_through_cache_rule.go +++ b/internal/service/ecr/pull_through_cache_rule.go @@ -8,14 +8,15 @@ import ( "log" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -65,7 +66,7 @@ func resourcePullThroughCacheRule() *schema.Resource { func resourcePullThroughCacheRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { // nosemgrep:ci.ecr-in-func-name var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) repositoryPrefix := d.Get("ecr_repository_prefix").(string) input := &ecr.CreatePullThroughCacheRuleInput{ @@ -77,7 +78,7 @@ func resourcePullThroughCacheRuleCreate(ctx context.Context, d *schema.ResourceD input.CredentialArn = aws.String(v.(string)) } - _, err := conn.CreatePullThroughCacheRuleWithContext(ctx, input) + _, err := conn.CreatePullThroughCacheRule(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Pull Through Cache Rule (%s): %s", repositoryPrefix, err) @@ -90,7 +91,7 @@ func resourcePullThroughCacheRuleCreate(ctx context.Context, d *schema.ResourceD func resourcePullThroughCacheRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) rule, err := findPullThroughCacheRuleByRepositoryPrefix(ctx, conn, d.Id()) @@ -114,7 +115,7 @@ func resourcePullThroughCacheRuleRead(ctx context.Context, d *schema.ResourceDat func resourcePullThroughCacheRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) repositoryPrefix := d.Get("ecr_repository_prefix").(string) input := &ecr.UpdatePullThroughCacheRuleInput{ @@ -122,7 +123,7 @@ func resourcePullThroughCacheRuleUpdate(ctx context.Context, d *schema.ResourceD EcrRepositoryPrefix: aws.String(repositoryPrefix), } - _, err := conn.UpdatePullThroughCacheRuleWithContext(ctx, input) + _, err := conn.UpdatePullThroughCacheRule(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating ECR Pull Through Cache Rule (%s): %s", repositoryPrefix, err) @@ -135,15 +136,15 @@ func resourcePullThroughCacheRuleUpdate(ctx context.Context, d *schema.ResourceD func resourcePullThroughCacheRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) log.Printf("[DEBUG] Deleting ECR Pull Through Cache Rule: %s", d.Id()) - _, err := conn.DeletePullThroughCacheRuleWithContext(ctx, &ecr.DeletePullThroughCacheRuleInput{ + _, err := conn.DeletePullThroughCacheRule(ctx, &ecr.DeletePullThroughCacheRuleInput{ EcrRepositoryPrefix: aws.String(d.Id()), RegistryId: aws.String(d.Get("registry_id").(string)), }) - if tfawserr.ErrCodeEquals(err, ecr.ErrCodePullThroughCacheRuleNotFoundException) { + if errs.IsA[*awstypes.PullThroughCacheRuleNotFoundException](err) { return diags } @@ -154,14 +155,14 @@ func resourcePullThroughCacheRuleDelete(ctx context.Context, d *schema.ResourceD return diags } -func findPullThroughCacheRuleByRepositoryPrefix(ctx context.Context, conn *ecr.ECR, repositoryPrefix string) (*ecr.PullThroughCacheRule, error) { +func findPullThroughCacheRuleByRepositoryPrefix(ctx context.Context, conn *ecr.Client, repositoryPrefix string) (*awstypes.PullThroughCacheRule, error) { input := &ecr.DescribePullThroughCacheRulesInput{ - EcrRepositoryPrefixes: aws.StringSlice([]string{repositoryPrefix}), + EcrRepositoryPrefixes: aws.ToStringSlice([]*string{&repositoryPrefix}), } - output, err := conn.DescribePullThroughCacheRulesWithContext(ctx, input) + output, err := conn.DescribePullThroughCacheRules(ctx, input) - if tfawserr.ErrCodeEquals(err, ecr.ErrCodePullThroughCacheRuleNotFoundException) { + if errs.IsA[*awstypes.PullThroughCacheRuleNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -176,5 +177,11 @@ func findPullThroughCacheRuleByRepositoryPrefix(ctx context.Context, conn *ecr.E return nil, tfresource.NewEmptyResultError(input) } - return tfresource.AssertSinglePtrResult(output.PullThroughCacheRules) + ptrSlice := make([]*awstypes.PullThroughCacheRule, len(output.PullThroughCacheRules)) + for i, rule := range output.PullThroughCacheRules { + ptrRule := rule + ptrSlice[i] = &ptrRule + } + + return tfresource.AssertSinglePtrResult(ptrSlice) } diff --git a/internal/service/ecr/pull_through_cache_rule_data_source.go b/internal/service/ecr/pull_through_cache_rule_data_source.go index 4a358205cb0..d8ab9357e4c 100644 --- a/internal/service/ecr/pull_through_cache_rule_data_source.go +++ b/internal/service/ecr/pull_through_cache_rule_data_source.go @@ -7,7 +7,7 @@ import ( "context" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -50,7 +50,7 @@ func dataSourcePullThroughCacheRule() *schema.Resource { func dataSourcePullThroughCacheRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) repositoryPrefix := d.Get("ecr_repository_prefix").(string) rule, err := findPullThroughCacheRuleByRepositoryPrefix(ctx, conn, repositoryPrefix) @@ -59,7 +59,7 @@ func dataSourcePullThroughCacheRuleRead(ctx context.Context, d *schema.ResourceD return sdkdiag.AppendErrorf(diags, "reading ECR Pull Through Cache Rule (%s): %s", repositoryPrefix, err) } - d.SetId(aws.StringValue(rule.EcrRepositoryPrefix)) + d.SetId(aws.ToString(rule.EcrRepositoryPrefix)) d.Set("credential_arn", rule.CredentialArn) d.Set("ecr_repository_prefix", rule.EcrRepositoryPrefix) d.Set("registry_id", rule.RegistryId) diff --git a/internal/service/ecr/pull_through_cache_rule_test.go b/internal/service/ecr/pull_through_cache_rule_test.go index 6a4d1aa8b97..4ed53ccf239 100644 --- a/internal/service/ecr/pull_through_cache_rule_test.go +++ b/internal/service/ecr/pull_through_cache_rule_test.go @@ -154,7 +154,7 @@ func TestAccECRPullThroughCacheRule_repositoryPrefixWithSlash(t *testing.T) { func testAccCheckPullThroughCacheRuleDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_pull_through_cache_rule" { @@ -185,7 +185,7 @@ func testAccCheckPullThroughCacheRuleExists(ctx context.Context, n string) resou return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) _, err := tfecr.FindPullThroughCacheRuleByRepositoryPrefix(ctx, conn, rs.Primary.ID) diff --git a/internal/service/ecr/registry_policy.go b/internal/service/ecr/registry_policy.go index 53c030854ff..564326c3bf9 100644 --- a/internal/service/ecr/registry_policy.go +++ b/internal/service/ecr/registry_policy.go @@ -7,14 +7,15 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -52,7 +53,7 @@ func ResourceRegistryPolicy() *schema.Resource { func resourceRegistryPolicyPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) @@ -64,12 +65,12 @@ func resourceRegistryPolicyPut(ctx context.Context, d *schema.ResourceData, meta PolicyText: aws.String(policy), } - out, err := conn.PutRegistryPolicyWithContext(ctx, &input) + out, err := conn.PutRegistryPolicy(ctx, &input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Registry Policy: %s", err) } - regID := aws.StringValue(out.RegistryId) + regID := aws.ToString(out.RegistryId) d.SetId(regID) @@ -78,12 +79,12 @@ func resourceRegistryPolicyPut(ctx context.Context, d *schema.ResourceData, meta func resourceRegistryPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) log.Printf("[DEBUG] Reading registry policy %s", d.Id()) - out, err := conn.GetRegistryPolicyWithContext(ctx, &ecr.GetRegistryPolicyInput{}) + out, err := conn.GetRegistryPolicy(ctx, &ecr.GetRegistryPolicyInput{}) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRegistryPolicyNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.RegistryPolicyNotFoundException](err) { log.Printf("[WARN] ECR Registry (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -93,7 +94,7 @@ func resourceRegistryPolicyRead(ctx context.Context, d *schema.ResourceData, met d.Set("registry_id", out.RegistryId) - policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.StringValue(out.PolicyText)) + policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.ToString(out.PolicyText)) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ECR Registry Policy (%s): setting policy: %s", d.Id(), err) @@ -112,11 +113,11 @@ func resourceRegistryPolicyRead(ctx context.Context, d *schema.ResourceData, met func resourceRegistryPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) - _, err := conn.DeleteRegistryPolicyWithContext(ctx, &ecr.DeleteRegistryPolicyInput{}) + _, err := conn.DeleteRegistryPolicy(ctx, &ecr.DeleteRegistryPolicyInput{}) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRegistryPolicyNotFoundException) { + if errs.IsA[*awstypes.RegistryPolicyNotFoundException](err) { return diags } return sdkdiag.AppendErrorf(diags, "deleting ECR Registry Policy (%s): %s", d.Id(), err) diff --git a/internal/service/ecr/registry_policy_test.go b/internal/service/ecr/registry_policy_test.go index 27d2be8b5ce..358933192f4 100644 --- a/internal/service/ecr/registry_policy_test.go +++ b/internal/service/ecr/registry_policy_test.go @@ -9,12 +9,13 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" tfecr "github.com/hashicorp/terraform-provider-aws/internal/service/ecr" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -92,16 +93,16 @@ func testAccRegistryPolicy_disappears(t *testing.T) { func testAccCheckRegistryPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_registry_policy" { continue } - _, err := conn.GetRegistryPolicyWithContext(ctx, &ecr.GetRegistryPolicyInput{}) + _, err := conn.GetRegistryPolicy(ctx, &ecr.GetRegistryPolicyInput{}) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRegistryPolicyNotFoundException) { + if errs.IsA[*awstypes.RegistryPolicyNotFoundException](err) { return nil } return err @@ -123,11 +124,11 @@ func testAccCheckRegistryPolicyExists(ctx context.Context, name string, res *ecr return fmt.Errorf("No ECR registry policy ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) - output, err := conn.GetRegistryPolicyWithContext(ctx, &ecr.GetRegistryPolicyInput{}) + output, err := conn.GetRegistryPolicy(ctx, &ecr.GetRegistryPolicyInput{}) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRegistryPolicyNotFoundException) { + if errs.IsA[*awstypes.RegistryPolicyNotFoundException](err) { return fmt.Errorf("ECR repository %s not found", rs.Primary.ID) } return err diff --git a/internal/service/ecr/registry_scanning_configuration.go b/internal/service/ecr/registry_scanning_configuration.go index 54a36925d27..848f31c48f1 100644 --- a/internal/service/ecr/registry_scanning_configuration.go +++ b/internal/service/ecr/registry_scanning_configuration.go @@ -8,12 +8,14 @@ import ( "log" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) @@ -55,25 +57,25 @@ func ResourceRegistryScanningConfiguration() *schema.Resource { ), }, "filter_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(ecr.ScanningRepositoryFilterType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.ScanningRepositoryFilterType](), }, }, }, }, "scan_frequency": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(ecr.ScanFrequency_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.ScanFrequency](), }, }, }, }, "scan_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(ecr.ScanType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.ScanType](), }, }, } @@ -81,14 +83,14 @@ func ResourceRegistryScanningConfiguration() *schema.Resource { func resourceRegistryScanningConfigurationPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := ecr.PutRegistryScanningConfigurationInput{ - ScanType: aws.String(d.Get("scan_type").(string)), + ScanType: awstypes.ScanType(d.Get("scan_type").(string)), Rules: expandScanningRegistryRules(d.Get("rule").(*schema.Set).List()), } - _, err := conn.PutRegistryScanningConfigurationWithContext(ctx, &input) + _, err := conn.PutRegistryScanningConfiguration(ctx, &input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Registry Scanning Configuration: %s", err) @@ -101,9 +103,9 @@ func resourceRegistryScanningConfigurationPut(ctx context.Context, d *schema.Res func resourceRegistryScanningConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) - out, err := conn.GetRegistryScanningConfigurationWithContext(ctx, &ecr.GetRegistryScanningConfigurationInput{}) + out, err := conn.GetRegistryScanningConfiguration(ctx, &ecr.GetRegistryScanningConfigurationInput{}) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ECR Registry Scanning Configuration (%s): %s", d.Id(), err) @@ -118,12 +120,12 @@ func resourceRegistryScanningConfigurationRead(ctx context.Context, d *schema.Re func resourceRegistryScanningConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) log.Printf("[DEBUG] Deleting ECR Registry Scanning Configuration: (%s)", d.Id()) - _, err := conn.PutRegistryScanningConfigurationWithContext(ctx, &ecr.PutRegistryScanningConfigurationInput{ - Rules: []*ecr.RegistryScanningRule{}, - ScanType: aws.String(ecr.ScanTypeBasic), + _, err := conn.PutRegistryScanningConfiguration(ctx, &ecr.PutRegistryScanningConfigurationInput{ + Rules: []awstypes.RegistryScanningRule{}, + ScanType: awstypes.ScanTypeBasic, }) if err != nil { @@ -135,8 +137,8 @@ func resourceRegistryScanningConfigurationDelete(ctx context.Context, d *schema. // Helper functions -func expandScanningRegistryRules(l []interface{}) []*ecr.RegistryScanningRule { - rules := make([]*ecr.RegistryScanningRule, 0) +func expandScanningRegistryRules(l []interface{}) []awstypes.RegistryScanningRule { + rules := make([]awstypes.RegistryScanningRule, 0) for _, rule := range l { if rule == nil { @@ -148,52 +150,52 @@ func expandScanningRegistryRules(l []interface{}) []*ecr.RegistryScanningRule { return rules } -func expandScanningRegistryRule(m map[string]interface{}) *ecr.RegistryScanningRule { +func expandScanningRegistryRule(m map[string]interface{}) awstypes.RegistryScanningRule { if m == nil { - return nil + return awstypes.RegistryScanningRule{} } - rule := &ecr.RegistryScanningRule{ + rule := awstypes.RegistryScanningRule{ RepositoryFilters: expandScanningRegistryRuleRepositoryFilters(m["repository_filter"].(*schema.Set).List()), - ScanFrequency: aws.String(m["scan_frequency"].(string)), + ScanFrequency: awstypes.ScanFrequency((m["scan_frequency"].(string))), } return rule } -func expandScanningRegistryRuleRepositoryFilters(l []interface{}) []*ecr.ScanningRepositoryFilter { +func expandScanningRegistryRuleRepositoryFilters(l []interface{}) []awstypes.ScanningRepositoryFilter { if len(l) == 0 || l[0] == nil { return nil } - filters := make([]*ecr.ScanningRepositoryFilter, 0) + filters := make([]awstypes.ScanningRepositoryFilter, 0) for _, f := range l { if f == nil { continue } m := f.(map[string]interface{}) - filters = append(filters, &ecr.ScanningRepositoryFilter{ + filters = append(filters, awstypes.ScanningRepositoryFilter{ Filter: aws.String(m["filter"].(string)), - FilterType: aws.String(m["filter_type"].(string)), + FilterType: awstypes.ScanningRepositoryFilterType((m["filter_type"].(string))), }) } return filters } -func flattenScanningConfigurationRules(r []*ecr.RegistryScanningRule) interface{} { +func flattenScanningConfigurationRules(r []awstypes.RegistryScanningRule) interface{} { out := make([]map[string]interface{}, len(r)) for i, rule := range r { m := make(map[string]interface{}) - m["scan_frequency"] = aws.StringValue(rule.ScanFrequency) + m["scan_frequency"] = rule.ScanFrequency m["repository_filter"] = flattenScanningConfigurationFilters(rule.RepositoryFilters) out[i] = m } return out } -func flattenScanningConfigurationFilters(l []*ecr.ScanningRepositoryFilter) []interface{} { +func flattenScanningConfigurationFilters(l []awstypes.ScanningRepositoryFilter) []interface{} { if len(l) == 0 { return nil } @@ -201,8 +203,8 @@ func flattenScanningConfigurationFilters(l []*ecr.ScanningRepositoryFilter) []in out := make([]interface{}, len(l)) for i, filter := range l { out[i] = map[string]interface{}{ - "filter": aws.StringValue(filter.Filter), - "filter_type": aws.StringValue(filter.FilterType), + "filter": aws.ToString(filter.Filter), + "filter_type": filter.FilterType, } } diff --git a/internal/service/ecr/registry_scanning_configuration_test.go b/internal/service/ecr/registry_scanning_configuration_test.go index ab10e3181c7..99a477497df 100644 --- a/internal/service/ecr/registry_scanning_configuration_test.go +++ b/internal/service/ecr/registry_scanning_configuration_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/service/ecr" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -135,14 +135,14 @@ func testAccRegistryScanningConfiguration_update(t *testing.T) { func testAccCheckRegistryScanningConfigurationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_registry_scanning_configuration" { continue } - _, err := conn.GetRegistryScanningConfigurationWithContext(ctx, &ecr.GetRegistryScanningConfigurationInput{}) + _, err := conn.GetRegistryScanningConfiguration(ctx, &ecr.GetRegistryScanningConfigurationInput{}) if err != nil { return err @@ -164,9 +164,9 @@ func testAccRegistryScanningConfigurationExists(ctx context.Context, name string return fmt.Errorf("No ECR Registry Scanning Configuration ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) - output, err := conn.GetRegistryScanningConfigurationWithContext(ctx, &ecr.GetRegistryScanningConfigurationInput{}) + output, err := conn.GetRegistryScanningConfiguration(ctx, &ecr.GetRegistryScanningConfigurationInput{}) if err != nil { return err diff --git a/internal/service/ecr/replication_configuration.go b/internal/service/ecr/replication_configuration.go index c537ce532b6..404df0e6d32 100644 --- a/internal/service/ecr/replication_configuration.go +++ b/internal/service/ecr/replication_configuration.go @@ -7,12 +7,13 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -76,9 +77,9 @@ func ResourceReplicationConfiguration() *schema.Resource { Required: true, }, "filter_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(ecr.RepositoryFilterType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.RepositoryFilterType](), }, }, }, @@ -95,13 +96,13 @@ func ResourceReplicationConfiguration() *schema.Resource { func resourceReplicationConfigurationPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := ecr.PutReplicationConfigurationInput{ ReplicationConfiguration: expandReplicationConfigurationReplicationConfiguration(d.Get("replication_configuration").([]interface{})), } - _, err := conn.PutReplicationConfigurationWithContext(ctx, &input) + _, err := conn.PutReplicationConfiguration(ctx, &input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Replication Configuration: %s", err) } @@ -113,10 +114,10 @@ func resourceReplicationConfigurationPut(ctx context.Context, d *schema.Resource func resourceReplicationConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) log.Printf("[DEBUG] Reading ECR Replication Configuration %s", d.Id()) - out, err := conn.DescribeRegistryWithContext(ctx, &ecr.DescribeRegistryInput{}) + out, err := conn.DescribeRegistry(ctx, &ecr.DescribeRegistryInput{}) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ECR Replication Configuration: %s", err) } @@ -132,15 +133,15 @@ func resourceReplicationConfigurationRead(ctx context.Context, d *schema.Resourc func resourceReplicationConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := ecr.PutReplicationConfigurationInput{ - ReplicationConfiguration: &ecr.ReplicationConfiguration{ - Rules: []*ecr.ReplicationRule{}, + ReplicationConfiguration: &awstypes.ReplicationConfiguration{ + Rules: []awstypes.ReplicationRule{}, }, } - _, err := conn.PutReplicationConfigurationWithContext(ctx, &input) + _, err := conn.PutReplicationConfiguration(ctx, &input) if err != nil { return sdkdiag.AppendErrorf(diags, "deleting ECR Replication Configuration: %s", err) } @@ -148,19 +149,19 @@ func resourceReplicationConfigurationDelete(ctx context.Context, d *schema.Resou return diags } -func expandReplicationConfigurationReplicationConfiguration(data []interface{}) *ecr.ReplicationConfiguration { +func expandReplicationConfigurationReplicationConfiguration(data []interface{}) *awstypes.ReplicationConfiguration { if len(data) == 0 || data[0] == nil { return nil } ec := data[0].(map[string]interface{}) - config := &ecr.ReplicationConfiguration{ + config := &awstypes.ReplicationConfiguration{ Rules: expandReplicationConfigurationReplicationConfigurationRules(ec["rule"].([]interface{})), } return config } -func flattenReplicationConfigurationReplicationConfiguration(ec *ecr.ReplicationConfiguration) []map[string]interface{} { +func flattenReplicationConfigurationReplicationConfiguration(ec *awstypes.ReplicationConfiguration) []map[string]interface{} { if ec == nil { return nil } @@ -174,16 +175,16 @@ func flattenReplicationConfigurationReplicationConfiguration(ec *ecr.Replication } } -func expandReplicationConfigurationReplicationConfigurationRules(data []interface{}) []*ecr.ReplicationRule { +func expandReplicationConfigurationReplicationConfigurationRules(data []interface{}) []awstypes.ReplicationRule { if len(data) == 0 || data[0] == nil { return nil } - var rules []*ecr.ReplicationRule + var rules []awstypes.ReplicationRule for _, rule := range data { ec := rule.(map[string]interface{}) - config := &ecr.ReplicationRule{ + config := awstypes.ReplicationRule{ Destinations: expandReplicationConfigurationReplicationConfigurationRulesDestinations(ec["destination"].([]interface{})), RepositoryFilters: expandReplicationConfigurationReplicationConfigurationRulesRepositoryFilters(ec["repository_filter"].([]interface{})), } @@ -193,7 +194,7 @@ func expandReplicationConfigurationReplicationConfigurationRules(data []interfac return rules } -func flattenReplicationConfigurationReplicationConfigurationRules(ec []*ecr.ReplicationRule) []interface{} { +func flattenReplicationConfigurationReplicationConfigurationRules(ec []awstypes.ReplicationRule) []interface{} { if len(ec) == 0 { return nil } @@ -212,16 +213,16 @@ func flattenReplicationConfigurationReplicationConfigurationRules(ec []*ecr.Repl return tfList } -func expandReplicationConfigurationReplicationConfigurationRulesDestinations(data []interface{}) []*ecr.ReplicationDestination { +func expandReplicationConfigurationReplicationConfigurationRulesDestinations(data []interface{}) []awstypes.ReplicationDestination { if len(data) == 0 || data[0] == nil { return nil } - var dests []*ecr.ReplicationDestination + var dests []awstypes.ReplicationDestination for _, dest := range data { ec := dest.(map[string]interface{}) - config := &ecr.ReplicationDestination{ + config := awstypes.ReplicationDestination{ Region: aws.String(ec["region"].(string)), RegistryId: aws.String(ec["registry_id"].(string)), } @@ -231,7 +232,7 @@ func expandReplicationConfigurationReplicationConfigurationRulesDestinations(dat return dests } -func flattenReplicationConfigurationReplicationConfigurationRulesDestinations(ec []*ecr.ReplicationDestination) []interface{} { +func flattenReplicationConfigurationReplicationConfigurationRulesDestinations(ec []awstypes.ReplicationDestination) []interface{} { if len(ec) == 0 { return nil } @@ -240,8 +241,8 @@ func flattenReplicationConfigurationReplicationConfigurationRulesDestinations(ec for _, apiObject := range ec { tfMap := map[string]interface{}{ - "region": aws.StringValue(apiObject.Region), - "registry_id": aws.StringValue(apiObject.RegistryId), + "region": aws.ToString(apiObject.Region), + "registry_id": aws.ToString(apiObject.RegistryId), } tfList = append(tfList, tfMap) @@ -250,18 +251,18 @@ func flattenReplicationConfigurationReplicationConfigurationRulesDestinations(ec return tfList } -func expandReplicationConfigurationReplicationConfigurationRulesRepositoryFilters(data []interface{}) []*ecr.RepositoryFilter { +func expandReplicationConfigurationReplicationConfigurationRulesRepositoryFilters(data []interface{}) []awstypes.RepositoryFilter { if len(data) == 0 || data[0] == nil { return nil } - var filters []*ecr.RepositoryFilter + var filters []awstypes.RepositoryFilter for _, filter := range data { ec := filter.(map[string]interface{}) - config := &ecr.RepositoryFilter{ + config := awstypes.RepositoryFilter{ Filter: aws.String(ec["filter"].(string)), - FilterType: aws.String(ec["filter_type"].(string)), + FilterType: awstypes.RepositoryFilterType((ec["filter_type"].(string))), } filters = append(filters, config) @@ -269,7 +270,7 @@ func expandReplicationConfigurationReplicationConfigurationRulesRepositoryFilter return filters } -func flattenReplicationConfigurationReplicationConfigurationRulesRepositoryFilters(ec []*ecr.RepositoryFilter) []interface{} { +func flattenReplicationConfigurationReplicationConfigurationRulesRepositoryFilters(ec []awstypes.RepositoryFilter) []interface{} { if len(ec) == 0 { return nil } @@ -278,8 +279,8 @@ func flattenReplicationConfigurationReplicationConfigurationRulesRepositoryFilte for _, apiObject := range ec { tfMap := map[string]interface{}{ - "filter": aws.StringValue(apiObject.Filter), - "filter_type": aws.StringValue(apiObject.FilterType), + "filter": aws.ToString(apiObject.Filter), + "filter_type": apiObject.FilterType, } tfList = append(tfList, tfMap) diff --git a/internal/service/ecr/replication_configuration_test.go b/internal/service/ecr/replication_configuration_test.go index 2193f067997..b1bd63f1dcd 100644 --- a/internal/service/ecr/replication_configuration_test.go +++ b/internal/service/ecr/replication_configuration_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/service/ecr" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -153,8 +153,8 @@ func testAccCheckReplicationConfigurationExists(ctx context.Context, name string return fmt.Errorf("Not found: %s", name) } - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) - out, err := conn.DescribeRegistryWithContext(ctx, &ecr.DescribeRegistryInput{}) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) + out, err := conn.DescribeRegistry(ctx, &ecr.DescribeRegistryInput{}) if err != nil { return fmt.Errorf("ECR replication rules not found: %w", err) } @@ -169,14 +169,14 @@ func testAccCheckReplicationConfigurationExists(ctx context.Context, name string func testAccCheckReplicationConfigurationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_replication_configuration" { continue } - out, err := conn.DescribeRegistryWithContext(ctx, &ecr.DescribeRegistryInput{}) + out, err := conn.DescribeRegistry(ctx, &ecr.DescribeRegistryInput{}) if err != nil { return err } diff --git a/internal/service/ecr/repositories_data_source_test.go b/internal/service/ecr/repositories_data_source_test.go index 963e0a28e46..7034ca2fd29 100644 --- a/internal/service/ecr/repositories_data_source_test.go +++ b/internal/service/ecr/repositories_data_source_test.go @@ -6,10 +6,11 @@ package ecr_test import ( "encoding/json" "fmt" + "strconv" "strings" "testing" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/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" @@ -35,7 +36,17 @@ func TestAccECRRepositoriesDataSource_basic(t *testing.T) { { Config: testAccRepositoriesDataSourceConfig_basic(rNames), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "names.#", "5"), + resource.TestCheckResourceAttrWith(dataSourceName, "names.#", func(value string) error { + valueInt, err := strconv.Atoi(value) + if err != nil { + return err + } + + if valueInt < 5 { + return fmt.Errorf("Number of repositories should be >= 5") + } + return nil + }), resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[0]), resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[1]), resource.TestCheckTypeSetElemAttr(dataSourceName, "names.*", rNames[2]), diff --git a/internal/service/ecr/repository.go b/internal/service/ecr/repository.go index 159f33ea851..90c9aca750a 100644 --- a/internal/service/ecr/repository.go +++ b/internal/service/ecr/repository.go @@ -8,14 +8,14 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -54,11 +54,11 @@ func ResourceRepository() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "encryption_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: ecr.EncryptionTypeAes256, - ValidateFunc: validation.StringInSlice(ecr.EncryptionType_Values(), false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: awstypes.EncryptionTypeAes256, + ValidateDiagFunc: enum.Validate[awstypes.EncryptionType](), }, "kms_key": { Type: schema.TypeString, @@ -90,10 +90,10 @@ func ResourceRepository() *schema.Resource { DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock, }, "image_tag_mutability": { - Type: schema.TypeString, - Optional: true, - Default: ecr.ImageTagMutabilityMutable, - ValidateFunc: validation.StringInSlice(ecr.ImageTagMutability_Values(), false), + Type: schema.TypeString, + Optional: true, + Default: awstypes.ImageTagMutabilityMutable, + ValidateDiagFunc: enum.Validate[awstypes.ImageTagMutability](), }, "name": { Type: schema.TypeString, @@ -116,44 +116,44 @@ func ResourceRepository() *schema.Resource { func resourceRepositoryCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) name := d.Get("name").(string) input := &ecr.CreateRepositoryInput{ EncryptionConfiguration: expandRepositoryEncryptionConfiguration(d.Get("encryption_configuration").([]interface{})), - ImageTagMutability: aws.String(d.Get("image_tag_mutability").(string)), + ImageTagMutability: awstypes.ImageTagMutability((d.Get("image_tag_mutability").(string))), RepositoryName: aws.String(name), Tags: getTagsIn(ctx), } if v, ok := d.GetOk("image_scanning_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { tfMap := v.([]interface{})[0].(map[string]interface{}) - input.ImageScanningConfiguration = &ecr.ImageScanningConfiguration{ - ScanOnPush: aws.Bool(tfMap["scan_on_push"].(bool)), + input.ImageScanningConfiguration = &awstypes.ImageScanningConfiguration{ + ScanOnPush: tfMap["scan_on_push"].(bool), } } - output, err := conn.CreateRepositoryWithContext(ctx, input) + output, err := conn.CreateRepository(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) { input.Tags = nil - output, err = conn.CreateRepositoryWithContext(ctx, input) + output, err = conn.CreateRepository(ctx, input) } if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Repository (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Repository.RepositoryName)) + d.SetId(aws.ToString(output.Repository.RepositoryName)) // For partitions not supporting tag-on-create, attempt tag after create. if tags := getTagsIn(ctx); input.Tags == nil && len(tags) > 0 { - err := createTags(ctx, conn, aws.StringValue(output.Repository.RepositoryArn), tags) + err := createTags(ctx, conn, aws.ToString(output.Repository.RepositoryArn), tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) { return append(diags, resourceRepositoryRead(ctx, d, meta)...) } @@ -167,7 +167,7 @@ func resourceRepositoryCreate(ctx context.Context, d *schema.ResourceData, meta func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) { return FindRepositoryByName(ctx, conn, d.Id()) @@ -183,7 +183,7 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendErrorf(diags, "reading ECR Repository (%s): %s", d.Id(), err) } - repository := outputRaw.(*ecr.Repository) + repository := outputRaw.(*awstypes.Repository) d.Set("arn", repository.RepositoryArn) if err := d.Set("encryption_configuration", flattenRepositoryEncryptionConfiguration(repository.EncryptionConfiguration)); err != nil { @@ -202,16 +202,16 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta in func resourceRepositoryUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) if d.HasChange("image_tag_mutability") { input := &ecr.PutImageTagMutabilityInput{ - ImageTagMutability: aws.String(d.Get("image_tag_mutability").(string)), + ImageTagMutability: awstypes.ImageTagMutability((d.Get("image_tag_mutability").(string))), RegistryId: aws.String(d.Get("registry_id").(string)), RepositoryName: aws.String(d.Id()), } - _, err := conn.PutImageTagMutabilityWithContext(ctx, input) + _, err := conn.PutImageTagMutability(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ECR Repository (%s) image tag mutability: %s", d.Id(), err) @@ -220,17 +220,17 @@ func resourceRepositoryUpdate(ctx context.Context, d *schema.ResourceData, meta if d.HasChange("image_scanning_configuration") { input := &ecr.PutImageScanningConfigurationInput{ - ImageScanningConfiguration: &ecr.ImageScanningConfiguration{}, + ImageScanningConfiguration: &awstypes.ImageScanningConfiguration{}, RegistryId: aws.String(d.Get("registry_id").(string)), RepositoryName: aws.String(d.Id()), } if v, ok := d.GetOk("image_scanning_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { tfMap := v.([]interface{})[0].(map[string]interface{}) - input.ImageScanningConfiguration.ScanOnPush = aws.Bool(tfMap["scan_on_push"].(bool)) + input.ImageScanningConfiguration.ScanOnPush = tfMap["scan_on_push"].(bool) } - _, err := conn.PutImageScanningConfigurationWithContext(ctx, input) + _, err := conn.PutImageScanningConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "setting ECR Repository (%s) image scanning configuration: %s", d.Id(), err) @@ -242,20 +242,18 @@ func resourceRepositoryUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceRepositoryDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) log.Printf("[DEBUG] Deleting ECR Repository: %s", d.Id()) - _, err := conn.DeleteRepositoryWithContext(ctx, &ecr.DeleteRepositoryInput{ - Force: aws.Bool(d.Get("force_delete").(bool)), + _, err := conn.DeleteRepository(ctx, &ecr.DeleteRepositoryInput{ + Force: d.Get("force_delete").(bool), RegistryId: aws.String(d.Get("registry_id").(string)), RepositoryName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) { return diags - } - - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotEmptyException) { + } else if errs.IsA[*awstypes.RepositoryNotEmptyException](err) { return sdkdiag.AppendErrorf(diags, "ECR Repository (%s) not empty, consider using force_delete: %s", d.Id(), err) } @@ -274,9 +272,9 @@ func resourceRepositoryDelete(ctx context.Context, d *schema.ResourceData, meta return diags } -func FindRepositoryByName(ctx context.Context, conn *ecr.ECR, name string) (*ecr.Repository, error) { +func FindRepositoryByName(ctx context.Context, conn *ecr.Client, name string) (*awstypes.Repository, error) { input := &ecr.DescribeRepositoriesInput{ - RepositoryNames: aws.StringSlice([]string{name}), + RepositoryNames: []string{name}, } output, err := FindRepository(ctx, conn, input) @@ -286,7 +284,7 @@ func FindRepositoryByName(ctx context.Context, conn *ecr.ECR, name string) (*ecr } // Eventual consistency check. - if aws.StringValue(output.RepositoryName) != name { + if aws.ToString(output.RepositoryName) != name { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -295,10 +293,10 @@ func FindRepositoryByName(ctx context.Context, conn *ecr.ECR, name string) (*ecr return output, nil } -func FindRepository(ctx context.Context, conn *ecr.ECR, input *ecr.DescribeRepositoriesInput) (*ecr.Repository, error) { - output, err := conn.DescribeRepositoriesWithContext(ctx, input) +func FindRepository(ctx context.Context, conn *ecr.Client, input *ecr.DescribeRepositoriesInput) (*awstypes.Repository, error) { + output, err := conn.DescribeRepositories(ctx, input) - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -309,7 +307,7 @@ func FindRepository(ctx context.Context, conn *ecr.ECR, input *ecr.DescribeRepos return nil, err } - if output == nil || len(output.Repositories) == 0 || output.Repositories[0] == nil { + if output == nil || len(output.Repositories) == 0 { return nil, tfresource.NewEmptyResultError(input) } @@ -317,30 +315,30 @@ func FindRepository(ctx context.Context, conn *ecr.ECR, input *ecr.DescribeRepos return nil, tfresource.NewTooManyResultsError(count, input) } - return output.Repositories[0], nil + return &output.Repositories[0], nil } -func flattenImageScanningConfiguration(isc *ecr.ImageScanningConfiguration) []map[string]interface{} { +func flattenImageScanningConfiguration(isc *awstypes.ImageScanningConfiguration) []map[string]interface{} { if isc == nil { return nil } config := make(map[string]interface{}) - config["scan_on_push"] = aws.BoolValue(isc.ScanOnPush) + config["scan_on_push"] = isc.ScanOnPush return []map[string]interface{}{ config, } } -func expandRepositoryEncryptionConfiguration(data []interface{}) *ecr.EncryptionConfiguration { +func expandRepositoryEncryptionConfiguration(data []interface{}) *awstypes.EncryptionConfiguration { if len(data) == 0 || data[0] == nil { return nil } ec := data[0].(map[string]interface{}) - config := &ecr.EncryptionConfiguration{ - EncryptionType: aws.String(ec["encryption_type"].(string)), + config := &awstypes.EncryptionConfiguration{ + EncryptionType: awstypes.EncryptionType((ec["encryption_type"].(string))), } if v, ok := ec["kms_key"]; ok { if s := v.(string); s != "" { @@ -350,14 +348,14 @@ func expandRepositoryEncryptionConfiguration(data []interface{}) *ecr.Encryption return config } -func flattenRepositoryEncryptionConfiguration(ec *ecr.EncryptionConfiguration) []map[string]interface{} { +func flattenRepositoryEncryptionConfiguration(ec *awstypes.EncryptionConfiguration) []map[string]interface{} { if ec == nil { return nil } config := map[string]interface{}{ - "encryption_type": aws.StringValue(ec.EncryptionType), - "kms_key": aws.StringValue(ec.KmsKey), + "encryption_type": ec.EncryptionType, + "kms_key": aws.ToString(ec.KmsKey), } return []map[string]interface{}{ diff --git a/internal/service/ecr/repository_data_source.go b/internal/service/ecr/repository_data_source.go index a6fc6ad40db..f22e818b41d 100644 --- a/internal/service/ecr/repository_data_source.go +++ b/internal/service/ecr/repository_data_source.go @@ -8,9 +8,10 @@ import ( "log" "slices" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/ecr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -86,12 +87,12 @@ func DataSourceRepository() *schema.Resource { func dataSourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get("name").(string) input := &ecr.DescribeRepositoriesInput{ - RepositoryNames: aws.StringSlice([]string{name}), + RepositoryNames: []string{name}, } if v, ok := d.GetOk("registry_id"); ok { @@ -104,8 +105,8 @@ func dataSourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading ECR Repository (%s): %s", name, err) } - d.SetId(aws.StringValue(repository.RepositoryName)) - arn := aws.StringValue(repository.RepositoryArn) + d.SetId(aws.ToString(repository.RepositoryName)) + arn := aws.ToString(repository.RepositoryArn) d.Set("arn", arn) if err := d.Set("encryption_configuration", flattenRepositoryEncryptionConfiguration(repository.EncryptionConfiguration)); err != nil { return sdkdiag.AppendErrorf(diags, "setting encryption_configuration: %s", err) @@ -121,7 +122,7 @@ func dataSourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta tags, err := listTags(ctx, conn, arn) // Some partitions (i.e., ISO) may not support tagging, giving error - if meta.(*conns.AWSClient).Partition != endpoints.AwsPartitionID && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if meta.(*conns.AWSClient).Partition != endpoints.AwsPartitionID && errs.IsUnsupportedOperationInPartitionError(meta.(*conns.AWSClient).Partition, err) { log.Printf("[WARN] failed listing tags for ECR Repository (%s): %s", d.Id(), err) return diags } @@ -144,17 +145,17 @@ func dataSourceRepositoryRead(ctx context.Context, d *schema.ResourceData, meta } if len(imageDetails) >= 1 { - slices.SortFunc(imageDetails, func(a, b *ecr.ImageDetail) int { - if aws.TimeValue(a.ImagePushedAt).After(aws.TimeValue(b.ImagePushedAt)) { + slices.SortFunc(imageDetails, func(a, b *awstypes.ImageDetail) int { + if aws.ToTime(a.ImagePushedAt).After(aws.ToTime(b.ImagePushedAt)) { return -1 } - if aws.TimeValue(a.ImagePushedAt).Before(aws.TimeValue(b.ImagePushedAt)) { + if aws.ToTime(a.ImagePushedAt).Before(aws.ToTime(b.ImagePushedAt)) { return 1 } return 0 }) - d.Set("most_recent_image_tags", aws.StringValueSlice(imageDetails[0].ImageTags)) + d.Set("most_recent_image_tags", imageDetails[0].ImageTags) } else { d.Set("most_recent_image_tags", nil) } diff --git a/internal/service/ecr/repository_policy.go b/internal/service/ecr/repository_policy.go index cafc71a8ddd..267b0370e9b 100644 --- a/internal/service/ecr/repository_policy.go +++ b/internal/service/ecr/repository_policy.go @@ -7,15 +7,16 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -59,7 +60,7 @@ func ResourceRepositoryPolicy() *schema.Resource { func resourceRepositoryPolicyPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) @@ -77,9 +78,9 @@ func resourceRepositoryPolicyPut(ctx context.Context, d *schema.ResourceData, me // Retry due to IAM eventual consistency var out *ecr.SetRepositoryPolicyOutput err = retry.RetryContext(ctx, propagationTimeout, func() *retry.RetryError { - out, err = conn.SetRepositoryPolicyWithContext(ctx, &input) + out, err = conn.SetRepositoryPolicy(ctx, &input) - if tfawserr.ErrMessageContains(err, ecr.ErrCodeInvalidParameterException, "Invalid repository policy provided") { + if errs.IsAErrorMessageContains[*awstypes.InvalidParameterException](err, "Invalid repository policy provided") { return retry.RetryableError(err) } if err != nil { @@ -88,22 +89,22 @@ func resourceRepositoryPolicyPut(ctx context.Context, d *schema.ResourceData, me return nil }) if tfresource.TimedOut(err) { - out, err = conn.SetRepositoryPolicyWithContext(ctx, &input) + out, err = conn.SetRepositoryPolicy(ctx, &input) } if err != nil { return sdkdiag.AppendErrorf(diags, "creating ECR Repository Policy: %s", err) } - log.Printf("[DEBUG] ECR repository policy created: %s", aws.StringValue(out.RepositoryName)) + log.Printf("[DEBUG] ECR repository policy created: %s", aws.ToString(out.RepositoryName)) - d.SetId(aws.StringValue(out.RepositoryName)) + d.SetId(aws.ToString(out.RepositoryName)) return append(diags, resourceRepositoryPolicyRead(ctx, d, meta)...) } func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) input := &ecr.GetRepositoryPolicyInput{ RepositoryName: aws.String(d.Id()), @@ -114,13 +115,9 @@ func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, m err := retry.RetryContext(ctx, propagationTimeout, func() *retry.RetryError { var err error - out, err = conn.GetRepositoryPolicyWithContext(ctx, input) + out, err = conn.GetRepositoryPolicy(ctx, input) - if d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { - return retry.RetryableError(err) - } - - if d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryPolicyNotFoundException) { + if d.IsNewResource() && (errs.IsA[*awstypes.RepositoryNotFoundException](err) || errs.IsA[*awstypes.RepositoryPolicyNotFoundException](err)) { return retry.RetryableError(err) } @@ -132,16 +129,16 @@ func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, m }) if tfresource.TimedOut(err) { - out, err = conn.GetRepositoryPolicyWithContext(ctx, input) + out, err = conn.GetRepositoryPolicy(ctx, input) } - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.RepositoryNotFoundException](err) { log.Printf("[WARN] ECR Repository Policy (%s) not found, removing from state", d.Id()) d.SetId("") return diags } - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryPolicyNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.RepositoryPolicyNotFoundException](err) { log.Printf("[WARN] ECR Repository Policy (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -155,12 +152,12 @@ func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "reading ECR Repository Policy (%s): empty response", d.Id()) } - log.Printf("[DEBUG] Received repository policy %s", out) + log.Printf("[DEBUG] Received repository policy %s", *out.PolicyText) d.Set("repository", out.RepositoryName) d.Set("registry_id", out.RegistryId) - policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.StringValue(out.PolicyText)) + policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.ToString(out.PolicyText)) if err != nil { return sdkdiag.AppendErrorf(diags, "while setting policy (%s), encountered: %s", policyToSet, err) @@ -179,15 +176,15 @@ func resourceRepositoryPolicyRead(ctx context.Context, d *schema.ResourceData, m func resourceRepositoryPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ECRConn(ctx) + conn := meta.(*conns.AWSClient).ECRClient(ctx) - _, err := conn.DeleteRepositoryPolicyWithContext(ctx, &ecr.DeleteRepositoryPolicyInput{ + _, err := conn.DeleteRepositoryPolicy(ctx, &ecr.DeleteRepositoryPolicyInput{ RepositoryName: aws.String(d.Id()), RegistryId: aws.String(d.Get("registry_id").(string)), }) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) || - tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryPolicyNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) || + errs.IsA[*awstypes.RepositoryPolicyNotFoundException](err) { return diags } return sdkdiag.AppendErrorf(diags, "deleting ECR Repository Policy (%s): %s", d.Id(), err) diff --git a/internal/service/ecr/repository_policy_test.go b/internal/service/ecr/repository_policy_test.go index 5b64d825632..69320ec1f88 100644 --- a/internal/service/ecr/repository_policy_test.go +++ b/internal/service/ecr/repository_policy_test.go @@ -9,14 +9,15 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" tfecr "github.com/hashicorp/terraform-provider-aws/internal/service/ecr" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -170,20 +171,20 @@ func TestAccECRRepositoryPolicy_Disappears_repository(t *testing.T) { func testAccCheckRepositoryPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_repository_policy" { continue } - _, err := conn.GetRepositoryPolicyWithContext(ctx, &ecr.GetRepositoryPolicyInput{ + _, err := conn.GetRepositoryPolicy(ctx, &ecr.GetRepositoryPolicyInput{ RegistryId: aws.String(rs.Primary.Attributes["registry_id"]), RepositoryName: aws.String(rs.Primary.ID), }) if err != nil { - if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) || - tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryPolicyNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) || + errs.IsA[*awstypes.RepositoryPolicyNotFoundException](err) { return nil } return err diff --git a/internal/service/ecr/repository_test.go b/internal/service/ecr/repository_test.go index 3c214e0d272..1408366f3b9 100644 --- a/internal/service/ecr/repository_test.go +++ b/internal/service/ecr/repository_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -24,7 +24,7 @@ import ( func TestAccECRRepository_basic(t *testing.T) { ctx := acctest.Context(t) - var v ecr.Repository + var v awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" @@ -43,7 +43,7 @@ func TestAccECRRepository_basic(t *testing.T) { testAccCheckRepositoryRegistryID(resourceName), testAccCheckRepositoryRepositoryURL(resourceName, rName), resource.TestCheckResourceAttr(resourceName, "encryption_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", ecr.EncryptionTypeAes256), + resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", string(awstypes.EncryptionTypeAes256)), resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.kms_key", ""), ), }, @@ -58,7 +58,7 @@ func TestAccECRRepository_basic(t *testing.T) { func TestAccECRRepository_disappears(t *testing.T) { ctx := acctest.Context(t) - var v ecr.Repository + var v awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" @@ -82,7 +82,7 @@ func TestAccECRRepository_disappears(t *testing.T) { func TestAccECRRepository_tags(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ecr.Repository + var v1, v2 awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" @@ -128,7 +128,7 @@ func TestAccECRRepository_tags(t *testing.T) { func TestAccECRRepository_immutability(t *testing.T) { ctx := acctest.Context(t) - var v ecr.Repository + var v awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" @@ -157,7 +157,7 @@ func TestAccECRRepository_immutability(t *testing.T) { func TestAccECRRepository_Image_scanning(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ecr.Repository + var v1, v2 awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" @@ -208,7 +208,7 @@ func TestAccECRRepository_Image_scanning(t *testing.T) { func TestAccECRRepository_Encryption_kms(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ecr.Repository + var v1, v2 awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" kmsKeyDataSourceName := "aws_kms_key.test" @@ -224,7 +224,7 @@ func TestAccECRRepository_Encryption_kms(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckRepositoryExists(ctx, resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "encryption_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", ecr.EncryptionTypeKms), + resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", string(awstypes.EncryptionTypeKms)), // This will be the default ECR service KMS key. We don't currently have a way to look this up. acctest.MatchResourceAttrRegionalARN(resourceName, "encryption_configuration.0.kms_key", "kms", regexache.MustCompile(fmt.Sprintf("key/%s$", verify.UUIDRegexPattern))), ), @@ -240,7 +240,7 @@ func TestAccECRRepository_Encryption_kms(t *testing.T) { testAccCheckRepositoryExists(ctx, resourceName, &v2), testAccCheckRepositoryRecreated(&v1, &v2), resource.TestCheckResourceAttr(resourceName, "encryption_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", ecr.EncryptionTypeKms), + resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", string(awstypes.EncryptionTypeKms)), resource.TestCheckResourceAttrPair(resourceName, "encryption_configuration.0.kms_key", kmsKeyDataSourceName, "arn"), ), }, @@ -255,7 +255,7 @@ func TestAccECRRepository_Encryption_kms(t *testing.T) { func TestAccECRRepository_Encryption_aes256(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 ecr.Repository + var v1, v2 awstypes.Repository rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_ecr_repository.test" @@ -278,7 +278,7 @@ func TestAccECRRepository_Encryption_aes256(t *testing.T) { testAccCheckRepositoryExists(ctx, resourceName, &v2), testAccCheckRepositoryNotRecreated(&v1, &v2), resource.TestCheckResourceAttr(resourceName, "encryption_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", ecr.EncryptionTypeAes256), + resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.encryption_type", string(awstypes.EncryptionTypeAes256)), resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.kms_key", ""), ), }, @@ -298,8 +298,7 @@ func TestAccECRRepository_Encryption_aes256(t *testing.T) { func testAccCheckRepositoryDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) - + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ecr_repository" { continue @@ -322,7 +321,7 @@ func testAccCheckRepositoryDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckRepositoryExists(ctx context.Context, n string, v *ecr.Repository) resource.TestCheckFunc { +func testAccCheckRepositoryExists(ctx context.Context, n string, v *awstypes.Repository) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -333,7 +332,7 @@ func testAccCheckRepositoryExists(ctx context.Context, n string, v *ecr.Reposito return fmt.Errorf("No ECR Repository ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ECRConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ECRClient(ctx) output, err := tfecr.FindRepositoryByName(ctx, conn, rs.Primary.ID) @@ -361,9 +360,9 @@ func testAccCheckRepositoryRepositoryURL(resourceName, repositoryName string) re } } -func testAccCheckRepositoryRecreated(i, j *ecr.Repository) resource.TestCheckFunc { // nosemgrep:ci.ecr-in-func-name +func testAccCheckRepositoryRecreated(i, j *awstypes.Repository) resource.TestCheckFunc { // nosemgrep:ci.ecr-in-func-name return func(s *terraform.State) error { - if aws.TimeValue(i.CreatedAt).Equal(aws.TimeValue(j.CreatedAt)) { + if aws.ToTime(i.CreatedAt).Equal(aws.ToTime(j.CreatedAt)) { return fmt.Errorf("ECR repository was not recreated") } @@ -371,9 +370,9 @@ func testAccCheckRepositoryRecreated(i, j *ecr.Repository) resource.TestCheckFun } } -func testAccCheckRepositoryNotRecreated(i, j *ecr.Repository) resource.TestCheckFunc { // nosemgrep:ci.ecr-in-func-name +func testAccCheckRepositoryNotRecreated(i, j *awstypes.Repository) resource.TestCheckFunc { // nosemgrep:ci.ecr-in-func-name return func(s *terraform.State) error { - if !aws.TimeValue(i.CreatedAt).Equal(aws.TimeValue(j.CreatedAt)) { + if !aws.ToTime(i.CreatedAt).Equal(aws.ToTime(j.CreatedAt)) { return fmt.Errorf("ECR repository was recreated") } diff --git a/internal/service/ecr/service_endpoints_gen_test.go b/internal/service/ecr/service_endpoints_gen_test.go index b95694bc169..88afce39b22 100644 --- a/internal/service/ecr/service_endpoints_gen_test.go +++ b/internal/service/ecr/service_endpoints_gen_test.go @@ -15,7 +15,6 @@ import ( aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" ecr_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ecr" - ecr_sdkv1 "github.com/aws/aws-sdk-go/service/ecr" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -203,25 +202,13 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S }, } - t.Run("v1", func(t *testing.T) { - for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv - testcase := testcase + for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv + testcase := testcase - t.Run(name, func(t *testing.T) { - testEndpointCase(t, region, testcase, callServiceV1) - }) - } - }) - - t.Run("v2", func(t *testing.T) { - for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv - testcase := testcase - - t.Run(name, func(t *testing.T) { - testEndpointCase(t, region, testcase, callServiceV2) - }) - } - }) + t.Run(name, func(t *testing.T) { + testEndpointCase(t, region, testcase, callService) + }) + } } func defaultEndpoint(region string) string { @@ -241,7 +228,7 @@ func defaultEndpoint(region string) string { return ep.URI.String() } -func callServiceV2(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { +func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { t.Helper() var endpoint string @@ -265,20 +252,6 @@ func callServiceV2(ctx context.Context, t *testing.T, meta *conns.AWSClient) str return endpoint } -func callServiceV1(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { - t.Helper() - - client := meta.ECRConn(ctx) - - req, _ := client.DescribeRepositoriesRequest(&ecr_sdkv1.DescribeRepositoriesInput{}) - - req.HTTPRequest.URL.Path = "/" - - endpoint := req.HTTPRequest.URL.String() - - return endpoint -} - func withNoConfig(_ *caseSetup) { // no-op } diff --git a/internal/service/ecr/service_package_gen.go b/internal/service/ecr/service_package_gen.go index fa74617d9a7..3804ee203c1 100644 --- a/internal/service/ecr/service_package_gen.go +++ b/internal/service/ecr/service_package_gen.go @@ -7,9 +7,6 @@ import ( aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" ecr_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ecr" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - ecr_sdkv1 "github.com/aws/aws-sdk-go/service/ecr" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -94,13 +91,6 @@ func (p *servicePackage) ServicePackageName() string { return names.ECR } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*ecr_sdkv1.ECR, error) { - sess := config["session"].(*session_sdkv1.Session) - - return ecr_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil -} - // NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*ecr_sdkv2.Client, error) { cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) diff --git a/internal/service/ecr/sweep.go b/internal/service/ecr/sweep.go index 2b4fb47cb48..fca783fba20 100644 --- a/internal/service/ecr/sweep.go +++ b/internal/service/ecr/sweep.go @@ -7,13 +7,14 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/sweep" - "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" ) func RegisterSweepers() { @@ -29,26 +30,26 @@ func sweepRepositories(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ECRConn(ctx) + conn := client.ECRClient(ctx) var errors error - err = conn.DescribeRepositoriesPagesWithContext(ctx, &ecr.DescribeRepositoriesInput{}, func(page *ecr.DescribeRepositoriesOutput, lastPage bool) bool { + err = describeRepositoriesPages(ctx, conn, &ecr.DescribeRepositoriesInput{}, func(page *ecr.DescribeRepositoriesOutput, lastPage bool) bool { if page == nil { return !lastPage } for _, repository := range page.Repositories { - repositoryName := aws.StringValue(repository.RepositoryName) + repositoryName := aws.ToString(repository.RepositoryName) log.Printf("[INFO] Deleting ECR repository: %s", repositoryName) - _, err = conn.DeleteRepositoryWithContext(ctx, &ecr.DeleteRepositoryInput{ + _, err = conn.DeleteRepository(ctx, &ecr.DeleteRepositoryInput{ // We should probably sweep repositories even if there are images. - Force: aws.Bool(true), + Force: true, RegistryId: repository.RegistryId, RepositoryName: repository.RepositoryName, }) if err != nil { - if !tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) { + if errs.IsA[*awstypes.RepositoryNotFoundException](err) { sweeperErr := fmt.Errorf("Error deleting ECR repository (%s): %w", repositoryName, err) log.Printf("[ERROR] %s", sweeperErr) errors = multierror.Append(errors, sweeperErr) @@ -60,11 +61,11 @@ func sweepRepositories(region string) error { return !lastPage }) if err != nil { - if awsv1.SkipSweepError(err) { + if awsv2.SkipSweepError(err) { log.Printf("[WARN] Skipping ECR repository sweep for %s: %s", region, err) return nil } - errors = multierror.Append(errors, fmt.Errorf("Error retreiving ECR repositories: %w", err)) + errors = multierror.Append(errors, fmt.Errorf("Error retrieving ECR repositories: %w", err)) } return errors diff --git a/internal/service/ecr/tags_gen.go b/internal/service/ecr/tags_gen.go index 0c3bf816d13..96121741024 100644 --- a/internal/service/ecr/tags_gen.go +++ b/internal/service/ecr/tags_gen.go @@ -5,9 +5,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/aws/aws-sdk-go/service/ecr/ecriface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ecr" + awstypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +19,12 @@ import ( // listTags lists ecr service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn ecriface.ECRAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *ecr.Client, identifier string, optFns ...func(*ecr.Options)) (tftags.KeyValueTags, error) { input := &ecr.ListTagsForResourceInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsForResourceWithContext(ctx, input) + output, err := conn.ListTagsForResource(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +36,7 @@ func listTags(ctx context.Context, conn ecriface.ECRAPI, identifier string) (tft // ListTags lists ecr service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).ECRConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).ECRClient(ctx), identifier) if err != nil { return err @@ -52,11 +52,11 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri // []*SERVICE.Tag handling // Tags returns ecr service tags. -func Tags(tags tftags.KeyValueTags) []*ecr.Tag { - result := make([]*ecr.Tag, 0, len(tags)) +func Tags(tags tftags.KeyValueTags) []awstypes.Tag { + result := make([]awstypes.Tag, 0, len(tags)) for k, v := range tags.Map() { - tag := &ecr.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -68,11 +68,11 @@ func Tags(tags tftags.KeyValueTags) []*ecr.Tag { } // KeyValueTags creates tftags.KeyValueTags from ecr service tags. -func KeyValueTags(ctx context.Context, tags []*ecr.Tag) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags []awstypes.Tag) tftags.KeyValueTags { m := make(map[string]*string, len(tags)) for _, tag := range tags { - m[aws.StringValue(tag.Key)] = tag.Value + m[aws.ToString(tag.Key)] = tag.Value } return tftags.New(ctx, m) @@ -80,7 +80,7 @@ func KeyValueTags(ctx context.Context, tags []*ecr.Tag) tftags.KeyValueTags { // getTagsIn returns ecr service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*ecr.Tag { +func getTagsIn(ctx context.Context) []awstypes.Tag { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -91,14 +91,14 @@ func getTagsIn(ctx context.Context) []*ecr.Tag { } // setTagsOut sets ecr service tags in Context. -func setTagsOut(ctx context.Context, tags []*ecr.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } } // createTags creates ecr service tags for new resources. -func createTags(ctx context.Context, conn ecriface.ECRAPI, identifier string, tags []*ecr.Tag) error { +func createTags(ctx context.Context, conn *ecr.Client, identifier string, tags []awstypes.Tag) error { if len(tags) == 0 { return nil } @@ -109,7 +109,7 @@ func createTags(ctx context.Context, conn ecriface.ECRAPI, identifier string, ta // updateTags updates ecr service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn ecriface.ECRAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *ecr.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*ecr.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -120,10 +120,10 @@ func updateTags(ctx context.Context, conn ecriface.ECRAPI, identifier string, ol if len(removedTags) > 0 { input := &ecr.UntagResourceInput{ ResourceArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -138,7 +138,7 @@ func updateTags(ctx context.Context, conn ecriface.ECRAPI, identifier string, ol Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -151,5 +151,5 @@ func updateTags(ctx context.Context, conn ecriface.ECRAPI, identifier string, ol // UpdateTags updates ecr service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).ECRConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).ECRClient(ctx), identifier, oldTags, newTags) } diff --git a/names/data/names_data.csv b/names/data/names_data.csv index 05429f0ff46..e9606ade2c4 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -132,7 +132,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,,,,,,,EC2,DescribeVpcs,, imagebuilder,imagebuilder,imagebuilder,imagebuilder,,imagebuilder,,,ImageBuilder,Imagebuilder,,1,,,aws_imagebuilder_,,imagebuilder_,EC2 Image Builder,Amazon,,,,,,,imagebuilder,ListImages,, ec2-instance-connect,ec2instanceconnect,ec2instanceconnect,ec2instanceconnect,,ec2instanceconnect,,,EC2InstanceConnect,EC2InstanceConnect,,1,,,aws_ec2instanceconnect_,,ec2instanceconnect_,EC2 Instance Connect,AWS,,x,,,,,EC2 Instance Connect,,, -ecr,ecr,ecr,ecr,,ecr,,,ECR,ECR,,1,2,,aws_ecr_,,ecr_,ECR (Elastic Container Registry),Amazon,,,,,,,ECR,DescribeRepositories,, +ecr,ecr,ecr,ecr,,ecr,,,ECR,ECR,,,2,,aws_ecr_,,ecr_,ECR (Elastic Container Registry),Amazon,,,,,,,ECR,DescribeRepositories,, ecr-public,ecrpublic,ecrpublic,ecrpublic,,ecrpublic,,,ECRPublic,ECRPublic,,,2,,aws_ecrpublic_,,ecrpublic_,ECR Public,Amazon,,,,,,,ECR PUBLIC,DescribeRepositories,, ecs,ecs,ecs,ecs,,ecs,,,ECS,ECS,,1,2,,aws_ecs_,,ecs_,ECS (Elastic Container),Amazon,,,,,,,ECS,ListClusters,, efs,efs,efs,efs,,efs,,,EFS,EFS,,1,,,aws_efs_,,efs_,EFS (Elastic File System),Amazon,,,,,,,EFS,DescribeFileSystems,,