2015-04-26 03:53:21 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/awslabs/aws-sdk-go/aws"
|
|
|
|
"github.com/awslabs/aws-sdk-go/service/elasticache"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-05-06 15:33:05 +02:00
|
|
|
func TestAccAWSElasticacheSubnetGroup(t *testing.T) {
|
2015-04-26 03:53:21 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
2015-05-06 15:33:05 +02:00
|
|
|
CheckDestroy: testAccCheckAWSElasticacheSubnetGroupDestroy,
|
2015-04-26 03:53:21 +02:00
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2015-05-06 15:33:05 +02:00
|
|
|
Config: testAccAWSElasticacheSubnetGroupConfig,
|
2015-04-26 03:53:21 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2015-05-06 15:33:05 +02:00
|
|
|
testAccCheckAWSElasticacheSubnetGroupExists("aws_elasticache_subnet_group.bar"),
|
2015-04-26 03:53:21 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-06 15:33:05 +02:00
|
|
|
func testAccCheckAWSElasticacheSubnetGroupDestroy(s *terraform.State) error {
|
2015-04-26 03:53:21 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_elasticache_subnet_group" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
res, err := conn.DescribeCacheSubnetGroups(&elasticache.DescribeCacheSubnetGroupsInput{
|
|
|
|
CacheSubnetGroupName: aws.String(rs.Primary.ID),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(res.CacheSubnetGroups) > 0 {
|
|
|
|
return fmt.Errorf("still exist.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-06 15:33:05 +02:00
|
|
|
func testAccCheckAWSElasticacheSubnetGroupExists(n string) 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 subnet group ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
|
|
|
|
_, err := conn.DescribeCacheSubnetGroups(&elasticache.DescribeCacheSubnetGroupsInput{
|
|
|
|
CacheSubnetGroupName: aws.String(rs.Primary.ID),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("CacheSubnetGroup error: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 15:33:05 +02:00
|
|
|
var testAccAWSElasticacheSubnetGroupConfig = fmt.Sprintf(`
|
2015-04-26 03:53:21 +02:00
|
|
|
resource "aws_vpc" "foo" {
|
2015-05-06 20:44:24 +02:00
|
|
|
cidr_block = "192.168.0.0/16"
|
2015-04-26 03:53:21 +02:00
|
|
|
tags {
|
|
|
|
Name = "tf-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "foo" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
2015-05-06 20:44:24 +02:00
|
|
|
cidr_block = "192.168.0.0/20"
|
2015-04-26 03:53:21 +02:00
|
|
|
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}"]
|
|
|
|
}
|
|
|
|
`, genRandInt())
|