Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AWS SDK for Go Migration] ECR (Elastic Container Registry) Service #36493

Merged
merged 37 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
08da208
data_source/ecr_lifecycle_policy_document: adding new data source for…
slapula Oct 12, 2018
8d96c00
adding documentation
slapula Oct 12, 2018
c3c906d
fixing acc test
slapula Oct 12, 2018
d3995af
fixing docs
slapula Oct 12, 2018
819b1d6
removing unneeded out
slapula Oct 12, 2018
e551dea
fix: Add missing aws_ecr_lifecycle_policy tagPatternList change
acwwat Jan 10, 2024
a92b240
migrated ecr
alexknez Mar 20, 2024
9250dc1
Merge branch 'main' into HEAD
ewbankkit Mar 28, 2024
81e819c
d/aws_ecr_authorization_token: Reduce visibility.
ewbankkit Mar 28, 2024
629764d
d/aws_ecr_image: Reduce visibility.
ewbankkit Mar 28, 2024
71031c6
r/aws_ecr_lifecycle_policy: Reduce visibility.
ewbankkit Mar 29, 2024
f1b5e84
r/aws_ecr_pull_through_cache_rule: Tidy up.
ewbankkit Mar 29, 2024
e5562b1
r/aws_ecr_registry_policy: Reduce visibility.
ewbankkit Mar 29, 2024
496f3f1
r/aws_ecr_registry_scanning_configuration: Reduce visibility.
ewbankkit Mar 29, 2024
2b864d8
r/aws_ecr_registry_scanning_configuration: Fixup acceptance tests.
ewbankkit Mar 29, 2024
3baa67c
r/aws_ecr_replication_configuration: Reduce visibility.
ewbankkit Mar 29, 2024
55d7b33
d/aws_ecr_repositories: Tidy up.
ewbankkit Mar 29, 2024
90019f6
d/aws_ecr_repository: Reduce visibility.
ewbankkit Mar 29, 2024
0ee6295
r/aws_ecr_repository: Reduce visibility.
ewbankkit Mar 29, 2024
004b82b
r/aws_ecr_repository_policy: Reduce visibility.
ewbankkit Mar 29, 2024
7f14b5c
d/aws_ecr_repository: Correct annotation.
ewbankkit Mar 29, 2024
e73f2ef
Correct IsNewResource check in Read.
ewbankkit Mar 29, 2024
3ca47bc
Tidy up 'testAccRegistryScanningConfiguration_update'.
ewbankkit Mar 29, 2024
5aee543
Revert "removing unneeded out"
ewbankkit Mar 29, 2024
c2221b7
Revert "fixing docs"
ewbankkit Mar 29, 2024
b2f1060
Revert "fixing acc test"
ewbankkit Mar 29, 2024
3f25cfc
Revert "adding documentation"
ewbankkit Mar 29, 2024
99cc2c2
Revert "data_source/ecr_lifecycle_policy_document: adding new data so…
ewbankkit Mar 29, 2024
585d9e1
Merge branch 'main' into HEAD
ewbankkit Mar 29, 2024
a35a8c3
Merge commit '585d9e1cd617ad32b8ffea4566273f7358cc7782' into HEAD
ewbankkit Mar 29, 2024
a31db27
Merge commit 'a35a8c322929cdd8d82f25b2a68f0f5a9212708e' into HEAD
ewbankkit Mar 29, 2024
e182c8b
Acceptance test output:
ewbankkit Mar 29, 2024
0d1571f
d/aws_ecr_lifecycle_policy_document: New data source.
ewbankkit Mar 29, 2024
cc1947c
d/aws_ecr_lifecycle_policy_document: Acceptance tests.
ewbankkit Mar 29, 2024
90aef9c
Fix markdown-lint errors.
ewbankkit Mar 29, 2024
0e76860
Fix terrafmt errors.
ewbankkit Mar 29, 2024
97148c2
Fix golangci-lint 'whitespace'.
ewbankkit Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35231.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecr_lifecycle_policy: Add missing `tagPatternList` change detection in policy JSON
```
3 changes: 3 additions & 0 deletions .changelog/6133.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_ecr_lifecycle_policy_document
```
5 changes: 0 additions & 5 deletions internal/conns/awsclient_gen.go

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

1 change: 0 additions & 1 deletion internal/service/bedrock/custom_model_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (d *customModelDataSource) Metadata(_ context.Context, request datasource.M
response.TypeName = "aws_bedrock_custom_model"
}

