From 820f72d86a3f6b8b09af6affad8f1df48a1443b2 Mon Sep 17 00:00:00 2001 From: Angel Abad Date: Thu, 24 Sep 2020 17:39:04 +0200 Subject: [PATCH 1/2] resource_aws_elasticache_replication_group: Add arn attribute --- aws/resource_aws_elasticache_replication_group.go | 14 ++++++++++++++ website/docs/r/elasticache_cluster.html.markdown | 2 +- .../r/elasticache_replication_group.html.markdown | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_elasticache_replication_group.go b/aws/resource_aws_elasticache_replication_group.go index a72737d5e3cc..5d3732fc113a 100644 --- a/aws/resource_aws_elasticache_replication_group.go +++ b/aws/resource_aws_elasticache_replication_group.go @@ -34,6 +34,10 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { Optional: true, Computed: true, }, + "arn": { + Type: schema.TypeString, + Computed: true, + }, "at_rest_encryption_enabled": { Type: schema.TypeBool, Optional: true, @@ -521,6 +525,16 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int } } + arn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "elasticache", + Region: meta.(*AWSClient).region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("replicationgroup:%s", d.Id()), + }.String() + + d.Set("arn", arn) + return nil } diff --git a/website/docs/r/elasticache_cluster.html.markdown b/website/docs/r/elasticache_cluster.html.markdown index f68a2d5c79b3..cb1e8810f0e5 100644 --- a/website/docs/r/elasticache_cluster.html.markdown +++ b/website/docs/r/elasticache_cluster.html.markdown @@ -138,9 +138,9 @@ SNS topic to send ElastiCache notifications to. Example: In addition to all arguments above, the following attributes are exported: +* `arn` - The ARN of the created ElastiCache Cluster. * `cache_nodes` - List of node objects including `id`, `address`, `port` and `availability_zone`. Referenceable e.g. as `${aws_elasticache_cluster.bar.cache_nodes.0.address}` - * `configuration_endpoint` - (Memcached only) The configuration endpoint to allow host discovery. * `cluster_address` - (Memcached only) The DNS name of the cache cluster without the port appended. diff --git a/website/docs/r/elasticache_replication_group.html.markdown b/website/docs/r/elasticache_replication_group.html.markdown index b1ff694a7920..5a8b83cd5414 100644 --- a/website/docs/r/elasticache_replication_group.html.markdown +++ b/website/docs/r/elasticache_replication_group.html.markdown @@ -146,6 +146,7 @@ Cluster Mode (`cluster_mode`) supports the following: In addition to all arguments above, the following attributes are exported: +* `arn` - The ARN of the created ElastiCache Replication Group. * `id` - The ID of the ElastiCache Replication Group. * `configuration_endpoint_address` - The address of the replication group configuration endpoint when cluster mode is enabled. * `primary_endpoint_address` - (Redis only) The address of the endpoint for the primary node in the replication group, if the cluster mode is disabled. From 506c306798feb8166957aa5e2d8fd6aafefb4b83 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Fri, 15 Jan 2021 15:52:10 -0800 Subject: [PATCH 2/2] Uses actual ARN API parameter and adds attribute to data source --- aws/data_source_aws_elasticache_replication_group.go | 5 +++++ ...a_source_aws_elasticache_replication_group_test.go | 1 + aws/resource_aws_elasticache_replication_group.go | 11 +---------- ...resource_aws_elasticache_replication_group_test.go | 1 + .../d/elasticache_replication_group.html.markdown | 2 +- .../r/elasticache_replication_group.html.markdown | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/aws/data_source_aws_elasticache_replication_group.go b/aws/data_source_aws_elasticache_replication_group.go index 2cc8a21a47e3..1880a52ad6e2 100644 --- a/aws/data_source_aws_elasticache_replication_group.go +++ b/aws/data_source_aws_elasticache_replication_group.go @@ -21,6 +21,10 @@ func dataSourceAwsElasticacheReplicationGroup() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "arn": { + Type: schema.TypeString, + Computed: true, + }, "auth_token_enabled": { Type: schema.TypeBool, Computed: true, @@ -95,6 +99,7 @@ func dataSourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta i d.SetId(aws.StringValue(rg.ReplicationGroupId)) d.Set("replication_group_description", rg.Description) + d.Set("arn", rg.ARN) d.Set("auth_token_enabled", rg.AuthTokenEnabled) if rg.AutomaticFailover != nil { switch aws.StringValue(rg.AutomaticFailover) { diff --git a/aws/data_source_aws_elasticache_replication_group_test.go b/aws/data_source_aws_elasticache_replication_group_test.go index 5e04cb7d75b1..5a4726745d51 100644 --- a/aws/data_source_aws_elasticache_replication_group_test.go +++ b/aws/data_source_aws_elasticache_replication_group_test.go @@ -22,6 +22,7 @@ func TestAccDataSourceAwsElasticacheReplicationGroup_basic(t *testing.T) { Config: testAccDataSourceAwsElasticacheReplicationGroupConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "auth_token_enabled", "false"), + resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), resource.TestCheckResourceAttrPair(dataSourceName, "automatic_failover_enabled", resourceName, "automatic_failover_enabled"), resource.TestCheckResourceAttrPair(dataSourceName, "member_clusters.#", resourceName, "member_clusters.#"), resource.TestCheckResourceAttrPair(dataSourceName, "node_type", resourceName, "node_type"), diff --git a/aws/resource_aws_elasticache_replication_group.go b/aws/resource_aws_elasticache_replication_group.go index b6d6137feaf8..4ec2da537c4b 100644 --- a/aws/resource_aws_elasticache_replication_group.go +++ b/aws/resource_aws_elasticache_replication_group.go @@ -462,6 +462,7 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int } d.Set("cluster_enabled", rgp.ClusterEnabled) d.Set("replication_group_id", rgp.ReplicationGroupId) + d.Set("arn", rgp.ARN) if rgp.NodeGroups != nil { if len(rgp.NodeGroups[0].NodeGroupMembers) == 0 { @@ -534,16 +535,6 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int } } - arn := arn.ARN{ - Partition: meta.(*AWSClient).partition, - Service: "elasticache", - Region: meta.(*AWSClient).region, - AccountID: meta.(*AWSClient).accountid, - Resource: fmt.Sprintf("replicationgroup:%s", d.Id()), - }.String() - - d.Set("arn", arn) - return nil } diff --git a/aws/resource_aws_elasticache_replication_group_test.go b/aws/resource_aws_elasticache_replication_group_test.go index 4d710f0a5fad..59d623616e22 100644 --- a/aws/resource_aws_elasticache_replication_group_test.go +++ b/aws/resource_aws_elasticache_replication_group_test.go @@ -71,6 +71,7 @@ func TestAccAWSElasticacheReplicationGroup_basic(t *testing.T) { Config: testAccAWSElasticacheReplicationGroupConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSElasticacheReplicationGroupExists(resourceName, &rg), + testAccCheckResourceAttrRegionalARN(resourceName, "arn", "elasticache", fmt.Sprintf("replicationgroup:%s", rName)), resource.TestCheckResourceAttr(resourceName, "number_cache_clusters", "2"), resource.TestCheckResourceAttr(resourceName, "member_clusters.#", "2"), resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"), diff --git a/website/docs/d/elasticache_replication_group.html.markdown b/website/docs/d/elasticache_replication_group.html.markdown index 85edc90efb83..f820b2511b05 100644 --- a/website/docs/d/elasticache_replication_group.html.markdown +++ b/website/docs/d/elasticache_replication_group.html.markdown @@ -28,8 +28,8 @@ The following arguments are supported: In addition to all arguments above, the following attributes are exported: -* `replication_group_id` - The identifier for the replication group. * `replication_group_description` - The description of the replication group. +* `arn` - The Amazon Resource Name (ARN) of the created ElastiCache Replication Group. * `auth_token_enabled` - A flag that enables using an AuthToken (password) when issuing Redis commands. * `automatic_failover_enabled` - A flag whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. * `node_type` – The cluster node type. diff --git a/website/docs/r/elasticache_replication_group.html.markdown b/website/docs/r/elasticache_replication_group.html.markdown index c80fcd4771c7..9aa04cf0c142 100644 --- a/website/docs/r/elasticache_replication_group.html.markdown +++ b/website/docs/r/elasticache_replication_group.html.markdown @@ -149,7 +149,7 @@ Cluster Mode (`cluster_mode`) supports the following: In addition to all arguments above, the following attributes are exported: -* `arn` - The ARN of the created ElastiCache Replication Group. +* `arn` - The Amazon Resource Name (ARN) of the created ElastiCache Replication Group. * `id` - The ID of the ElastiCache Replication Group. * `cluster_enabled` - Indicates if cluster mode is enabled. * `configuration_endpoint_address` - The address of the replication group configuration endpoint when cluster mode is enabled.