Skip to content

Commit

Permalink
Merge pull request #30034 from hashicorp/td-ecrpublic-region
Browse files Browse the repository at this point in the history
data-source/aws_ecrpublic_authorization_token: Update documentation to say `us-east-1`-only
  • Loading branch information
gdavison authored Mar 16, 2023
2 parents 8ef7ae8 + b7c8c73 commit 9bccc30
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 45 deletions.
1 change: 0 additions & 1 deletion docs/acc-test-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi
| `AWS_CODEBUILD_GITHUB_SOURCE_LOCATION` | GitHub source URL for CodeBuild testing. CodeBuild must have access to this repository via OAuth or Source Credentials. Defaults to `https://github.com/hashibot-test/aws-test.git`. |
| `AWS_DEFAULT_REGION` | Primary AWS region for tests. Defaults to `us-west-2`. |
| `AWS_DETECTIVE_MEMBER_EMAIL` | Email address for Detective Member testing. A valid email address associated with an AWS root account is required for tests to pass. |
| `AWS_EC2_CLASSIC_REGION` | AWS region for EC2-Classic testing. Defaults to `us-east-1` in AWS Commercial and `AWS_DEFAULT_REGION` otherwise. |
| `AWS_EC2_CLIENT_VPN_LIMIT` | Concurrency limit for Client VPN acceptance tests. [Default is 5](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/limits.html) if not specified. |
| `AWS_EC2_EIP_PUBLIC_IPV4_POOL` | Identifier for EC2 Public IPv4 Pool for EC2 EIP testing. |
| `AWS_GUARDDUTY_MEMBER_ACCOUNT_ID` | Identifier of AWS Account for GuardDuty Member testing. **DEPRECATED:** Should be replaced with standard alternate account handling for tests. |
Expand Down
6 changes: 3 additions & 3 deletions internal/service/ecrpublic/authorization_token_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ func dataSourceAuthorizationTokenRead(ctx context.Context, d *schema.ResourceDat
out, err := conn.GetAuthorizationTokenWithContext(ctx, params)

if err != nil {
return sdkdiag.AppendErrorf(diags, "getting Public ECR authorization token: %s", err)
return sdkdiag.AppendErrorf(diags, "getting ECR Public authorization token: %s", err)
}

authorizationData := out.AuthorizationData
authorizationToken := aws.StringValue(authorizationData.AuthorizationToken)
expiresAt := aws.TimeValue(authorizationData.ExpiresAt).Format(time.RFC3339)
authBytes, err := base64.URLEncoding.DecodeString(authorizationToken)
if err != nil {
return sdkdiag.AppendErrorf(diags, "decoding Public ECR authorization token: %s", err)
return sdkdiag.AppendErrorf(diags, "decoding ECR Public authorization token: %s", err)
}

basicAuthorization := strings.Split(string(authBytes), ":")
if len(basicAuthorization) != 2 {
return sdkdiag.AppendErrorf(diags, "unknown Public ECR authorization token format")
return sdkdiag.AppendErrorf(diags, "unknown ECR Public authorization token format")
}

userName := basicAuthorization[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
Expand All @@ -14,12 +15,12 @@ func TestAccECRPublicAuthorizationTokenDataSource_basic(t *testing.T) {
dataSourceName := "data.aws_ecrpublic_authorization_token.repo"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecr.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccAuthorizationTokenDataSourceConfig_basic,
Config: testAccAuthorizationTokenDataSourceConfig_basic(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "authorization_token"),
resource.TestCheckResourceAttrSet(dataSourceName, "expires_at"),
Expand All @@ -32,6 +33,7 @@ func TestAccECRPublicAuthorizationTokenDataSource_basic(t *testing.T) {
})
}

var testAccAuthorizationTokenDataSourceConfig_basic = `
data "aws_ecrpublic_authorization_token" "repo" {}
func testAccAuthorizationTokenDataSourceConfig_basic() string {
return `data "aws_ecrpublic_authorization_token" "repo" {}
`
}
9 changes: 5 additions & 4 deletions internal/service/ecrpublic/repository_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/ecrpublic"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -21,7 +22,7 @@ func TestAccECRPublicRepositoryPolicy_basic(t *testing.T) {
resourceName := "aws_ecrpublic_repository_policy.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryPolicyDestroy(ctx),
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestAccECRPublicRepositoryPolicy_disappears(t *testing.T) {
resourceName := "aws_ecrpublic_repository_policy.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryPolicyDestroy(ctx),
Expand All @@ -80,7 +81,7 @@ func TestAccECRPublicRepositoryPolicy_Disappears_repository(t *testing.T) {
repositoryResourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryPolicyDestroy(ctx),
Expand All @@ -104,7 +105,7 @@ func TestAccECRPublicRepositoryPolicy_iam(t *testing.T) {
resourceName := "aws_ecrpublic_repository_policy.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryPolicyDestroy(ctx),
Expand Down
40 changes: 10 additions & 30 deletions internal/service/ecrpublic/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccECRPublicRepository_basic(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestAccECRPublicRepository_tags(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestAccECRPublicRepository_CatalogData_aboutText(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestAccECRPublicRepository_CatalogData_architectures(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestAccECRPublicRepository_CatalogData_description(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestAccECRPublicRepository_CatalogData_operatingSystems(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestAccECRPublicRepository_CatalogData_usageText(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestAccECRPublicRepository_CatalogData_logoImageBlob(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -315,7 +315,7 @@ func TestAccECRPublicRepository_Basic_forceDestroy(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestAccECRPublicRepository_disappears(t *testing.T) {
resourceName := "aws_ecrpublic_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) },
ErrorCheck: acctest.ErrorCheck(t, ecrpublic.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRepositoryDestroy(ctx),
Expand Down Expand Up @@ -533,23 +533,3 @@ resource "aws_ecrpublic_repository" "test" {
}
`, rName)
}