// Schema returns the schema for this data source.
func (d *customModelDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
Expand Down
51 changes: 24 additions & 27 deletions internal/service/ecr/authorization_token_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@ package ecr

import (
"context"
"log"
"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"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
)

// @SDKDataSource("aws_ecr_authorization_token")
func DataSourceAuthorizationToken() *schema.Resource {
// @SDKDataSource("aws_ecr_authorization_token", name="Authorization Token")
func dataSourceAuthorizationToken() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceAuthorizationTokenRead,

Schema: map[string]*schema.Schema{
"registry_id": {
"authorization_token": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"expires_at": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"authorization_token": {
"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Expand All @@ -37,40 +41,32 @@ func DataSourceAuthorizationToken() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"expires_at": {
"registry_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"user_name": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
}
}

func dataSourceAuthorizationTokenRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ECRConn(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)
conn := meta.(*conns.AWSClient).ECRClient(ctx)

out, err := conn.GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenInput{})

if err != nil {
return sdkdiag.AppendErrorf(diags, "getting ECR authorization token: %s", err)
return sdkdiag.AppendErrorf(diags, "reading 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("")
Expand All @@ -88,5 +84,6 @@ func dataSourceAuthorizationTokenRead(ctx context.Context, d *schema.ResourceDat
d.Set("expires_at", expiresAt)
d.Set("user_name", userName)
d.Set("password", password)

return diags
}
14 changes: 13 additions & 1 deletion internal/service/ecr/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ package ecr

// Exports for use in tests only.
var (
ResourcePullThroughCacheRule = resourcePullThroughCacheRule
ResourceLifecyclePolicy = resourceLifecyclePolicy
ResourcePullThroughCacheRule = resourcePullThroughCacheRule
ResourceRegistryPolicy = resourceRegistryPolicy
ResourceRegistryScanningConfiguration = resourceRegistryScanningConfiguration
ResourceReplicationConfiguration = resourceReplicationConfiguration
ResourceRepository = resourceRepository
ResourceRepositoryPolicy = resourceRepositoryPolicy

FindLifecyclePolicyByRepositoryName = findLifecyclePolicyByRepositoryName
FindPullThroughCacheRuleByRepositoryPrefix = findPullThroughCacheRuleByRepositoryPrefix
FindRegistryPolicy = findRegistryPolicy
FindRegistryScanningConfiguration = findRegistryScanningConfiguration
FindReplicationConfiguration = findReplicationConfiguration
FindRepositoryByName = findRepositoryByName
FindRepositoryPolicyByRepositoryName = findRepositoryPolicyByRepositoryName
)
2 changes: 1 addition & 1 deletion internal/service/ecr/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
69 changes: 32 additions & 37 deletions internal/service/ecr/image_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ 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"
"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"
)

// @SDKDataSource("aws_ecr_image")
func DataSourceImage() *schema.Resource {
// @SDKDataSource("aws_ecr_image", name="Image")
func dataSourceImage() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceImageRead,

Schema: map[string]*schema.Schema{
"image_digest": {
Type: schema.TypeString,
Expand Down Expand Up @@ -76,14 +78,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 = []types.ImageIdentifier{
{
ImageDigest: aws.String(v.(string)),
},
Expand All @@ -92,7 +94,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 = []types.ImageIdentifier{
{
ImageTag: aws.String(v.(string)),
},
Expand All @@ -106,7 +108,7 @@ func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, meta inter
input.RegistryId = aws.String(v.(string))
}

imageDetails, err := FindImageDetails(ctx, conn, input)
imageDetails, err := findImageDetails(ctx, conn, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading ECR Images: %s", err)
Expand All @@ -121,11 +123,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 types.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
Expand All @@ -134,56 +136,49 @@ 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,
}

repository, err := FindRepository(ctx, conn, repositoryInput)
repository, err := findRepository(ctx, conn, repositoryInput)

if err != nil {
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) ([]types.ImageDetail, error) {
var output []types.ImageDetail

err := conn.DescribeImagesPagesWithContext(ctx, input, func(page *ecr.DescribeImagesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
pages := ecr.NewDescribeImagesPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

for _, v := range page.ImageDetails {
if v != nil {
output = append(output, v)
if errs.IsA[*types.ImageNotFoundException](err) || errs.IsA[*types.RepositoryNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
if err != nil {
return nil, err
}
}

if err != nil {
return nil, err
output = append(output, page.ImageDetails...)
}

return output, nil
Expand Down
Loading
Loading