Skip to content

Commit

Permalink
Merge pull request #38002 from nikhil-goenka/f/aws_elasticache_replic…
Browse files Browse the repository at this point in the history
…ation_group

aws_elasticache_replication_group
  • Loading branch information
ewbankkit committed Jul 17, 2024
2 parents a8c5397 + f19f9f8 commit 3e8a2a2
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changelog/38002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_elasticache_replication_group: Add `cluster_mode` argument
```

```release-note:enhancement
data-source/aws_elasticache_replication_group: Add `cluster_mode` attribute
```
16 changes: 16 additions & 0 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func resourceReplicationGroup() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"cluster_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateDiagFunc: enum.Validate[awstypes.ClusterMode](),
},
"configuration_endpoint_address": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -422,6 +428,10 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData,
}
}

if v, ok := d.GetOk("cluster_mode"); ok {
input.ClusterMode = awstypes.ClusterMode(v.(string))
}

if v, ok := d.GetOk("data_tiering_enabled"); ok {
input.DataTieringEnabled = aws.Bool(v.(bool))
}
Expand Down Expand Up @@ -651,6 +661,7 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m
d.Set("replicas_per_node_group", len(rgp.NodeGroups[0].NodeGroupMembers)-1)

d.Set("cluster_enabled", rgp.ClusterEnabled)
d.Set("cluster_mode", rgp.ClusterMode)
d.Set("replication_group_id", rgp.ReplicationGroupId)
d.Set(names.AttrARN, rgp.ARN)
d.Set("data_tiering_enabled", rgp.DataTiering == awstypes.DataTieringStatusEnabled)
Expand Down Expand Up @@ -774,6 +785,11 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData,
requestUpdate = true
}

if d.HasChange("cluster_mode") {
input.ClusterMode = awstypes.ClusterMode(d.Get("cluster_mode").(string))
requestUpdate = true
}

if d.HasChange(names.AttrEngineVersion) {
input.EngineVersion = aws.String(d.Get(names.AttrEngineVersion).(string))
requestUpdate = true
Expand Down
9 changes: 6 additions & 3 deletions internal/service/elasticache/replication_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func dataSourceReplicationGroup() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"cluster_mode": {
Type: schema.TypeString,
Computed: true,
},
"configuration_endpoint_address": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -125,9 +129,7 @@ func dataSourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData,
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx)

groupID := d.Get("replication_group_id").(string)

rg, err := findReplicationGroupByID(ctx, conn, groupID)
rg, err := findReplicationGroupByID(ctx, conn, d.Get("replication_group_id").(string))

if err != nil {
return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("ElastiCache Replication Group", err))
Expand Down Expand Up @@ -174,6 +176,7 @@ func dataSourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData,
d.Set("node_type", rg.CacheNodeType)
d.Set("num_node_groups", len(rg.NodeGroups))
d.Set("replicas_per_node_group", len(rg.NodeGroups[0].NodeGroupMembers)-1)
d.Set("cluster_mode", rg.ClusterMode)
d.Set("log_delivery_configuration", flattenLogDeliveryConfigurations(rg.LogDeliveryConfigurations))
d.Set("snapshot_window", rg.SnapshotWindow)
d.Set("snapshot_retention_limit", rg.SnapshotRetentionLimit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestAccElastiCacheReplicationGroupDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "auth_token_enabled", acctest.CtFalse),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(dataSourceName, "automatic_failover_enabled", resourceName, "automatic_failover_enabled"),
resource.TestCheckResourceAttrPair(dataSourceName, "cluster_mode", resourceName, "cluster_mode"),
resource.TestCheckResourceAttrPair(dataSourceName, "multi_az_enabled", resourceName, "multi_az_enabled"),
resource.TestCheckResourceAttrPair(dataSourceName, "member_clusters.#", resourceName, "member_clusters.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "node_type", resourceName, "node_type"),
Expand Down
80 changes: 80 additions & 0 deletions internal/service/elasticache/replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,62 @@ func TestAccElastiCacheReplicationGroup_ClusterMode_singleNode(t *testing.T) {
})
}

func TestAccElastiCacheReplicationGroup_ClusterMode_updateFromDisabled_Compatible_Enabled(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var rg awstypes.ReplicationGroup
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_elasticache_replication_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.ElastiCacheServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckReplicationGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccReplicationGroup_ClusterMode_updateFromDisabled_Compatible_Enabled(rName, "disabled", false),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckReplicationGroupExists(ctx, resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "cluster_mode", "disabled"),
resource.TestCheckResourceAttr(resourceName, "num_node_groups", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "replicas_per_node_group", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "num_cache_clusters", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "member_clusters.#", acctest.Ct2),
),
},
{
Config: testAccReplicationGroup_ClusterMode_updateFromDisabled_Compatible_Enabled(rName, "compatible", true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckReplicationGroupExists(ctx, resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "cluster_mode", "compatible"),
resource.TestCheckResourceAttr(resourceName, "num_node_groups", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "replicas_per_node_group", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "num_cache_clusters", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "member_clusters.#", acctest.Ct2),
),
},
{
Config: testAccReplicationGroup_ClusterMode_updateFromDisabled_Compatible_Enabled(rName, names.AttrEnabled, true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckReplicationGroupExists(ctx, resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "cluster_mode", names.AttrEnabled),
resource.TestCheckResourceAttr(resourceName, "num_node_groups", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "replicas_per_node_group", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "num_cache_clusters", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "member_clusters.#", acctest.Ct2),
),
},
},
})
}

func TestAccElastiCacheReplicationGroup_clusteringAndCacheNodesCausesError(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -3552,6 +3608,30 @@ resource "aws_elasticache_replication_group" "test" {
)
}

func testAccReplicationGroup_ClusterMode_updateFromDisabled_Compatible_Enabled(rName, clusterMode string, enableClusterMode bool) string {
return acctest.ConfigCompose(
acctest.ConfigAvailableAZsNoOptIn(),
fmt.Sprintf(`
resource "aws_elasticache_replication_group" "test" {
replication_group_id = %[1]q
description = "test description"
node_type = "cache.t2.medium"
apply_immediately = true
automatic_failover_enabled = true
cluster_mode = %[2]q
engine_version = "7.1"
parameter_group_name = tobool("%[3]t") ? "default.redis7.cluster.on" : "default.redis7"
num_node_groups = 1
replicas_per_node_group = 1
timeouts {
create = "60m"
update = "60m"
}
}
`, rName, clusterMode, enableClusterMode),
)
}

func testAccReplicationGroupConfig_useCMKKMSKeyID(rName string) string {
return acctest.ConfigCompose(
acctest.ConfigVPCWithSubnets(rName, 1),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/elasticache_replication_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This data source exports the following attributes in addition to the arguments a
* `arn` - ARN of the created ElastiCache Replication Group.
* `auth_token_enabled` - Whether an AuthToken (password) is enabled.
* `automatic_failover_enabled` - A flag whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails.
* `cluster_mode` - Whether cluster mode is enabled or disabled.
* `node_type` – The cluster node type.
* `num_cache_clusters` – The number of cache clusters that the replication group has.
* `num_node_groups` - Number of node groups (shards) for the replication group.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/elasticache_replication_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ The following arguments are optional:
Only supported for engine type `"redis"` and if the engine version is 6 or higher.
Defaults to `true`.
* `automatic_failover_enabled` - (Optional) Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If enabled, `num_cache_clusters` must be greater than 1. Must be enabled for Redis (cluster mode enabled) replication groups. Defaults to `false`.
* `cluster_mode` - (Optional) Specifies whether cluster mode is enabled or disabled. Valid values are `enabled` or `disabled` or `compatible`
* `data_tiering_enabled` - (Optional) Enables data tiering. Data tiering is only supported for replication groups using the r6gd node type. This parameter must be set to `true` when using r6gd nodes.
* `engine` - (Optional) Name of the cache engine to be used for the clusters in this replication group. The only valid value is `redis`.
* `engine_version` - (Optional) Version number of the cache engine to be used for the cache clusters in this replication group.
Expand Down

0 comments on commit 3e8a2a2

Please sign in to comment.