func testAccPreCheck(ctx context.Context, t *testing.T) {
// At this time, calls to DescribeRepositories returns (and by default, retries)
// an InternalFailure when the region is not supported i.e. not us-east-1.
// TODO: Remove when ECRPublic is supported across other known regions
// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/18047
if region := acctest.Provider.Meta().(*conns.AWSClient).Region; region != endpoints.UsEast1RegionID {
t.Skipf("skipping acceptance testing: region (%s) does not support ECR Public repositories", region)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).ECRPublicConn()
input := &ecrpublic.DescribeRepositoriesInput{}
_, err := conn.DescribeRepositoriesWithContext(ctx, input)
if acctest.PreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
}
if err != nil {
t.Fatalf("unexpected PreCheck error: %s", err)
}
}
4 changes: 3 additions & 1 deletion website/docs/d/ecrpublic_authorization_token.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: |-

# Data Source: aws_ecrpublic_authorization_token

The Public ECR Authorization Token data source allows the authorization token, token expiration date, user name and password to be retrieved for a Public ECR repository.
The Public ECR Authorization Token data source allows the authorization token, token expiration date, user name, and password to be retrieved for a Public ECR repository.

~> **NOTE:** This data source can only be used in the `us-east-1` region.

## Example Usage

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/ecrpublic_repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: |-

Provides a Public Elastic Container Registry Repository.

~> **NOTE:** This resource can only be used with `us-east-1` region.
~> **NOTE:** This resource can only be used in the `us-east-1` region.

## Example Usage

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/ecrpublic_repository_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Provides an Elastic Container Registry Public Repository Policy.

Note that currently only one policy may be applied to a repository.

~> **NOTE:** This resource can only be used with `us-east-1` region.
~> **NOTE:** This resource can only be used in the `us-east-1` region.

## Example Usage

Expand Down

0 comments on commit 9bccc30

Please sign in to comment.