-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Data Source: aws_elasticache_replication_group (#2124)
* Make files * fix * New data source: aws_elasticache_replication_group, make docs * Reflect 1st review * goimport
- Loading branch information
1 parent
386326d
commit d503e89
Showing
5 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/elasticache" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsElasticacheReplicationGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsElasticacheReplicationGroupRead, | ||
Schema: map[string]*schema.Schema{ | ||
"replication_group_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"replication_group_description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"auth_token_enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"automatic_failover_enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"port": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"configuration_endpoint_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"primary_endpoint_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"number_cache_clusters": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"node_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_window": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_retention_limit": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsElasticacheReplicationGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).elasticacheconn | ||
input := &elasticache.DescribeReplicationGroupsInput{ | ||
ReplicationGroupId: aws.String(d.Get("replication_group_id").(string)), | ||
} | ||
|
||
resp, err := conn.DescribeReplicationGroups(input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var rg *elasticache.ReplicationGroup | ||
for _, r := range resp.ReplicationGroups { | ||
if *r.ReplicationGroupId == d.Get("replication_group_id").(string) { | ||
rg = r | ||
} | ||
} | ||
if rg == nil { | ||
return fmt.Errorf("Elasticache Replication Group (%s) not found", d.Get("replication_group_id").(string)) | ||
} | ||
|
||
d.SetId(*rg.ReplicationGroupId) | ||
d.Set("replication_group_description", rg.Description) | ||
d.Set("auth_token_enabled", rg.AuthTokenEnabled) | ||
if rg.AutomaticFailover != nil { | ||
switch *rg.AutomaticFailover { | ||
case elasticache.AutomaticFailoverStatusDisabled, elasticache.AutomaticFailoverStatusDisabling: | ||
d.Set("automatic_failover_enabled", false) | ||
case elasticache.AutomaticFailoverStatusEnabled, elasticache.AutomaticFailoverStatusEnabling: | ||
d.Set("automatic_failover_enabled", true) | ||
} | ||
} | ||
if rg.ConfigurationEndpoint != nil { | ||
d.Set("port", rg.ConfigurationEndpoint.Port) | ||
d.Set("configuration_endpoint_address", rg.ConfigurationEndpoint.Address) | ||
} else { | ||
if rg.NodeGroups == nil { | ||
d.SetId("") | ||
return fmt.Errorf("Elasticache Replication Group (%s) doesn't have node groups.", d.Get("replication_group_id").(string)) | ||
} | ||
d.Set("port", rg.NodeGroups[0].PrimaryEndpoint.Port) | ||
d.Set("primary_endpoint_address", rg.NodeGroups[0].PrimaryEndpoint.Address) | ||
} | ||
d.Set("number_cache_clusters", len(rg.MemberClusters)) | ||
d.Set("node_type", rg.CacheNodeType) | ||
d.Set("snapshot_window", rg.SnapshotWindow) | ||
d.Set("snapshot_retention_limit", rg.SnapshotRetentionLimit) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsElasticacheReplicationGroup_basic(t *testing.T) { | ||
rName := acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsElasticacheReplicationGroupConfig_basic(rName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "replication_group_id", fmt.Sprintf("tf-%s", rName)), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "replication_group_description", "test description"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "auth_token_enabled", "false"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "automatic_failover_enabled", "true"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "port", "6379"), | ||
resource.TestCheckResourceAttrSet("data.aws_elasticache_replication_group.bar", "primary_endpoint_address"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "number_cache_clusters", "2"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "node_type", "cache.m1.small"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.bar", "snapshot_window", "01:00-02:00"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAwsElasticacheReplicationGroup_ClusterMode(t *testing.T) { | ||
rName := acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsElasticacheReplicationGroupConfig_ClusterMode(rName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.cluster", "replication_group_id", fmt.Sprintf("tf-%s", rName)), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.cluster", "replication_group_description", "test description"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.cluster", "auth_token_enabled", "false"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.cluster", "automatic_failover_enabled", "true"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.cluster", "port", "6379"), | ||
resource.TestCheckResourceAttrSet("data.aws_elasticache_replication_group.cluster", "configuration_endpoint_address"), | ||
resource.TestCheckResourceAttr("data.aws_elasticache_replication_group.cluster", "node_type", "cache.m1.small"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsElasticacheReplicationGroupConfig_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
data "aws_availability_zones" "available" {} | ||
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 = "default.redis3.2" | ||
availability_zones = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}"] | ||
automatic_failover_enabled = true | ||
snapshot_window = "01:00-02:00" | ||
} | ||
data "aws_elasticache_replication_group" "bar" { | ||
replication_group_id = "${aws_elasticache_replication_group.bar.replication_group_id}" | ||
}`, rName) | ||
} | ||
|
||
func testAccDataSourceAwsElasticacheReplicationGroupConfig_ClusterMode(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_elasticache_replication_group" "cluster" { | ||
replication_group_id = "tf-%s" | ||
replication_group_description = "test description" | ||
node_type = "cache.m1.small" | ||
port = 6379 | ||
parameter_group_name = "default.redis3.2.cluster.on" | ||
automatic_failover_enabled = true | ||
cluster_mode { | ||
replicas_per_node_group = 1 | ||
num_node_groups = 2 | ||
} | ||
} | ||
data "aws_elasticache_replication_group" "cluster" { | ||
replication_group_id = "${aws_elasticache_replication_group.cluster.replication_group_id}" | ||
}`, rName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
website/docs/d/elasticache_replication_group.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_elasticache_replication_group" | ||
sidebar_current: "docs-aws-datasource-elasticache-replication-group" | ||
description: |- | ||
Get information on an ElastiCache Replication Group resource. | ||
--- | ||
|
||
# aws_elasticache_replication_group | ||
|
||
Use this data source to get information about an Elasticache Replication Group. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_elasticache_replication_group" "bar" { | ||
replication_group_id = "example" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `replication_group_id` – (Required) The identifier for the replication group. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `replication_group_id` - The identifier for the replication group. | ||
* `replication_group_description` - The description of the replication group. | ||
* `auth_token_enabled` - A flag that enables using an AuthToken (password) when issuing Redis commands. | ||
* `automatic_failover_enabled` - A flag whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | ||
* `node_type` – The cluster node type. | ||
* `number_cache_clusters` – The number of cache clusters that the replication group has. | ||
* `snapshot_window` - The daily time range (in UTC) during which ElastiCache begins taking a daily snapshot of your node group (shard). | ||
* `snapshot_retention_limit` - The number of days for which ElastiCache retains automatic cache cluster snapshots before deleting them. | ||
* `port` – The port number on which the configuration endpoint will accept connections. | ||
* `configuration_endpoint_address` - The configuration endpoint address to allow host discovery. | ||
* `primary_endpoint_address` - The endpoint of the primary node in this node group (shard). |