Making the changes to the snapshotting for Elasticache Redis as per @catsby's findings

This commit is contained in:
stack72 2015-11-05 12:23:07 +00:00
parent 707bfd739a
commit ca2ea80af3
2 changed files with 43 additions and 28 deletions

View File

@ -205,12 +205,14 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
req.CacheParameterGroupName = aws.String(v.(string))
}
if v, ok := d.GetOk("snapshot_retention_limit"); ok {
req.SnapshotRetentionLimit = aws.Int64(int64(v.(int)))
}
if !strings.Contains(d.Get("node_type").(string), "cache.t2") {
if v, ok := d.GetOk("snapshot_retention_limit"); ok {
req.SnapshotRetentionLimit = aws.Int64(int64(v.(int)))
}
if v, ok := d.GetOk("snapshot_window"); ok {
req.SnapshotWindow = aws.String(v.(string))
if v, ok := d.GetOk("snapshot_window"); ok {
req.SnapshotWindow = aws.String(v.(string))
}
}
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("parameter_group_name", c.CacheParameterGroup)
d.Set("maintenance_window", c.PreferredMaintenanceWindow)
log.Printf("[INFO] Found %s as the Snapshow 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.SnapshotWindow != nil {
d.Set("snapshot_window", c.SnapshotWindow)
}
if c.SnapshotRetentionLimit != nil {
d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit)
}
if c.NotificationConfiguration != nil {
if *c.NotificationConfiguration.TopicStatus == "active" {
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))
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") {
req.SnapshotWindow = aws.String(d.Get("snapshot_window").(string))
}
if d.HasChange("snapshot_retention_limit") {
req.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int)))
if d.HasChange("snapshot_retention_limit") {
req.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int)))
requestUpdate = true
}
}
if d.HasChange("num_cache_nodes") {

View File

@ -35,13 +35,17 @@ func TestAccAWSElasticacheCluster_basic(t *testing.T) {
func TestAccAWSElasticacheCluster_snapshots(t *testing.T) {
var ec elasticache.CacheCluster
ri := genRandInt()
config := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSElasticacheClusterConfig_snapshots,
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
@ -56,13 +60,18 @@ func TestAccAWSElasticacheCluster_snapshots(t *testing.T) {
}
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
var ec elasticache.CacheCluster
ri := genRandInt()
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri)
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSElasticacheClusterConfig_snapshots,
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
@ -74,7 +83,7 @@ func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
},
resource.TestStep{
Config: testAccAWSElasticacheClusterConfig_snapshotsUpdated,
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
@ -204,17 +213,15 @@ resource "aws_elasticache_cluster" "bar" {
port = 11211
parameter_group_name = "default.memcached1.4"
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
snapshot_window = "05:00-09:00"
snapshot_retention_limit = 3
}
`, genRandInt(), genRandInt(), genRandInt())
var testAccAWSElasticacheClusterConfig_snapshots = fmt.Sprintf(`
var testAccAWSElasticacheClusterConfig_snapshots = `
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "bar" {
name = "tf-test-security-group-%03d"
name = "tf-test-security-group"
description = "tf-test-security-group-descr"
ingress {
from_port = -1
@ -225,7 +232,7 @@ resource "aws_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"
security_group_names = ["${aws_security_group.bar.name}"]
}
@ -241,14 +248,14 @@ resource "aws_elasticache_cluster" "bar" {
snapshot_window = "05:00-09:00"
snapshot_retention_limit = 3
}
`, genRandInt(), genRandInt(), genRandInt())
`
var testAccAWSElasticacheClusterConfig_snapshotsUpdated = fmt.Sprintf(`
var testAccAWSElasticacheClusterConfig_snapshotsUpdated = `
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "bar" {
name = "tf-test-security-group-%03d"
name = "tf-test-security-group"
description = "tf-test-security-group-descr"
ingress {
from_port = -1
@ -259,7 +266,7 @@ resource "aws_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"
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}"]
snapshot_window = "07:00-09:00"
snapshot_retention_limit = 7
apply_immediately = true
}
`, genRandInt(), genRandInt(), genRandInt())
`
var testAccAWSElasticacheClusterInVPCConfig = fmt.Sprintf(`
resource "aws_vpc" "foo" {