diff --git a/builtin/providers/aws/import_aws_elasticache_cluster_test.go b/builtin/providers/aws/import_aws_elasticache_cluster_test.go index f1e951bc1a40..6128ddf9503e 100644 --- a/builtin/providers/aws/import_aws_elasticache_cluster_test.go +++ b/builtin/providers/aws/import_aws_elasticache_cluster_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) @@ -12,6 +13,8 @@ func TestAccAWSElasticacheCluster_importBasic(t *testing.T) { os.Setenv("AWS_DEFAULT_REGION", "us-east-1") defer os.Setenv("AWS_DEFAULT_REGION", oldvar) + name := acctest.RandString(10) + resourceName := "aws_elasticache_cluster.bar" resource.Test(t, resource.TestCase{ @@ -20,7 +23,7 @@ func TestAccAWSElasticacheCluster_importBasic(t *testing.T) { CheckDestroy: testAccCheckAWSElasticacheClusterDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSElasticacheClusterConfig, + Config: testAccAWSElasticacheClusterConfigBasic(name), }, resource.TestStep{ diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index 831424020790..9b30963c4e7b 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -364,9 +364,11 @@ func resourceAwsElasticacheClusterRead(d *schema.ResourceData, meta interface{}) } d.Set("subnet_group_name", c.CacheSubnetGroupName) - d.Set("security_group_names", c.CacheSecurityGroups) - d.Set("security_group_ids", c.SecurityGroups) - d.Set("parameter_group_name", c.CacheParameterGroup) + d.Set("security_group_names", flattenElastiCacheSecurityGroupNames(c.CacheSecurityGroups)) + d.Set("security_group_ids", flattenElastiCacheSecurityGroupIds(c.SecurityGroups)) + if c.CacheParameterGroup != nil { + d.Set("parameter_group_name", c.CacheParameterGroup.CacheParameterGroupName) + } d.Set("maintenance_window", c.PreferredMaintenanceWindow) d.Set("snapshot_window", c.SnapshotWindow) d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit) diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster_test.go b/builtin/providers/aws/resource_aws_elasticache_cluster_test.go index fe3d87691d56..cc90838624b0 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster_test.go @@ -219,6 +219,23 @@ func testAccCheckAWSElasticacheClusterExists(n string, v *elasticache.CacheClust } } +func testAccAWSElasticacheClusterConfigBasic(clusterId string) string { + return fmt.Sprintf(` +provider "aws" { + region = "us-east-1" +} + +resource "aws_elasticache_cluster" "bar" { + cluster_id = "tf-%s" + engine = "memcached" + node_type = "cache.m1.small" + num_cache_nodes = 1 + port = 11211 + parameter_group_name = "default.memcached1.4" +} +`, clusterId) +} + var testAccAWSElasticacheClusterConfig = fmt.Sprintf(` provider "aws" { region = "us-east-1" diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 925abf8f4342..a18f3d4b23e2 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -758,6 +758,26 @@ func flattenAttachment(a *ec2.NetworkInterfaceAttachment) map[string]interface{} return att } +func flattenElastiCacheSecurityGroupNames(securityGroups []*elasticache.CacheSecurityGroupMembership) []string { + result := make([]string, 0, len(securityGroups)) + for _, sg := range securityGroups { + if sg.CacheSecurityGroupName != nil { + result = append(result, *sg.CacheSecurityGroupName) + } + } + return result +} + +func flattenElastiCacheSecurityGroupIds(securityGroups []*elasticache.SecurityGroupMembership) []string { + result := make([]string, 0, len(securityGroups)) + for _, sg := range securityGroups { + if sg.SecurityGroupId != nil { + result = append(result, *sg.SecurityGroupId) + } + } + return result +} + // Flattens step adjustments into a list of map[string]interface. func flattenStepAdjustments(adjustments []*autoscaling.StepAdjustment) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(adjustments))