From d25d41d1ba9378d7dc31950254354a9e61926ba7 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sun, 20 Dec 2020 09:46:08 +0200 Subject: [PATCH 01/15] add ecr replication config --- aws/provider.go | 1 + ...ource_aws_ecr_replication_configuration.go | 200 ++++++++++++++++++ ..._aws_ecr_replication_configuration_test.go | 62 ++++++ 3 files changed, 263 insertions(+) create mode 100644 aws/resource_aws_ecr_replication_configuration.go create mode 100644 aws/resource_aws_ecr_replication_configuration_test.go diff --git a/aws/provider.go b/aws/provider.go index 9a268bf1f49..1b5ca4238a7 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -667,6 +667,7 @@ func Provider() *schema.Provider { "aws_ec2_transit_gateway_vpc_attachment_accepter": resourceAwsEc2TransitGatewayVpcAttachmentAccepter(), "aws_ecr_lifecycle_policy": resourceAwsEcrLifecyclePolicy(), "aws_ecrpublic_repository": resourceAwsEcrPublicRepository(), + "aws_ecr_replication_configuration": resourceAwsEcrReplicationConfiguration(), "aws_ecr_repository": resourceAwsEcrRepository(), "aws_ecr_repository_policy": resourceAwsEcrRepositoryPolicy(), "aws_ecs_capacity_provider": resourceAwsEcsCapacityProvider(), diff --git a/aws/resource_aws_ecr_replication_configuration.go b/aws/resource_aws_ecr_replication_configuration.go new file mode 100644 index 00000000000..62f1ef0387d --- /dev/null +++ b/aws/resource_aws_ecr_replication_configuration.go @@ -0,0 +1,200 @@ +package aws + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ecr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceAwsEcrReplicationConfiguration() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsEcrReplicationConfigurationPut, + Read: resourceAwsEcrReplicationConfigurationRead, + Update: resourceAwsEcrReplicationConfigurationPut, + Delete: schema.Noop, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "registry_id": { + Type: schema.TypeString, + Computed: true, + }, + "replication_configuration": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "destination": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": { + Type: schema.TypeString, + Required: true, + }, + "registry_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateAwsAccountId, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func resourceAwsEcrReplicationConfigurationPut(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).ecrconn + + input := ecr.PutReplicationConfigurationInput{ + ReplicationConfiguration: expandEcrReplicationConfigurationReplicationConfiguration(d.Get("replication_configuration").([]interface{})), + } + + log.Printf("[DEBUG] Creating ECR Replication Configuration: %#v", input) + _, err := conn.PutReplicationConfiguration(&input) + if err != nil { + return fmt.Errorf("error creating ECR Replication Configuration: %s", err) + } + + d.SetId(meta.(*AWSClient).accountid) + + return resourceAwsEcrReplicationConfigurationRead(d, meta) +} + +func resourceAwsEcrReplicationConfigurationRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).ecrconn + + log.Printf("[DEBUG] Reading ECR Replication Configuration %s", d.Id()) + out, err := conn.DescribeRegistry(&ecr.DescribeRegistryInput{}) + if err != nil { + return fmt.Errorf("error reading ECR Replication Configuration: %w", err) + } + + d.Set("registry_id", out.RegistryId) + + if err := d.Set("replication_configuration", flattenEcrReplicationConfigurationReplicationConfiguration(out.ReplicationConfiguration)); err != nil { + return fmt.Errorf("error setting replication_configuration for ECR Replication Configuration: %w", err) + } + + return nil +} + +func expandEcrReplicationConfigurationReplicationConfiguration(data []interface{}) *ecr.ReplicationConfiguration { + if len(data) == 0 || data[0] == nil { + return nil + } + + ec := data[0].(map[string]interface{}) + config := &ecr.ReplicationConfiguration{ + Rules: expandEcrReplicationConfigurationReplicationConfigurationRules(ec["rule"].([]interface{})), + } + return config +} + +func flattenEcrReplicationConfigurationReplicationConfiguration(ec *ecr.ReplicationConfiguration) []map[string]interface{} { + if ec == nil { + return nil + } + + config := map[string]interface{}{ + "rule": flattenEcrReplicationConfigurationReplicationConfigurationRules(ec.Rules), + } + + return []map[string]interface{}{ + config, + } +} + +func expandEcrReplicationConfigurationReplicationConfigurationRules(data []interface{}) []*ecr.ReplicationRule { + if len(data) == 0 || data[0] == nil { + return nil + } + + var rules []*ecr.ReplicationRule + + for _, rule := range data { + ec := rule.(map[string]interface{}) + config := &ecr.ReplicationRule{ + Destinations: expandEcrReplicationConfigurationReplicationConfigurationRulesDestinations(ec["destination"].([]interface{})), + } + + rules = append(rules, config) + + } + return rules +} + +func flattenEcrReplicationConfigurationReplicationConfigurationRules(ec []*ecr.ReplicationRule) []interface{} { + if len(ec) == 0 { + return nil + } + + var tfList []interface{} + + for _, apiObject := range ec { + tfMap := map[string]interface{}{ + "destination": flattenEcrReplicationConfigurationReplicationConfigurationRulesDestinations(apiObject.Destinations), + } + + tfList = append(tfList, tfMap) + } + + return tfList +} + +func expandEcrReplicationConfigurationReplicationConfigurationRulesDestinations(data []interface{}) []*ecr.ReplicationDestination { + if len(data) == 0 || data[0] == nil { + return nil + } + + var dests []*ecr.ReplicationDestination + + for _, dest := range data { + ec := dest.(map[string]interface{}) + config := &ecr.ReplicationDestination{ + Region: aws.String(ec["region"].(string)), + RegistryId: aws.String(ec["registry_id"].(string)), + } + + dests = append(dests, config) + } + return dests +} + +func flattenEcrReplicationConfigurationReplicationConfigurationRulesDestinations(ec []*ecr.ReplicationDestination) []interface{} { + if len(ec) == 0 { + return nil + } + + var tfList []interface{} + + for _, apiObject := range ec { + tfMap := map[string]interface{}{ + "region": aws.StringValue(apiObject.Region), + "registry_id": aws.StringValue(apiObject.RegistryId), + } + + tfList = append(tfList, tfMap) + } + + return tfList +} diff --git a/aws/resource_aws_ecr_replication_configuration_test.go b/aws/resource_aws_ecr_replication_configuration_test.go new file mode 100644 index 00000000000..e9d6eacabc2 --- /dev/null +++ b/aws/resource_aws_ecr_replication_configuration_test.go @@ -0,0 +1,62 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { + resourceName := "aws_ecr_replication_configuration.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcrReplicationConfiguration(), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcrReplicationConfigurationExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckAWSEcrReplicationConfigurationExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + _, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + return nil + } +} + +func testAccAWSEcrReplicationConfiguration() string { + return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + +data "aws_regions" "test" {} + +resource "aws_ecr_replication_configuration" "test" { + replication_configuration { + rule { + destination { + region = data.aws_regions.test.names[0] + registry_id = data.aws_caller_identity.current.account_id + } + } + } +} +`) +} From 81338d49ca5a70931667b80f036f306203e4bcd8 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 26 Dec 2020 22:09:39 +0200 Subject: [PATCH 02/15] docs --- ...ource_aws_ecr_replication_configuration.go | 1 + ...cr_replication_configuration.html.markdown | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 website/docs/r/ecr_replication_configuration.html.markdown diff --git a/aws/resource_aws_ecr_replication_configuration.go b/aws/resource_aws_ecr_replication_configuration.go index 62f1ef0387d..1b66a39aec6 100644 --- a/aws/resource_aws_ecr_replication_configuration.go +++ b/aws/resource_aws_ecr_replication_configuration.go @@ -33,6 +33,7 @@ func resourceAwsEcrReplicationConfiguration() *schema.Resource { "rule": { Type: schema.TypeList, Required: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "destination": { diff --git a/website/docs/r/ecr_replication_configuration.html.markdown b/website/docs/r/ecr_replication_configuration.html.markdown new file mode 100644 index 00000000000..b4cf63a358d --- /dev/null +++ b/website/docs/r/ecr_replication_configuration.html.markdown @@ -0,0 +1,63 @@ +--- +subcategory: "ECR" +layout: "aws" +page_title: "AWS: aws_ecr_replication_configuration" +description: |- + Provides an Elastic Container Registry Replication Configuration. +--- + +# Resource: aws_ecr_replication configuration + +Provides an Elastic Container Registry Replication Configuration. + +## Example Usage + +```hcl +data "aws_caller_identity" "current" {} + +data "aws_regions" "test" {} + +resource "aws_ecr_replication_configuration" "test" { + replication_configuration { + rule { + destination { + region = data.aws_regions.test.names[0] + registry_id = data.aws_caller_identity.current.account_id + } + } + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `replication_configuration` - (Required) Replication configuration for a registry. See [Replication Configuration](#encryption-configuration). + +### Replication Configuration + +* `rule` - (Required) The replication rules for a replication configuration. See [Rule](#rule). + +### Rule + +* `destination` - (Required) the details of a replication destination. See [Destination](#destination). + +### Destination + +* `region` - (Required) A Region to replicate to. +* `registry_id` - (Required) The account ID of the destination registry to replicate to. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `registry_id` - The registry ID where the replication configuration was created. + +## Import + +ECR Replication Configuration can be imported using the `registry_id`, e.g. + +``` +$ terraform import aws_ecr_replication_configuration.service 012345678912 +``` From 312d823619a4af51dab656f03d8239a51074e884 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 9 Jan 2021 12:37:51 +0200 Subject: [PATCH 03/15] add updated case --- ..._aws_ecr_replication_configuration_test.go | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_ecr_replication_configuration_test.go b/aws/resource_aws_ecr_replication_configuration_test.go index e9d6eacabc2..930d9430137 100644 --- a/aws/resource_aws_ecr_replication_configuration_test.go +++ b/aws/resource_aws_ecr_replication_configuration_test.go @@ -27,6 +27,12 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccAWSEcrReplicationConfigurationUpdated(), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcrReplicationConfigurationExists(resourceName), + ), + }, }, }) } @@ -43,7 +49,26 @@ func testAccCheckAWSEcrReplicationConfigurationExists(name string) resource.Test } func testAccAWSEcrReplicationConfiguration() string { - return fmt.Sprintf(` + return ` +data "aws_caller_identity" "current" {} + +data "aws_regions" "test" {} + +resource "aws_ecr_replication_configuration" "test" { + replication_configuration { + rule { + destination { + region = tolist(data.aws_regions.test.names)[0] + registry_id = data.aws_caller_identity.current.account_id + } + } + } +} +`) +} + +func testAccAWSEcrReplicationConfigurationUpdated() string { + return ` data "aws_caller_identity" "current" {} data "aws_regions" "test" {} @@ -52,7 +77,7 @@ resource "aws_ecr_replication_configuration" "test" { replication_configuration { rule { destination { - region = data.aws_regions.test.names[0] + region = tolist(data.aws_regions.test.names)[1] registry_id = data.aws_caller_identity.current.account_id } } From 195a5a088dfc014c6515e5844b16c127aeb9d380 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 9 Jan 2021 12:44:47 +0200 Subject: [PATCH 04/15] add specific checks --- ...ource_aws_ecr_replication_configuration_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_ecr_replication_configuration_test.go b/aws/resource_aws_ecr_replication_configuration_test.go index 930d9430137..d9e89a06345 100644 --- a/aws/resource_aws_ecr_replication_configuration_test.go +++ b/aws/resource_aws_ecr_replication_configuration_test.go @@ -20,6 +20,11 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { Config: testAccAWSEcrReplicationConfiguration(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcrReplicationConfigurationExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.#", "1"), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "replication_configuration.0.rule.0.destination.0.region"), + testAccCheckResourceAttrAccountID(resourceName, "replication_configuration.0.rule.0.destination.0.registry_id"), ), }, { @@ -31,6 +36,11 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { Config: testAccAWSEcrReplicationConfigurationUpdated(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcrReplicationConfigurationExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.#", "1"), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "replication_configuration.0.rule.0.destination.0.region"), + testAccCheckResourceAttrAccountID(resourceName, "replication_configuration.0.rule.0.destination.0.registry_id"), ), }, }, @@ -64,7 +74,7 @@ resource "aws_ecr_replication_configuration" "test" { } } } -`) +` } func testAccAWSEcrReplicationConfigurationUpdated() string { @@ -83,5 +93,5 @@ resource "aws_ecr_replication_configuration" "test" { } } } -`) +` } From 2f85f78a934ad70cbbbcca255106d7836425ebe1 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Thu, 11 Mar 2021 22:49:39 +0200 Subject: [PATCH 05/15] changelog --- .changelog/11857.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/11857.txt diff --git a/.changelog/11857.txt b/.changelog/11857.txt new file mode 100644 index 00000000000..fc20a35b203 --- /dev/null +++ b/.changelog/11857.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_cloud9_environment_membership +``` From 52dc0dc465351553ee336f77820f1c58b8c0116c Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 27 Mar 2021 19:27:16 +0300 Subject: [PATCH 06/15] error check --- aws/resource_aws_ecr_replication_configuration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws/resource_aws_ecr_replication_configuration_test.go b/aws/resource_aws_ecr_replication_configuration_test.go index d9e89a06345..a13ec224544 100644 --- a/aws/resource_aws_ecr_replication_configuration_test.go +++ b/aws/resource_aws_ecr_replication_configuration_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/aws/aws-sdk-go/service/ecr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) @@ -13,6 +14,7 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, ecr.EndpointsID), Providers: testAccProviders, CheckDestroy: nil, Steps: []resource.TestStep{ From 899298a049966188311c1c636c3e7538e291f6af Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 27 Mar 2021 19:36:27 +0300 Subject: [PATCH 07/15] docs --- website/docs/r/ecr_replication_configuration.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/ecr_replication_configuration.html.markdown b/website/docs/r/ecr_replication_configuration.html.markdown index b4cf63a358d..bab5c5793a0 100644 --- a/website/docs/r/ecr_replication_configuration.html.markdown +++ b/website/docs/r/ecr_replication_configuration.html.markdown @@ -12,7 +12,7 @@ Provides an Elastic Container Registry Replication Configuration. ## Example Usage -```hcl +```terraform data "aws_caller_identity" "current" {} data "aws_regions" "test" {} From 963fdc52eaa1675adc0c7566c2cde48526c9949a Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 27 Mar 2021 19:46:31 +0300 Subject: [PATCH 08/15] fix docs --- website/docs/r/ecr_replication_configuration.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/ecr_replication_configuration.html.markdown b/website/docs/r/ecr_replication_configuration.html.markdown index bab5c5793a0..471e992387d 100644 --- a/website/docs/r/ecr_replication_configuration.html.markdown +++ b/website/docs/r/ecr_replication_configuration.html.markdown @@ -6,7 +6,7 @@ description: |- Provides an Elastic Container Registry Replication Configuration. --- -# Resource: aws_ecr_replication configuration +# Resource: aws_ecr_replication_configuration Provides an Elastic Container Registry Replication Configuration. From da3e14803cb1a5838357720569c90e26c5a96fa0 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sat, 3 Apr 2021 11:35:36 +0300 Subject: [PATCH 09/15] Update website/docs/r/ecr_replication_configuration.html.markdown Co-authored-by: Graham Davison --- website/docs/r/ecr_replication_configuration.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/ecr_replication_configuration.html.markdown b/website/docs/r/ecr_replication_configuration.html.markdown index 471e992387d..9ed6c763453 100644 --- a/website/docs/r/ecr_replication_configuration.html.markdown +++ b/website/docs/r/ecr_replication_configuration.html.markdown @@ -15,13 +15,13 @@ Provides an Elastic Container Registry Replication Configuration. ```terraform data "aws_caller_identity" "current" {} -data "aws_regions" "test" {} +data "aws_regions" "example" {} -resource "aws_ecr_replication_configuration" "test" { +resource "aws_ecr_replication_configuration" "example" { replication_configuration { rule { destination { - region = data.aws_regions.test.names[0] + region = data.aws_regions.example.names[0] registry_id = data.aws_caller_identity.current.account_id } } From e4f0e34111a950a19b350dddb98479aec11f8591 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sat, 3 Apr 2021 11:35:45 +0300 Subject: [PATCH 10/15] Update aws/resource_aws_ecr_replication_configuration.go Co-authored-by: Graham Davison --- aws/resource_aws_ecr_replication_configuration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_ecr_replication_configuration.go b/aws/resource_aws_ecr_replication_configuration.go index 1b66a39aec6..af60f7d2264 100644 --- a/aws/resource_aws_ecr_replication_configuration.go +++ b/aws/resource_aws_ecr_replication_configuration.go @@ -73,7 +73,7 @@ func resourceAwsEcrReplicationConfigurationPut(d *schema.ResourceData, meta inte log.Printf("[DEBUG] Creating ECR Replication Configuration: %#v", input) _, err := conn.PutReplicationConfiguration(&input) if err != nil { - return fmt.Errorf("error creating ECR Replication Configuration: %s", err) + return fmt.Errorf("error creating ECR Replication Configuration: %w", err) } d.SetId(meta.(*AWSClient).accountid) From 66e410473f7fcd91b945cff43b582f85a2466f16 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Sat, 3 Apr 2021 11:35:50 +0300 Subject: [PATCH 11/15] Update .changelog/11857.txt Co-authored-by: Graham Davison --- .changelog/11857.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/11857.txt b/.changelog/11857.txt index fc20a35b203..34a91d2647a 100644 --- a/.changelog/11857.txt +++ b/.changelog/11857.txt @@ -1,3 +1,3 @@ ```release-note:new-resource -aws_cloud9_environment_membership +aws_ecr_replication_configuration ``` From 600e71b0e41f96e1e60e46e61226779a717ae15b Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 3 Apr 2021 11:42:58 +0300 Subject: [PATCH 12/15] add check --- aws/resource_aws_ecr_replication_configuration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws/resource_aws_ecr_replication_configuration_test.go b/aws/resource_aws_ecr_replication_configuration_test.go index a13ec224544..9f43af890bd 100644 --- a/aws/resource_aws_ecr_replication_configuration_test.go +++ b/aws/resource_aws_ecr_replication_configuration_test.go @@ -22,6 +22,7 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { Config: testAccAWSEcrReplicationConfiguration(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcrReplicationConfigurationExists(resourceName), + testAccCheckResourceAttrAccountID(resourceName, "registry_id"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.#", "1"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.#", "1"), @@ -38,6 +39,7 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { Config: testAccAWSEcrReplicationConfigurationUpdated(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcrReplicationConfigurationExists(resourceName), + testAccCheckResourceAttrAccountID(resourceName, "registry_id"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.#", "1"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.#", "1"), From 1c741e56df787c0fa246f257909c54dfaff60b0a Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 3 Apr 2021 11:51:31 +0300 Subject: [PATCH 13/15] changes --- aws/resource_aws_ecr_replication_configuration.go | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/resource_aws_ecr_replication_configuration.go b/aws/resource_aws_ecr_replication_configuration.go index af60f7d2264..625cb2a9ca2 100644 --- a/aws/resource_aws_ecr_replication_configuration.go +++ b/aws/resource_aws_ecr_replication_configuration.go @@ -70,7 +70,6 @@ func resourceAwsEcrReplicationConfigurationPut(d *schema.ResourceData, meta inte ReplicationConfiguration: expandEcrReplicationConfigurationReplicationConfiguration(d.Get("replication_configuration").([]interface{})), } - log.Printf("[DEBUG] Creating ECR Replication Configuration: %#v", input) _, err := conn.PutReplicationConfiguration(&input) if err != nil { return fmt.Errorf("error creating ECR Replication Configuration: %w", err) From d496f869f2098232c90d63672ab1a9d36e8654a0 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 3 Apr 2021 11:52:16 +0300 Subject: [PATCH 14/15] change log --- .changelog/{11857.txt => 16853.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{11857.txt => 16853.txt} (100%) diff --git a/.changelog/11857.txt b/.changelog/16853.txt similarity index 100% rename from .changelog/11857.txt rename to .changelog/16853.txt From ab582cff524dec64ce68336d8ea30d6a7f01b429 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Sat, 3 Apr 2021 12:06:42 +0300 Subject: [PATCH 15/15] use builtin alternate region func --- ..._aws_ecr_replication_configuration_test.go | 45 +++---------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/aws/resource_aws_ecr_replication_configuration_test.go b/aws/resource_aws_ecr_replication_configuration_test.go index 9f43af890bd..37ba7f1a524 100644 --- a/aws/resource_aws_ecr_replication_configuration_test.go +++ b/aws/resource_aws_ecr_replication_configuration_test.go @@ -19,14 +19,14 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccAWSEcrReplicationConfiguration(), + Config: testAccAWSEcrReplicationConfiguration(testAccGetAlternateRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcrReplicationConfigurationExists(resourceName), testAccCheckResourceAttrAccountID(resourceName, "registry_id"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.#", "1"), resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "replication_configuration.0.rule.0.destination.0.region"), + resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.0.region", testAccGetAlternateRegion()), testAccCheckResourceAttrAccountID(resourceName, "replication_configuration.0.rule.0.destination.0.registry_id"), ), }, @@ -35,18 +35,6 @@ func TestAccAWSEcrReplicationConfiguration_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - { - Config: testAccAWSEcrReplicationConfigurationUpdated(), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSEcrReplicationConfigurationExists(resourceName), - testAccCheckResourceAttrAccountID(resourceName, "registry_id"), - resource.TestCheckResourceAttr(resourceName, "replication_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "replication_configuration.0.rule.0.destination.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "replication_configuration.0.rule.0.destination.0.region"), - testAccCheckResourceAttrAccountID(resourceName, "replication_configuration.0.rule.0.destination.0.registry_id"), - ), - }, }, }) } @@ -62,40 +50,19 @@ func testAccCheckAWSEcrReplicationConfigurationExists(name string) resource.Test } } -func testAccAWSEcrReplicationConfiguration() string { - return ` +func testAccAWSEcrReplicationConfiguration(region string) string { + return fmt.Sprintf(` data "aws_caller_identity" "current" {} -data "aws_regions" "test" {} - -resource "aws_ecr_replication_configuration" "test" { - replication_configuration { - rule { - destination { - region = tolist(data.aws_regions.test.names)[0] - registry_id = data.aws_caller_identity.current.account_id - } - } - } -} -` -} - -func testAccAWSEcrReplicationConfigurationUpdated() string { - return ` -data "aws_caller_identity" "current" {} - -data "aws_regions" "test" {} - resource "aws_ecr_replication_configuration" "test" { replication_configuration { rule { destination { - region = tolist(data.aws_regions.test.names)[1] + region = %[1]q registry_id = data.aws_caller_identity.current.account_id } } } } -` +`, region) }