From 2efd93a67e80e025ba21e12e4947136a791a34f2 Mon Sep 17 00:00:00 2001 From: stack72 Date: Wed, 28 Sep 2016 11:33:50 +0100 Subject: [PATCH] provider/aws: Modifying the parameter_group_name of aws_elasticache_replication_group caused a panic Fixes #9097 The update for `parameter_group_name` was trying to find the incorrect value to set `cache_parameter_group_name` - this is what was causing the panic ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSElasticacheReplicationGroup_updateParameterGroup' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/28 11:17:30 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSElasticacheReplicationGroup_updateParameterGroup -timeout 120m === RUN TestAccAWSElasticacheReplicationGroup_updateParameterGroup --- PASS: TestAccAWSElasticacheReplicationGroup_updateParameterGroup (903.90s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws903.931s ``` --- ...ource_aws_elasticache_replication_group.go | 2 +- ..._aws_elasticache_replication_group_test.go | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_elasticache_replication_group.go b/builtin/providers/aws/resource_aws_elasticache_replication_group.go index 4bb42261a9..bcee8cf03c 100644 --- a/builtin/providers/aws/resource_aws_elasticache_replication_group.go +++ b/builtin/providers/aws/resource_aws_elasticache_replication_group.go @@ -275,7 +275,7 @@ func resourceAwsElasticacheReplicationGroupUpdate(d *schema.ResourceData, meta i } if d.HasChange("parameter_group_name") { - params.CacheParameterGroupName = aws.String(d.Get("cache_parameter_group_name").(string)) + params.CacheParameterGroupName = aws.String(d.Get("parameter_group_name").(string)) 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 ebd3e6a9e3..58c872a235 100644 --- a/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go @@ -98,6 +98,36 @@ func TestAccAWSElasticacheReplicationGroup_updateNodeSize(t *testing.T) { }) } +//This is a test to prove that we panic we get in https://github.com/hashicorp/terraform/issues/9097 +func TestAccAWSElasticacheReplicationGroup_updateParameterGroup(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{ + resource.TestStep{ + Config: testAccAWSElasticacheReplicationGroupConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg), + resource.TestCheckResourceAttr( + "aws_elasticache_replication_group.bar", "parameter_group_name", "default.redis2.8"), + ), + }, + + resource.TestStep{ + Config: testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg), + resource.TestCheckResourceAttr( + "aws_elasticache_replication_group.bar", "parameter_group_name", "allkeys-lru"), + ), + }, + }, + }) +} + func TestAccAWSElasticacheReplicationGroup_vpc(t *testing.T) { var rg elasticache.ReplicationGroup resource.Test(t, resource.TestCase{ @@ -293,6 +323,50 @@ resource "aws_elasticache_replication_group" "bar" { }`, rName, rName, rName) } +func testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(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_parameter_group" "bar" { + name = "allkeys-lru" + family = "redis2.8" + + parameter { + name = "maxmemory-policy" + value = "allkeys-lru" + } +} + +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 = "${aws_elasticache_parameter_group.bar.name}" + security_group_names = ["${aws_elasticache_security_group.bar.name}"] + apply_immediately = true +}`, rName, rName, rName) +} + func testAccAWSElasticacheReplicationGroupConfigUpdatedDescription(rName string) string { return fmt.Sprintf(` provider "aws" {