Skip to content

Commit 520f96e

Browse files
committed
provider/aws: Support Import of AWS elasticache_replication_groups
Fixes hashicorp#9094 ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSElasticacheReplicationGroup_importBasic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/30 00:09:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSElasticacheReplicationGroup_importBasic -timeout 120m === RUN TestAccAWSElasticacheReplicationGroup_importBasic --- PASS: TestAccAWSElasticacheReplicationGroup_importBasic (756.38s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws756.398s ```
1 parent 88c3554 commit 520f96e

3 files changed

Lines changed: 66 additions & 7 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package aws
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform/helper/acctest"
8+
"github.com/hashicorp/terraform/helper/resource"
9+
)
10+
11+
func TestAccAWSElasticacheReplicationGroup_importBasic(t *testing.T) {
12+
oldvar := os.Getenv("AWS_DEFAULT_REGION")
13+
os.Setenv("AWS_DEFAULT_REGION", "us-east-1")
14+
defer os.Setenv("AWS_DEFAULT_REGION", oldvar)
15+
16+
name := acctest.RandString(10)
17+
18+
resourceName := "aws_elasticache_replication_group.bar"
19+
20+
resource.Test(t, resource.TestCase{
21+
PreCheck: func() { testAccPreCheck(t) },
22+
Providers: testAccProviders,
23+
CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
24+
Steps: []resource.TestStep{
25+
resource.TestStep{
26+
Config: testAccAWSElasticacheReplicationGroupConfig(name),
27+
},
28+
29+
resource.TestStep{
30+
ResourceName: resourceName,
31+
ImportState: true,
32+
ImportStateVerify: true,
33+
ImportStateVerifyIgnore: []string{"apply_immediately"}, //not in the API
34+
},
35+
},
36+
})
37+
}

builtin/providers/aws/resource_aws_elasticache_replication_group.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
5757
Read: resourceAwsElasticacheReplicationGroupRead,
5858
Update: resourceAwsElasticacheReplicationGroupUpdate,
5959
Delete: resourceAwsElasticacheReplicationGroupDelete,
60+
Importer: &schema.ResourceImporter{
61+
State: schema.ImportStatePassthrough,
62+
},
6063

6164
Schema: resourceSchema,
6265
}
@@ -192,7 +195,17 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int
192195
return nil
193196
}
194197

195-
d.Set("automatic_failover_enabled", rgp.AutomaticFailover)
198+
if rgp.AutomaticFailover != nil {
199+
switch strings.ToLower(*rgp.AutomaticFailover) {
200+
case "disabled", "disabling":
201+
d.Set("automatic_failover_enabled", false)
202+
case "enabled", "enabling":
203+
d.Set("automatic_failover_enabled", true)
204+
default:
205+
log.Printf("Unknown AutomaticFailover state %s", *rgp.AutomaticFailover)
206+
}
207+
}
208+
196209
d.Set("replication_group_description", rgp.Description)
197210
d.Set("number_cache_clusters", len(rgp.MemberClusters))
198211
d.Set("replication_group_id", rgp.ReplicationGroupId)
@@ -217,15 +230,16 @@ func resourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta int
217230
d.Set("engine", c.Engine)
218231
d.Set("engine_version", c.EngineVersion)
219232
d.Set("subnet_group_name", c.CacheSubnetGroupName)
220-
d.Set("security_group_names", c.CacheSecurityGroups)
221-
d.Set("security_group_ids", c.SecurityGroups)
222-
d.Set("parameter_group_name", c.CacheParameterGroup)
233+
d.Set("security_group_names", flattenElastiCacheSecurityGroupNames(c.CacheSecurityGroups))
234+
d.Set("security_group_ids", flattenElastiCacheSecurityGroupIds(c.SecurityGroups))
235+
if c.CacheParameterGroup != nil {
236+
d.Set("parameter_group_name", c.CacheParameterGroup.CacheParameterGroupName)
237+
}
223238
d.Set("maintenance_window", c.PreferredMaintenanceWindow)
224239
d.Set("snapshot_window", c.SnapshotWindow)
225240
d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit)
226-
241+
d.Set("port", rgp.NodeGroups[0].PrimaryEndpoint.Port)
227242
d.Set("primary_endpoint_address", rgp.NodeGroups[0].PrimaryEndpoint.Address)
228-
229243
}
230244

231245
return nil

website/source/docs/providers/aws/r/elasticache_replication_group.html.markdown

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,12 @@ Please note that setting a `snapshot_retention_limit` is not supported on cache.
6868
The following attributes are exported:
6969

7070
* `id` - The ID of the ElastiCache Replication Group
71-
* `primary_endpoint_address` - The address of the endpoint for the primary node in the replication group
71+
* `primary_endpoint_address` - The address of the endpoint for the primary node in the replication group
72+
73+
## Import
74+
75+
ElastiCache Replication Groups can be imported using the `replication_group_id`, e.g.
76+
77+
```
78+
$ terraform import aws_elasticache_replication_group.my_replication_group replication-group-1
79+
```

0 commit comments

Comments
 (0)