Skip to content

Commit

Permalink
Merge pull request #34019 from bschaatsbergen/add-elasticache-args-fo…
Browse files Browse the repository at this point in the history
…r-replication-group

feat: add `network_type` and `ip_discovery` to ElastiCache replication group
  • Loading branch information
ewbankkit authored Oct 20, 2023
2 parents 6238200 + 0b791e0 commit 9b2d692
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/34019.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_elasticache_replication_group: Add `ip_discovery` and `network_type` arguments
```
34 changes: 34 additions & 0 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ func ResourceReplicationGroup() *schema.Resource {
"snapshot_name",
},
},
"ip_discovery": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(elasticache.IpDiscovery_Values(), false),
},
"log_delivery_configuration": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -183,6 +189,13 @@ func ResourceReplicationGroup() *schema.Resource {
Optional: true,
Default: false,
},
"network_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(elasticache.NetworkType_Values(), false),
},
"node_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -405,6 +418,14 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData,
input.CacheParameterGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("ip_discovery"); ok {
input.IpDiscovery = aws.String(v.(string))
}

if v, ok := d.GetOk("network_type"); ok {
input.NetworkType = aws.String(v.(string))
}

if v, ok := d.GetOk("port"); ok {
input.Port = aws.Int64(int64(v.(int)))
}
Expand Down Expand Up @@ -597,6 +618,9 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m
d.Set("arn", rgp.ARN)
d.Set("data_tiering_enabled", aws.StringValue(rgp.DataTiering) == elasticache.DataTieringStatusEnabled)

d.Set("ip_discovery", rgp.IpDiscovery)
d.Set("network_type", rgp.NetworkType)

d.Set("log_delivery_configuration", flattenLogDeliveryConfigurations(rgp.LogDeliveryConfigurations))
d.Set("snapshot_window", rgp.SnapshotWindow)
d.Set("snapshot_retention_limit", rgp.SnapshotRetentionLimit)
Expand Down Expand Up @@ -694,6 +718,16 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData,
requestUpdate = true
}

if d.HasChange("ip_discovery") {
input.IpDiscovery = aws.String(d.Get("ip_discovery").(string))
requestUpdate = true
}

if d.HasChange("network_type") {
input.IpDiscovery = aws.String(d.Get("network_type").(string))
requestUpdate = true
}

if d.HasChange("automatic_failover_enabled") {
input.AutomaticFailoverEnabled = aws.Bool(d.Get("automatic_failover_enabled").(bool))
requestUpdate = true
Expand Down
163 changes: 163 additions & 0 deletions internal/service/elasticache/replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,89 @@ func TestAccElastiCacheReplicationGroup_ValidationMultiAz_noAutomaticFailover(t
})
}

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

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, elasticache.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckReplicationGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccReplicationGroupConfig_ipDiscovery(rName, "ipv6"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckReplicationGroupExists(ctx, resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "port", "6379"),
resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t3.small"),
resource.TestCheckResourceAttr(resourceName, "num_node_groups", "2"),
resource.TestCheckResourceAttr(resourceName, "replicas_per_node_group", "1"),
resource.TestCheckResourceAttr(resourceName, "num_cache_clusters", "4"),
resource.TestCheckResourceAttr(resourceName, "parameter_group_name", "default.redis7.cluster.on"),
resource.TestCheckResourceAttr(resourceName, "automatic_failover_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "ip_discovery", "ipv6"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately", "preferred_cache_cluster_azs"},
},
},
})
}

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

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, elasticache.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckReplicationGroupDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccReplicationGroupConfig_networkType(rName, "ipv6", "dual_stack"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckReplicationGroupExists(ctx, resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "port", "6379"),
resource.TestCheckResourceAttr(resourceName, "node_type", "cache.t3.small"),
resource.TestCheckResourceAttr(resourceName, "num_node_groups", "2"),
resource.TestCheckResourceAttr(resourceName, "replicas_per_node_group", "1"),
resource.TestCheckResourceAttr(resourceName, "num_cache_clusters", "4"),
resource.TestCheckResourceAttr(resourceName, "parameter_group_name", "default.redis7.cluster.on"),
resource.TestCheckResourceAttr(resourceName, "automatic_failover_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "ip_discovery", "ipv6"),
resource.TestCheckResourceAttr(resourceName, "network_type", "dual_stack"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately", "preferred_cache_cluster_azs"},
},
},
})
}

func TestAccElastiCacheReplicationGroup_ClusterMode_basic(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -3021,6 +3104,86 @@ resource "aws_security_group" "test" {
)
}

func testAccReplicationGroupConfig_ipDiscovery(rName, ipDiscovery string) string {
return acctest.ConfigCompose(
acctest.ConfigVPCWithSubnetsIPv6(rName, 2),
fmt.Sprintf(`
resource "aws_elasticache_replication_group" "test" {
replication_group_id = %[1]q
description = "test description"
node_type = "cache.t3.small"
num_node_groups = 2
replicas_per_node_group = 1
port = 6379
parameter_group_name = "default.redis7.cluster.on"
automatic_failover_enabled = true
subnet_group_name = aws_elasticache_subnet_group.test.name
ip_discovery = %[2]q
network_type = "dual_stack"
security_group_ids = [aws_security_group.test.id]
}
resource "aws_elasticache_subnet_group" "test" {
name = %[1]q
subnet_ids = aws_subnet.test[*].id
}
resource "aws_security_group" "test" {
name = %[1]q
description = "tf-test-security-group-descr"
vpc_id = aws_vpc.test.id
ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
}
`, rName, ipDiscovery),
)
}

func testAccReplicationGroupConfig_networkType(rName, ipDiscovery, networkType string) string {
return acctest.ConfigCompose(
acctest.ConfigVPCWithSubnetsIPv6(rName, 2),
fmt.Sprintf(`
resource "aws_elasticache_replication_group" "test" {
replication_group_id = %[1]q
description = "test description"
node_type = "cache.t3.small"
num_node_groups = 2
replicas_per_node_group = 1
port = 6379
parameter_group_name = "default.redis7.cluster.on"
automatic_failover_enabled = true
subnet_group_name = aws_elasticache_subnet_group.test.name
ip_discovery = %[2]q
network_type = %[3]q
security_group_ids = [aws_security_group.test.id]
}
resource "aws_elasticache_subnet_group" "test" {
name = %[1]q
subnet_ids = aws_subnet.test[*].id
}
resource "aws_security_group" "test" {
name = %[1]q
description = "tf-test-security-group-descr"
vpc_id = aws_vpc.test.id
ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
}
`, rName, ipDiscovery, networkType),
)
}

func testAccReplicationGroupConfig_multiAZNoAutomaticFailover(rName string) string {
return fmt.Sprintf(`
resource "aws_elasticache_replication_group" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/elasticache_replication_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ The following arguments are optional:
The actual engine version used is returned in the attribute `engine_version_actual`, see [Attribute Reference](#attribute-reference) below.
* `final_snapshot_identifier` - (Optional) The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made.
* `global_replication_group_id` - (Optional) The ID of the global replication group to which this replication group should belong. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group; otherwise, the replication group is not part of any global replication group. If `global_replication_group_id` is set, the `num_node_groups` parameter cannot be set.
* `ip_discovery` - (Optional) The IP version to advertise in the discovery protocol. Valid values are `ipv4` or `ipv6`.
* `kms_key_id` - (Optional) The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true`.
* `log_delivery_configuration` - (Optional, Redis only) Specifies the destination and format of Redis [SLOWLOG](https://redis.io/commands/slowlog) or Redis [Engine Log](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Log_Delivery.html#Log_contents-engine-log). See the documentation on [Amazon ElastiCache](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Log_Delivery.html#Log_contents-engine-log). See [Log Delivery Configuration](#log-delivery-configuration) below for more details.
* `maintenance_window` – (Optional) Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is `ddd:hh24:mi-ddd:hh24:mi` (24H Clock UTC). The minimum maintenance window is a 60 minute period. Example: `sun:05:00-sun:09:00`
* `multi_az_enabled` - (Optional) Specifies whether to enable Multi-AZ Support for the replication group. If `true`, `automatic_failover_enabled` must also be enabled. Defaults to `false`.
* `network_type` - (Optional) The IP versions for cache cluster connections. Valid values are `ipv4`, `ipv6` or `dual_stack`.
* `node_type` - (Optional) Instance class to be used. See AWS documentation for information on [supported node types](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/CacheNodes.SupportedTypes.html) and [guidance on selecting node types](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/nodes-select-size.html). Required unless `global_replication_group_id` is set. Cannot be set if `global_replication_group_id` is set.
* `notification_topic_arn` – (Optional) ARN of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic`
* `num_cache_clusters` - (Optional) Number of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications. Conflicts with `num_node_groups`. Defaults to `1`.
Expand Down

0 comments on commit 9b2d692

Please sign in to comment.