Merge pull request #9010 from hashicorp/aws-elasticache-cluster-import
Aws elasticache cluster import
This commit is contained in:
commit
b6718de299
|
@ -0,0 +1,36 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccAWSElasticacheCluster_importBasic(t *testing.T) {
|
||||
oldvar := os.Getenv("AWS_DEFAULT_REGION")
|
||||
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{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSElasticacheClusterConfigBasic(name),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -210,6 +210,9 @@ func resourceAwsElasticacheCluster() *schema.Resource {
|
|||
Read: resourceAwsElasticacheClusterRead,
|
||||
Update: resourceAwsElasticacheClusterUpdate,
|
||||
Delete: resourceAwsElasticacheClusterDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: resourceSchema,
|
||||
}
|
||||
|
@ -361,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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -762,6 +762,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))
|
||||
|
|
|
@ -48,6 +48,7 @@ To make a resource importable, please see the
|
|||
* aws_eip
|
||||
* aws_elastic_beanstalk_application
|
||||
* aws_elastic_beanstalk_environment
|
||||
* aws_elasticache_cluster
|
||||
* aws_elasticache_parameter_group
|
||||
* aws_elasticache_subnet_group
|
||||
* aws_elb
|
||||
|
@ -149,4 +150,3 @@ To make a resource importable, please see the
|
|||
* triton_key
|
||||
* triton_machine
|
||||
* triton_vlan
|
||||
|
||||
|
|
|
@ -122,3 +122,12 @@ The following attributes are exported:
|
|||
|
||||
[1]: https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_ModifyCacheCluster.html
|
||||
[2]: https://docs.aws.amazon.com/fr_fr/AmazonElastiCache/latest/UserGuide/Clusters.Modify.html
|
||||
|
||||
|
||||
## Import
|
||||
|
||||
ElastiCache Clusters can be imported using the `cluster_id`, e.g.
|
||||
|
||||
```
|
||||
$ terraform import aws_elasticache_cluster.my_cluster my_cluster
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue