Making the changes to the snapshotting for Elasticache Redis as per @catsby's findings
This commit is contained in:
parent
707bfd739a
commit
ca2ea80af3
|
@ -205,12 +205,14 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
|
||||||
req.CacheParameterGroupName = aws.String(v.(string))
|
req.CacheParameterGroupName = aws.String(v.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("snapshot_retention_limit"); ok {
|
if !strings.Contains(d.Get("node_type").(string), "cache.t2") {
|
||||||
req.SnapshotRetentionLimit = aws.Int64(int64(v.(int)))
|
if v, ok := d.GetOk("snapshot_retention_limit"); ok {
|
||||||
}
|
req.SnapshotRetentionLimit = aws.Int64(int64(v.(int)))
|
||||||
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("snapshot_window"); ok {
|
if v, ok := d.GetOk("snapshot_window"); ok {
|
||||||
req.SnapshotWindow = aws.String(v.(string))
|
req.SnapshotWindow = aws.String(v.(string))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("maintenance_window"); ok {
|
if v, ok := d.GetOk("maintenance_window"); ok {
|
||||||
|
@ -287,10 +289,12 @@ func resourceAwsElasticacheClusterRead(d *schema.ResourceData, meta interface{})
|
||||||
d.Set("security_group_ids", c.SecurityGroups)
|
d.Set("security_group_ids", c.SecurityGroups)
|
||||||
d.Set("parameter_group_name", c.CacheParameterGroup)
|
d.Set("parameter_group_name", c.CacheParameterGroup)
|
||||||
d.Set("maintenance_window", c.PreferredMaintenanceWindow)
|
d.Set("maintenance_window", c.PreferredMaintenanceWindow)
|
||||||
log.Printf("[INFO] Found %s as the Snapshow Window", *c.SnapshotWindow)
|
if c.SnapshotWindow != nil {
|
||||||
d.Set("snapshot_window", c.SnapshotWindow)
|
d.Set("snapshot_window", c.SnapshotWindow)
|
||||||
log.Printf("[INFO] Found %d as the Snapshow Retention Limit", *c.SnapshotRetentionLimit)
|
}
|
||||||
d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit)
|
if c.SnapshotRetentionLimit != nil {
|
||||||
|
d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit)
|
||||||
|
}
|
||||||
if c.NotificationConfiguration != nil {
|
if c.NotificationConfiguration != nil {
|
||||||
if *c.NotificationConfiguration.TopicStatus == "active" {
|
if *c.NotificationConfiguration.TopicStatus == "active" {
|
||||||
d.Set("notification_topic_arn", c.NotificationConfiguration.TopicArn)
|
d.Set("notification_topic_arn", c.NotificationConfiguration.TopicArn)
|
||||||
|
@ -373,13 +377,16 @@ func resourceAwsElasticacheClusterUpdate(d *schema.ResourceData, meta interface{
|
||||||
req.EngineVersion = aws.String(d.Get("engine_version").(string))
|
req.EngineVersion = aws.String(d.Get("engine_version").(string))
|
||||||
requestUpdate = true
|
requestUpdate = true
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(d.Get("node_type").(string), "cache.t2") {
|
||||||
|
if d.HasChange("snapshot_window") {
|
||||||
|
req.SnapshotWindow = aws.String(d.Get("snapshot_window").(string))
|
||||||
|
requestUpdate = true
|
||||||
|
}
|
||||||
|
|
||||||
if d.HasChange("snapshot_window") {
|
if d.HasChange("snapshot_retention_limit") {
|
||||||
req.SnapshotWindow = aws.String(d.Get("snapshot_window").(string))
|
req.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int)))
|
||||||
}
|
requestUpdate = true
|
||||||
|
}
|
||||||
if d.HasChange("snapshot_retention_limit") {
|
|
||||||
req.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("num_cache_nodes") {
|
if d.HasChange("num_cache_nodes") {
|
||||||
|
|
|
@ -35,13 +35,17 @@ func TestAccAWSElasticacheCluster_basic(t *testing.T) {
|
||||||
|
|
||||||
func TestAccAWSElasticacheCluster_snapshots(t *testing.T) {
|
func TestAccAWSElasticacheCluster_snapshots(t *testing.T) {
|
||||||
var ec elasticache.CacheCluster
|
var ec elasticache.CacheCluster
|
||||||
|
|
||||||
|
ri := genRandInt()
|
||||||
|
config := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSElasticacheClusterConfig_snapshots,
|
Config: config,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
||||||
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
||||||
|
@ -56,13 +60,18 @@ func TestAccAWSElasticacheCluster_snapshots(t *testing.T) {
|
||||||
}
|
}
|
||||||
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
||||||
var ec elasticache.CacheCluster
|
var ec elasticache.CacheCluster
|
||||||
|
|
||||||
|
ri := genRandInt()
|
||||||
|
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri)
|
||||||
|
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSElasticacheClusterConfig_snapshots,
|
Config: preConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
||||||
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
||||||
|
@ -74,7 +83,7 @@ func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSElasticacheClusterConfig_snapshotsUpdated,
|
Config: postConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
||||||
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
||||||
|
@ -204,17 +213,15 @@ resource "aws_elasticache_cluster" "bar" {
|
||||||
port = 11211
|
port = 11211
|
||||||
parameter_group_name = "default.memcached1.4"
|
parameter_group_name = "default.memcached1.4"
|
||||||
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
||||||
snapshot_window = "05:00-09:00"
|
|
||||||
snapshot_retention_limit = 3
|
|
||||||
}
|
}
|
||||||
`, genRandInt(), genRandInt(), genRandInt())
|
`, genRandInt(), genRandInt(), genRandInt())
|
||||||
|
|
||||||
var testAccAWSElasticacheClusterConfig_snapshots = fmt.Sprintf(`
|
var testAccAWSElasticacheClusterConfig_snapshots = `
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-east-1"
|
region = "us-east-1"
|
||||||
}
|
}
|
||||||
resource "aws_security_group" "bar" {
|
resource "aws_security_group" "bar" {
|
||||||
name = "tf-test-security-group-%03d"
|
name = "tf-test-security-group"
|
||||||
description = "tf-test-security-group-descr"
|
description = "tf-test-security-group-descr"
|
||||||
ingress {
|
ingress {
|
||||||
from_port = -1
|
from_port = -1
|
||||||
|
@ -225,7 +232,7 @@ resource "aws_security_group" "bar" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_elasticache_security_group" "bar" {
|
resource "aws_elasticache_security_group" "bar" {
|
||||||
name = "tf-test-security-group-%03d"
|
name = "tf-test-security-group"
|
||||||
description = "tf-test-security-group-descr"
|
description = "tf-test-security-group-descr"
|
||||||
security_group_names = ["${aws_security_group.bar.name}"]
|
security_group_names = ["${aws_security_group.bar.name}"]
|
||||||
}
|
}
|
||||||
|
@ -241,14 +248,14 @@ resource "aws_elasticache_cluster" "bar" {
|
||||||
snapshot_window = "05:00-09:00"
|
snapshot_window = "05:00-09:00"
|
||||||
snapshot_retention_limit = 3
|
snapshot_retention_limit = 3
|
||||||
}
|
}
|
||||||
`, genRandInt(), genRandInt(), genRandInt())
|
`
|
||||||
|
|
||||||
var testAccAWSElasticacheClusterConfig_snapshotsUpdated = fmt.Sprintf(`
|
var testAccAWSElasticacheClusterConfig_snapshotsUpdated = `
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-east-1"
|
region = "us-east-1"
|
||||||
}
|
}
|
||||||
resource "aws_security_group" "bar" {
|
resource "aws_security_group" "bar" {
|
||||||
name = "tf-test-security-group-%03d"
|
name = "tf-test-security-group"
|
||||||
description = "tf-test-security-group-descr"
|
description = "tf-test-security-group-descr"
|
||||||
ingress {
|
ingress {
|
||||||
from_port = -1
|
from_port = -1
|
||||||
|
@ -259,7 +266,7 @@ resource "aws_security_group" "bar" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_elasticache_security_group" "bar" {
|
resource "aws_elasticache_security_group" "bar" {
|
||||||
name = "tf-test-security-group-%03d"
|
name = "tf-test-security-group"
|
||||||
description = "tf-test-security-group-descr"
|
description = "tf-test-security-group-descr"
|
||||||
security_group_names = ["${aws_security_group.bar.name}"]
|
security_group_names = ["${aws_security_group.bar.name}"]
|
||||||
}
|
}
|
||||||
|
@ -274,8 +281,9 @@ resource "aws_elasticache_cluster" "bar" {
|
||||||
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
||||||
snapshot_window = "07:00-09:00"
|
snapshot_window = "07:00-09:00"
|
||||||
snapshot_retention_limit = 7
|
snapshot_retention_limit = 7
|
||||||
|
apply_immediately = true
|
||||||
}
|
}
|
||||||
`, genRandInt(), genRandInt(), genRandInt())
|
`
|
||||||
|
|
||||||
var testAccAWSElasticacheClusterInVPCConfig = fmt.Sprintf(`
|
var testAccAWSElasticacheClusterInVPCConfig = fmt.Sprintf(`
|
||||||
resource "aws_vpc" "foo" {
|
resource "aws_vpc" "foo" {
|
||||||
|
|
Loading…
Reference in New Issue