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

Add elasticache ip discovery #27856

Merged
merged 17 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/service/elasticache/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ func ResourceCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"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 @@ -422,6 +428,10 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error {
req.PreferredAvailabilityZones = flex.ExpandStringList(v.([]interface{}))
}

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

id, arn, err := createCacheCluster(conn, req)
if err != nil {
return fmt.Errorf("error creating ElastiCache Cache Cluster: %w", err)
Expand Down Expand Up @@ -508,6 +518,8 @@ func resourceClusterRead(d *schema.ResourceData, meta interface{}) error {

d.Set("arn", c.ARN)

d.Set("ip_discovery", c.IpDiscovery)

tags, err := ListTags(conn, aws.StringValue(c.ARN))

if err != nil && !verify.ErrorISOUnsupported(conn.PartitionID, err) {
Expand Down Expand Up @@ -585,6 +597,11 @@ func resourceClusterUpdate(d *schema.ResourceData, meta interface{}) error {
requestUpdate = true
}

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

if d.HasChange("log_delivery_configuration") {
oldLogDeliveryConfig, newLogDeliveryConfig := d.GetChange("log_delivery_configuration")

Expand Down
60 changes: 60 additions & 0 deletions internal/service/elasticache/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,53 @@ func TestAccElastiCacheCluster_ParameterGroupName_default(t *testing.T) {
})
}

func TestAccElastiCacheCluster_IpDiscovery(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var ec elasticache.CacheCluster
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_elasticache_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, elasticache.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccClusterConfig_ipDiscovery(rName, "memcached", "1.6.6", "ipv4"),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(resourceName, &ec),
resource.TestCheckResourceAttr(resourceName, "engine", "memcached"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "1.6.6"),
resource.TestCheckResourceAttr(resourceName, "engine_version_actual", "1.6.6"),
resource.TestCheckResourceAttr(resourceName, "ip_discovery", "ipv4"),
),
},
{
Config: testAccClusterConfig_ipDiscovery(rName, "memcached", "1.6.6", "ipv6"),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(resourceName, &ec),
resource.TestCheckResourceAttr(resourceName, "engine", "memcached"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "1.6.6"),
resource.TestCheckResourceAttr(resourceName, "engine_version_actual", "1.6.6"),
resource.TestCheckResourceAttr(resourceName, "ip_discovery", "ipv6"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
},
},
},
})
}

func TestAccElastiCacheCluster_port(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
Expand Down Expand Up @@ -1305,6 +1352,19 @@ resource "aws_elasticache_cluster" "test" {
`, rName, engine, engineVersion, parameterGroupName)
}

func testAccClusterConfig_ipDiscovery(rName, engine, engineVersion, ipDiscovery string) string {
return fmt.Sprintf(`
resource "aws_elasticache_cluster" "test" {
cluster_id = %q
engine = %q
engine_version = %q
node_type = "cache.t3.small"
num_cache_nodes = 1
ip_discovery = %q
}
`, rName, engine, engineVersion, ipDiscovery)
}

func testAccClusterConfig_port(rName string, port int) string {
return fmt.Sprintf(`
resource "aws_elasticache_cluster" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/elasticache_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ The following arguments are optional:
Otherwise, specify the full version desired, e.g., `5.0.6`.
The actual engine version used is returned in the attribute `engine_version_actual`, see [Attributes Reference](#attributes-reference) below.
* `final_snapshot_identifier` - (Optional, Redis only) Name of your final cluster snapshot. If omitted, no final snapshot will be made.
* `ip_discovery` - (Optional) The network type for the cache cluster. 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` or `ipv6`.
* `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). 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).
Expand Down