diff --git a/builtin/providers/aws/resource_aws_elasticache_replication_group.go b/builtin/providers/aws/resource_aws_elasticache_replication_group.go index 94ff26df01..9930794099 100644 --- a/builtin/providers/aws/resource_aws_elasticache_replication_group.go +++ b/builtin/providers/aws/resource_aws_elasticache_replication_group.go @@ -370,6 +370,12 @@ func resourceAwsElasticacheReplicationGroupUpdate(d *schema.ResourceData, meta i } if d.HasChange("snapshot_retention_limit") { + // This is a real hack to set the Snapshotting Cluster ID to be the first Cluster in the RG + o, _ := d.GetChange("snapshot_retention_limit") + if o.(int) == 0 { + params.SnapshottingClusterId = aws.String(fmt.Sprintf("%s-001", d.Id())) + } + params.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int))) requestUpdate = true } diff --git a/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go b/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go index 67ad63e8e2..97c778ccf8 100644 --- a/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go @@ -288,6 +288,36 @@ func TestAccAWSElasticacheReplicationGroup_clusteringAndCacheNodesCausesError(t }) } +func TestAccAWSElasticacheReplicationGroup_enableSnapshotting(t *testing.T) { + var rg elasticache.ReplicationGroup + rName := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSElasticacheReplicationGroupConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg), + resource.TestCheckResourceAttr( + "aws_elasticache_replication_group.bar", "snapshot_retention_limit", "0"), + ), + }, + + { + Config: testAccAWSElasticacheReplicationGroupConfigEnableSnapshotting(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg), + resource.TestCheckResourceAttr( + "aws_elasticache_replication_group.bar", "snapshot_retention_limit", "2"), + ), + }, + }, + }) +} + func TestResourceAWSElastiCacheReplicationGroupIdValidation(t *testing.T) { cases := []struct { Value string @@ -446,6 +476,44 @@ resource "aws_elasticache_replication_group" "bar" { }`, rName, rName, rName) } +func testAccAWSElasticacheReplicationGroupConfigEnableSnapshotting(rName string) string { + return fmt.Sprintf(` +provider "aws" { + region = "us-east-1" +} +resource "aws_security_group" "bar" { + name = "tf-test-security-group-%s" + description = "tf-test-security-group-descr" + ingress { + from_port = -1 + to_port = -1 + protocol = "icmp" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_elasticache_security_group" "bar" { + name = "tf-test-security-group-%s" + description = "tf-test-security-group-descr" + security_group_names = ["${aws_security_group.bar.name}"] +} + +resource "aws_elasticache_replication_group" "bar" { + replication_group_id = "tf-%s" + replication_group_description = "test description" + node_type = "cache.m1.small" + number_cache_clusters = 2 + port = 6379 + parameter_group_name = "default.redis3.2" + security_group_names = ["${aws_elasticache_security_group.bar.name}"] + apply_immediately = true + auto_minor_version_upgrade = false + maintenance_window = "tue:06:30-tue:07:30" + snapshot_window = "01:00-02:00" + snapshot_retention_limit = 2 +}`, rName, rName, rName) +} + func testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName string, rInt int) string { return fmt.Sprintf(` provider "aws" {