Merge pull request #9140 from hashicorp/import-aws-elasticache_replication_groups

provider/aws: Support Import of AWS elasticache_replication_groups
This commit is contained in:
Paul Stack 2016-10-03 16:59:31 +01:00 committed by GitHub
commit 2d90f8a91c
3 changed files with 66 additions and 7 deletions

View File

@ -0,0 +1,37 @@
package aws
import (
"os"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSElasticacheReplicationGroup_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_replication_group.bar"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSElasticacheReplicationGroupConfig(name),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately"}, //not in the API
},
},
})
}

View File

@ -57,6 +57,9 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
Read: resourceAwsElasticacheReplicationGroupRead, Read: resourceAwsElasticacheReplicationGroupRead,
Update: resourceAwsElasticacheReplicationGroupUpdate, Update: resourceAwsElasticacheReplicationGroupUpdate,
Delete: resourceAwsElasticacheReplicationGroupDelete, Delete: resourceAwsElasticacheReplicationGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: resourceSchema, Schema: resourceSchema,
} }
@ -192,7 +195,17 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int
return nil return nil
} }
d.Set("automatic_failover_enabled", rgp.AutomaticFailover) if rgp.AutomaticFailover != nil {
switch strings.ToLower(*rgp.AutomaticFailover) {
case "disabled", "disabling":
d.Set("automatic_failover_enabled", false)
case "enabled", "enabling":
d.Set("automatic_failover_enabled", true)
default:
log.Printf("Unknown AutomaticFailover state %s", *rgp.AutomaticFailover)
}
}
d.Set("replication_group_description", rgp.Description) d.Set("replication_group_description", rgp.Description)
d.Set("number_cache_clusters", len(rgp.MemberClusters)) d.Set("number_cache_clusters", len(rgp.MemberClusters))
d.Set("replication_group_id", rgp.ReplicationGroupId) d.Set("replication_group_id", rgp.ReplicationGroupId)
@ -217,15 +230,16 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int
d.Set("engine", c.Engine) d.Set("engine", c.Engine)
d.Set("engine_version", c.EngineVersion) d.Set("engine_version", c.EngineVersion)
d.Set("subnet_group_name", c.CacheSubnetGroupName) d.Set("subnet_group_name", c.CacheSubnetGroupName)
d.Set("security_group_names", c.CacheSecurityGroups) d.Set("security_group_names", flattenElastiCacheSecurityGroupNames(c.CacheSecurityGroups))
d.Set("security_group_ids", c.SecurityGroups) d.Set("security_group_ids", flattenElastiCacheSecurityGroupIds(c.SecurityGroups))
d.Set("parameter_group_name", c.CacheParameterGroup) if c.CacheParameterGroup != nil {
d.Set("parameter_group_name", c.CacheParameterGroup.CacheParameterGroupName)
}
d.Set("maintenance_window", c.PreferredMaintenanceWindow) d.Set("maintenance_window", c.PreferredMaintenanceWindow)
d.Set("snapshot_window", c.SnapshotWindow) d.Set("snapshot_window", c.SnapshotWindow)
d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit) d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit)
d.Set("port", rgp.NodeGroups[0].PrimaryEndpoint.Port)
d.Set("primary_endpoint_address", rgp.NodeGroups[0].PrimaryEndpoint.Address) d.Set("primary_endpoint_address", rgp.NodeGroups[0].PrimaryEndpoint.Address)
} }
return nil return nil

View File

@ -69,3 +69,11 @@ The following attributes are exported:
* `id` - The ID of the ElastiCache Replication Group * `id` - The ID of the ElastiCache Replication Group
* `primary_endpoint_address` - The address of the endpoint for the primary node in the replication group * `primary_endpoint_address` - The address of the endpoint for the primary node in the replication group
## Import
ElastiCache Replication Groups can be imported using the `replication_group_id`, e.g.
```
$ terraform import aws_elasticache_replication_group.my_replication_group replication-group-1
```