Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding ip_discovery and network_type for elasticache replication group #28306

3 changes: 3 additions & 0 deletions .changelog/28306.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 in support of [IPv6 clusters](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/network-type.html)
jms200 marked this conversation as resolved.
Show resolved Hide resolved
```
34 changes: 34 additions & 0 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,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 @@ -210,6 +216,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 @@ -461,6 +474,14 @@ func resourceReplicationGroupCreate(d *schema.ResourceData, meta interface{}) er
params.CacheParameterGroupName = aws.String(v.(string))
}

if v, ok := d.GetOk("ip_discovery"); ok {
req.IpDiscovery = aws.String(v.(string))
jms200 marked this conversation as resolved.
Show resolved Hide resolved
}

if v, ok := d.GetOk("network_type"); ok {
req.NetworkType = aws.String(v.(string))
jms200 marked this conversation as resolved.
Show resolved Hide resolved
}

if v, ok := d.GetOk("port"); ok {
params.Port = aws.Int64(int64(v.(int)))
}
Expand Down Expand Up @@ -677,6 +698,9 @@ func resourceReplicationGroupRead(d *schema.ResourceData, meta interface{}) erro
d.Set("arn", rgp.ARN)
d.Set("data_tiering_enabled", aws.StringValue(rgp.DataTiering) == elasticache.DataTieringStatusEnabled)

jms200 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -816,6 +840,16 @@ func resourceReplicationGroupUpdate(d *schema.ResourceData, meta interface{}) er
requestUpdate = true
}

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

if d.HasChange("network_type") {
req.IpDiscovery = aws.String(d.Get("network_type").(string))
jms200 marked this conversation as resolved.
Show resolved Hide resolved
requestUpdate = true
}

if d.HasChange("automatic_failover_enabled") {
params.AutomaticFailoverEnabled = aws.Bool(d.Get("automatic_failover_enabled").(bool))
requestUpdate = true
Expand Down
96 changes: 96 additions & 0 deletions internal/service/elasticache/replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,102 @@ func TestAccElastiCacheReplicationGroup_basic(t *testing.T) {
})
}

func TestAccElastiCacheReplicationGroup_network_type_ipv6(t *testing.T) {
jms200 marked this conversation as resolved.
Show resolved Hide resolved
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, elasticache.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckReplicationGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccReplicationGroupConfig_basic(rName),
jms200 marked this conversation as resolved.
Show resolved Hide resolved
Check: resource.ComposeAggregateTestCheckFunc(
jms200 marked this conversation as resolved.
Show resolved Hide resolved
testAccCheckReplicationGroupExists(resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "engine", "redis"),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "elasticache", fmt.Sprintf("replicationgroup:%s", rName)),
resource.TestCheckResourceAttr(resourceName, "number_cache_clusters", "1"),
resource.TestCheckResourceAttr(resourceName, "multi_az_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "automatic_failover_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "member_clusters.#", "1"),
resource.TestCheckResourceAttr(resourceName, "parameter_group_name", "default.redis6.x"),
resource.TestCheckResourceAttr(resourceName, "cluster_mode.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cluster_mode.0.num_node_groups", "1"),
resource.TestCheckResourceAttr(resourceName, "cluster_mode.0.replicas_per_node_group", "0"),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "6.2"),
resource.TestMatchResourceAttr(resourceName, "engine_version_actual", regexp.MustCompile(`^6\.[[:digit:]]+\.[[:digit:]]+$`)),
resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "true"),
resource.TestCheckResourceAttr(resourceName, "data_tiering_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "ip_discovery", "ipv6"),
resource.TestCheckResourceAttr(resourceName, "network_type", "ipv6"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately"}, //not in the API
},
},
})
}

func TestAccElastiCacheReplicationGroup_network_type_dual_stack(t *testing.T) {
jms200 marked this conversation as resolved.
Show resolved Hide resolved
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, elasticache.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckReplicationGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccReplicationGroupConfig_basic(rName),
jms200 marked this conversation as resolved.
Show resolved Hide resolved
Check: resource.ComposeAggregateTestCheckFunc(
jms200 marked this conversation as resolved.
Show resolved Hide resolved
testAccCheckReplicationGroupExists(resourceName, &rg),
resource.TestCheckResourceAttr(resourceName, "engine", "redis"),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "elasticache", fmt.Sprintf("replicationgroup:%s", rName)),
resource.TestCheckResourceAttr(resourceName, "number_cache_clusters", "1"),
resource.TestCheckResourceAttr(resourceName, "multi_az_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "automatic_failover_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "member_clusters.#", "1"),
resource.TestCheckResourceAttr(resourceName, "parameter_group_name", "default.redis6.x"),
resource.TestCheckResourceAttr(resourceName, "cluster_mode.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cluster_mode.0.num_node_groups", "1"),
resource.TestCheckResourceAttr(resourceName, "cluster_mode.0.replicas_per_node_group", "0"),
resource.TestCheckResourceAttr(resourceName, "cluster_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "6.2"),
resource.TestMatchResourceAttr(resourceName, "engine_version_actual", regexp.MustCompile(`^6\.[[:digit:]]+\.[[:digit:]]+$`)),
resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "true"),
resource.TestCheckResourceAttr(resourceName, "data_tiering_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "ip_discovery", "ipv6"),
resource.TestCheckResourceAttr(resourceName, "network_type", "dual_stack"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately"}, //not in the API
},
},
})
}

func TestAccElastiCacheReplicationGroup_basic_v5(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
Expand Down
2 changes: 2 additions & 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,8 @@ In addition to all arguments above, the following attributes are exported:
* `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.
* `ip_discovery` - The IP version advertised in the discovery protocol.
jms200 marked this conversation as resolved.
Show resolved Hide resolved
* `network_type` - The IP versions for cache cluster connections.
* `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
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 @@ -190,10 +190,12 @@ The following arguments are optional:
The actual engine version used is returned in the attribute `engine_version_actual`, see [Attributes Reference](#attributes-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 (or the `num_node_groups` parameter of the deprecated `cluster_mode` block) 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. IPv6 is supported with Redis engine `6.2` onword or Memcached version `1.6.6` for all [Nitro system](https://aws.amazon.com/ec2/nitro/) instances. Valid values are `ipv4`, `ipv6` or `dual_stack`.
jms200 marked this conversation as resolved.
Show resolved Hide resolved
* `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`
* `number_cache_clusters` - (Optional, **Deprecated** use `num_cache_clusters` instead) 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_cache_clusters`, `num_node_groups`, or the deprecated `cluster_mode`. Defaults to `1`.
Expand Down