2015-04-26 03:53:21 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-10-28 20:09:45 +01:00
|
|
|
"strings"
|
2015-04-26 03:53:21 +02:00
|
|
|
"testing"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2015-12-22 16:02:19 +01:00
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/elasticache"
|
2016-02-04 18:20:22 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-04-26 03:53:21 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-05-14 20:57:01 +02:00
|
|
|
func TestAccAWSElasticacheCluster_basic(t *testing.T) {
|
2015-10-28 20:09:45 +01:00
|
|
|
var ec elasticache.CacheCluster
|
2015-04-26 03:53:21 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
2015-04-28 18:30:15 +02:00
|
|
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
2015-04-26 03:53:21 +02:00
|
|
|
Steps: []resource.TestStep{
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2015-04-28 18:30:15 +02:00
|
|
|
Config: testAccAWSElasticacheClusterConfig,
|
2015-04-26 03:53:21 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2015-05-06 15:33:05 +02:00
|
|
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
2015-10-28 20:09:45 +01:00
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
2015-05-13 00:05:03 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-05-14 20:57:01 +02:00
|
|
|
"aws_elasticache_cluster.bar", "cache_nodes.0.id", "0001"),
|
2016-09-20 18:29:57 +02:00
|
|
|
resource.TestCheckResourceAttrSet("aws_elasticache_cluster.bar", "configuration_endpoint"),
|
|
|
|
resource.TestCheckResourceAttrSet("aws_elasticache_cluster.bar", "cluster_address"),
|
2015-04-26 03:53:21 +02:00
|
|
|
),
|
|
|
|
},
|
2015-04-28 18:30:15 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-11-03 13:35:06 +01:00
|
|
|
func TestAccAWSElasticacheCluster_snapshotsWithUpdates(t *testing.T) {
|
|
|
|
var ec elasticache.CacheCluster
|
2015-11-05 13:23:07 +01:00
|
|
|
|
2016-02-04 18:20:22 +01:00
|
|
|
ri := acctest.RandInt()
|
2016-02-04 22:48:54 +01:00
|
|
|
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshots, ri, ri, acctest.RandString(10))
|
|
|
|
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfig_snapshotsUpdated, ri, ri, acctest.RandString(10))
|
2015-11-05 13:23:07 +01:00
|
|
|
|
2015-11-03 13:35:06 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2015-11-05 13:23:07 +01:00
|
|
|
Config: preConfig,
|
2015-11-03 13:35:06 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "snapshot_window", "05:00-09:00"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "snapshot_retention_limit", "3"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2015-11-05 13:23:07 +01:00
|
|
|
Config: postConfig,
|
2015-11-03 13:35:06 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "snapshot_window", "07:00-09:00"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "snapshot_retention_limit", "7"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-10-31 00:55:00 +01:00
|
|
|
|
2015-11-06 18:36:26 +01:00
|
|
|
func TestAccAWSElasticacheCluster_decreasingCacheNodes(t *testing.T) {
|
|
|
|
var ec elasticache.CacheCluster
|
|
|
|
|
2016-02-04 18:20:22 +01:00
|
|
|
ri := acctest.RandInt()
|
2016-02-04 22:48:54 +01:00
|
|
|
preConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes, ri, ri, acctest.RandString(10))
|
|
|
|
postConfig := fmt.Sprintf(testAccAWSElasticacheClusterConfigDecreasingNodes_update, ri, ri, acctest.RandString(10))
|
2015-11-06 18:36:26 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2015-11-06 18:36:26 +01:00
|
|
|
Config: preConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "num_cache_nodes", "3"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2015-11-06 18:36:26 +01:00
|
|
|
Config: postConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "num_cache_nodes", "1"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:30:15 +02:00
|
|
|
func TestAccAWSElasticacheCluster_vpc(t *testing.T) {
|
2015-06-02 18:19:23 +02:00
|
|
|
var csg elasticache.CacheSubnetGroup
|
2015-10-28 20:09:45 +01:00
|
|
|
var ec elasticache.CacheCluster
|
2015-04-28 18:30:15 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2015-04-28 18:30:15 +02:00
|
|
|
Config: testAccAWSElasticacheClusterInVPCConfig,
|
2015-04-26 03:53:21 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2015-06-02 18:19:23 +02:00
|
|
|
testAccCheckAWSElasticacheSubnetGroupExists("aws_elasticache_subnet_group.bar", &csg),
|
2015-10-28 20:09:45 +01:00
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
|
|
|
testAccCheckAWSElasticacheClusterAttributes(&ec),
|
2016-01-11 15:33:21 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "availability_zone", "us-west-2a"),
|
2015-04-26 03:53:21 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-11 15:45:07 +01:00
|
|
|
func TestAccAWSElasticacheCluster_multiAZInVpc(t *testing.T) {
|
|
|
|
var csg elasticache.CacheSubnetGroup
|
|
|
|
var ec elasticache.CacheCluster
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSElasticacheClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-05-31 15:25:27 +02:00
|
|
|
{
|
2016-01-11 15:45:07 +01:00
|
|
|
Config: testAccAWSElasticacheClusterMultiAZInVPCConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSElasticacheSubnetGroupExists("aws_elasticache_subnet_group.bar", &csg),
|
|
|
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticache_cluster.bar", "availability_zone", "Multiple"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-10-28 20:09:45 +01:00
|
|
|
func testAccCheckAWSElasticacheClusterAttributes(v *elasticache.CacheCluster) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if v.NotificationConfiguration == nil {
|
|
|
|
return fmt.Errorf("Expected NotificationConfiguration for ElastiCache Cluster (%s)", *v.CacheClusterId)
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.ToLower(*v.NotificationConfiguration.TopicStatus) != "active" {
|
|
|
|
return fmt.Errorf("Expected NotificationConfiguration status to be 'active', got (%s)", *v.NotificationConfiguration.TopicStatus)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:30:15 +02:00
|
|
|
func testAccCheckAWSElasticacheClusterDestroy(s *terraform.State) error {
|
2015-04-26 03:53:21 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
2015-04-28 18:30:15 +02:00
|
|
|
if rs.Type != "aws_elasticache_cluster" {
|
2015-04-26 03:53:21 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
res, err := conn.DescribeCacheClusters(&elasticache.DescribeCacheClustersInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
CacheClusterId: aws.String(rs.Primary.ID),
|
2015-04-26 03:53:21 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
2015-12-22 16:02:19 +01:00
|
|
|
// Verify the error is what we want
|
|
|
|
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "CacheClusterNotFound" {
|
|
|
|
continue
|
|
|
|
}
|
2015-04-26 03:53:21 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(res.CacheClusters) > 0 {
|
|
|
|
return fmt.Errorf("still exist.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-28 20:09:45 +01:00
|
|
|
func testAccCheckAWSElasticacheClusterExists(n string, v *elasticache.CacheCluster) resource.TestCheckFunc {
|
2015-04-26 03:53:21 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No cache cluster ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
|
2015-10-28 20:09:45 +01:00
|
|
|
resp, err := conn.DescribeCacheClusters(&elasticache.DescribeCacheClustersInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
CacheClusterId: aws.String(rs.Primary.ID),
|
2015-04-26 03:53:21 +02:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Elasticache error: %v", err)
|
|
|
|
}
|
2015-10-28 20:09:45 +01:00
|
|
|
|
|
|
|
for _, c := range resp.CacheClusters {
|
|
|
|
if *c.CacheClusterId == rs.Primary.ID {
|
|
|
|
*v = *c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 03:53:21 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
provider/aws: Support Import of aws_elasticache_cluster
Initial tests were failing as follows:
```
=== RUN TestAccAWSElasticacheCluster_importBasic
--- FAIL: TestAccAWSElasticacheCluster_importBasic (362.66s)
testing.go:265: Step 1 error: ImportStateVerify attributes not
equivalent. Difference is shown below. Top is actual, bottom is
expected.
(map[string]string) {
}
(map[string]string) (len=2) {
(string) (len=20) "parameter_group_name": (string) (len=20)
"default.memcached1.4",
(string) (len=22) "security_group_names.#":
(string) (len=1) "0"
}
FAIL
exit status 1
```
The import of ElastiCache clusters helped to point out 3 things:
1. Currently, we were trying to set the parameter_group_name as follows:
```
d.Set("parameter_group_name", c.CacheParameterGroup)
```
Unfortunately, c.CacheParameterGroup is a struct not a string. This was
causing the test import failure. So this had to be replaced as follows:
```
if c.CacheParameterGroup != nil {
d.Set("parameter_group_name", c.CacheParameterGroup.CacheParameterGroupName)
}
```
2. We were trying to set the security_group_names as follows:
```
d.Set("security_group_names", c.CacheSecurityGroups)
```
The CacheSecurityGroups was actually a []* so had to be changed to work
as follows:
```
if len(c.CacheSecurityGroups) > 0 {
d.Set("security_group_names",
flattenElastiCacheSecurityGroupNames(c.CacheSecurityGroups))
}
```
3. We were trying to set the security_group_ids as follows:
```
d.Set("security_group_ids", c.SecurityGroups)
```
This is another []* and needs to be changed as follows:
```
if len(c.SecurityGroups) > 0 {
d.Set("security_group_ids",
flattenElastiCacheSecurityGroupIds(c.SecurityGroups))
}
```
This then allows the import test to pass as expected:
```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSElasticacheCluster_importBasic'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/23 10:59:01 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v
-run=TestAccAWSElasticacheCluster_importBasic -timeout 120m
=== RUN TestAccAWSElasticacheCluster_importBasic
--- PASS: TestAccAWSElasticacheCluster_importBasic (351.96s)
PASS
ok github.com/hashicorp/terraform/builtin/providers/aws 351.981s
```
As a final test, I ran the basic ElastiCache cluster creation to make
sure all passed as expected:
```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSElasticacheCluster_basic'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/23 11:05:51 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v
-run=TestAccAWSElasticacheCluster_basic -timeout 120m
=== RUN TestAccAWSElasticacheCluster_basic
--- PASS: TestAccAWSElasticacheCluster_basic (809.25s)
PASS
ok github.com/hashicorp/terraform/builtin/providers/aws 809.267s
```
2016-09-23 12:06:19 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:30:15 +02:00
|
|
|
var testAccAWSElasticacheClusterConfig = fmt.Sprintf(`
|
2015-06-01 00:01:07 +02:00
|
|
|
provider "aws" {
|
2015-05-14 20:57:01 +02:00
|
|
|
region = "us-east-1"
|
|
|
|
}
|
2015-04-26 03:53:21 +02:00
|
|
|
resource "aws_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
security_group_names = ["${aws_security_group.bar.name}"]
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:30:15 +02:00
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2016-02-04 18:20:22 +01:00
|
|
|
cluster_id = "tf-%s"
|
2015-04-26 03:53:21 +02:00
|
|
|
engine = "memcached"
|
|
|
|
node_type = "cache.m1.small"
|
|
|
|
num_cache_nodes = 1
|
2015-06-01 00:01:07 +02:00
|
|
|
port = 11211
|
2015-04-26 03:53:21 +02:00
|
|
|
parameter_group_name = "default.memcached1.4"
|
|
|
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
2015-10-31 00:55:00 +01:00
|
|
|
}
|
2016-02-04 18:20:22 +01:00
|
|
|
`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
|
2015-10-31 00:55:00 +01:00
|
|
|
|
2015-11-05 13:23:07 +01:00
|
|
|
var testAccAWSElasticacheClusterConfig_snapshots = `
|
2015-10-31 00:55:00 +01:00
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
resource "aws_security_group" "bar" {
|
2015-11-06 12:16:51 +01:00
|
|
|
name = "tf-test-security-group-%03d"
|
2015-10-31 00:55:00 +01:00
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_security_group" "bar" {
|
2015-11-06 12:16:51 +01:00
|
|
|
name = "tf-test-security-group-%03d"
|
2015-10-31 00:55:00 +01:00
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
security_group_names = ["${aws_security_group.bar.name}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2016-02-04 22:48:54 +01:00
|
|
|
cluster_id = "tf-%s"
|
2015-10-31 00:55:00 +01:00
|
|
|
engine = "redis"
|
2015-11-06 23:55:04 +01:00
|
|
|
node_type = "cache.m1.small"
|
2015-10-31 00:55:00 +01:00
|
|
|
num_cache_nodes = 1
|
|
|
|
port = 6379
|
2016-10-19 16:43:27 +02:00
|
|
|
parameter_group_name = "default.redis3.2"
|
2015-10-31 00:55:00 +01:00
|
|
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
|
|
|
snapshot_window = "05:00-09:00"
|
|
|
|
snapshot_retention_limit = 3
|
2015-04-26 03:53:21 +02:00
|
|
|
}
|
2015-11-05 13:23:07 +01:00
|
|
|
`
|
2015-04-26 03:53:21 +02:00
|
|
|
|
2015-11-05 13:23:07 +01:00
|
|
|
var testAccAWSElasticacheClusterConfig_snapshotsUpdated = `
|
2015-11-03 13:35:06 +01:00
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
resource "aws_security_group" "bar" {
|
2015-11-06 23:55:04 +01:00
|
|
|
name = "tf-test-security-group-%03d"
|
2015-11-03 13:35:06 +01:00
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_security_group" "bar" {
|
2015-11-06 23:55:04 +01:00
|
|
|
name = "tf-test-security-group-%03d"
|
2015-11-03 13:35:06 +01:00
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
security_group_names = ["${aws_security_group.bar.name}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2016-02-04 22:48:54 +01:00
|
|
|
cluster_id = "tf-%s"
|
2015-11-03 13:35:06 +01:00
|
|
|
engine = "redis"
|
|
|
|
node_type = "cache.m1.small"
|
|
|
|
num_cache_nodes = 1
|
|
|
|
port = 6379
|
2016-10-19 16:43:27 +02:00
|
|
|
parameter_group_name = "default.redis3.2"
|
2015-11-03 13:35:06 +01:00
|
|
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
|
|
|
snapshot_window = "07:00-09:00"
|
|
|
|
snapshot_retention_limit = 7
|
2015-11-05 13:23:07 +01:00
|
|
|
apply_immediately = true
|
2015-11-03 13:35:06 +01:00
|
|
|
}
|
2015-11-05 13:23:07 +01:00
|
|
|
`
|
2015-11-03 13:35:06 +01:00
|
|
|
|
2015-11-06 18:36:26 +01:00
|
|
|
var testAccAWSElasticacheClusterConfigDecreasingNodes = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
resource "aws_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
security_group_names = ["${aws_security_group.bar.name}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2016-02-04 22:48:54 +01:00
|
|
|
cluster_id = "tf-%s"
|
2015-11-06 18:36:26 +01:00
|
|
|
engine = "memcached"
|
|
|
|
node_type = "cache.m1.small"
|
|
|
|
num_cache_nodes = 3
|
|
|
|
port = 11211
|
|
|
|
parameter_group_name = "default.memcached1.4"
|
|
|
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAWSElasticacheClusterConfigDecreasingNodes_update = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
resource "aws_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
security_group_names = ["${aws_security_group.bar.name}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2016-02-04 22:48:54 +01:00
|
|
|
cluster_id = "tf-%s"
|
2015-11-06 18:36:26 +01:00
|
|
|
engine = "memcached"
|
|
|
|
node_type = "cache.m1.small"
|
|
|
|
num_cache_nodes = 1
|
|
|
|
port = 11211
|
|
|
|
parameter_group_name = "default.memcached1.4"
|
|
|
|
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
|
|
|
|
apply_immediately = true
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2015-04-28 18:30:15 +02:00
|
|
|
var testAccAWSElasticacheClusterInVPCConfig = fmt.Sprintf(`
|
2015-04-26 03:53:21 +02:00
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "192.168.0.0/16"
|
|
|
|
tags {
|
|
|
|
Name = "tf-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "foo" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
cidr_block = "192.168.0.0/20"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
tags {
|
|
|
|
Name = "tf-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_subnet_group" "bar" {
|
|
|
|
name = "tf-test-cache-subnet-%03d"
|
|
|
|
description = "tf-test-cache-subnet-group-descr"
|
|
|
|
subnet_ids = ["${aws_subnet.foo.id}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:30:15 +02:00
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2015-09-15 01:50:53 +02:00
|
|
|
// Including uppercase letters in this name to ensure
|
|
|
|
// that we correctly handle the fact that the API
|
|
|
|
// normalizes names to lowercase.
|
2016-02-04 18:20:22 +01:00
|
|
|
cluster_id = "tf-%s"
|
2015-04-26 03:53:21 +02:00
|
|
|
node_type = "cache.m1.small"
|
|
|
|
num_cache_nodes = 1
|
|
|
|
engine = "redis"
|
|
|
|
engine_version = "2.8.19"
|
|
|
|
port = 6379
|
|
|
|
subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
|
|
|
|
security_group_ids = ["${aws_security_group.bar.id}"]
|
|
|
|
parameter_group_name = "default.redis2.8"
|
2015-10-28 20:09:45 +01:00
|
|
|
notification_topic_arn = "${aws_sns_topic.topic_example.arn}"
|
2016-01-11 15:33:21 +01:00
|
|
|
availability_zone = "us-west-2a"
|
2015-10-28 20:09:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_sns_topic" "topic_example" {
|
|
|
|
name = "tf-ecache-cluster-test"
|
2015-04-26 03:53:21 +02:00
|
|
|
}
|
2016-02-04 18:20:22 +01:00
|
|
|
`, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
|
2016-01-11 15:45:07 +01:00
|
|
|
|
|
|
|
var testAccAWSElasticacheClusterMultiAZInVPCConfig = fmt.Sprintf(`
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "192.168.0.0/16"
|
|
|
|
tags {
|
|
|
|
Name = "tf-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "foo" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
cidr_block = "192.168.0.0/20"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
tags {
|
|
|
|
Name = "tf-test-%03d"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "bar" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
cidr_block = "192.168.16.0/20"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
tags {
|
|
|
|
Name = "tf-test-%03d"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_subnet_group" "bar" {
|
|
|
|
name = "tf-test-cache-subnet-%03d"
|
|
|
|
description = "tf-test-cache-subnet-group-descr"
|
|
|
|
subnet_ids = [
|
|
|
|
"${aws_subnet.foo.id}",
|
|
|
|
"${aws_subnet.bar.id}"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "bar" {
|
|
|
|
name = "tf-test-security-group-%03d"
|
|
|
|
description = "tf-test-security-group-descr"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
ingress {
|
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
|
|
|
protocol = "icmp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elasticache_cluster" "bar" {
|
2016-02-04 18:20:22 +01:00
|
|
|
cluster_id = "tf-%s"
|
2016-01-11 15:45:07 +01:00
|
|
|
engine = "memcached"
|
|
|
|
node_type = "cache.m1.small"
|
|
|
|
num_cache_nodes = 2
|
|
|
|
port = 11211
|
|
|
|
subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
|
|
|
|
security_group_ids = ["${aws_security_group.bar.id}"]
|
|
|
|
parameter_group_name = "default.memcached1.4"
|
|
|
|
az_mode = "cross-az"
|
|
|
|
availability_zones = [
|
|
|
|
"us-west-2a",
|
|
|
|
"us-west-2b"
|
|
|
|
]
|
|
|
|
}
|
2016-02-04 18:20:22 +01:00
|
|
|
`, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
|