Merge pull request #11833 from hashicorp/f-redshift-cluster-acctests

provider/aws: Update redshift_cluster acceptance tests
This commit is contained in:
Jake Champlin 2017-02-09 16:20:52 -05:00 committed by GitHub
commit 3b372b649b

View File

@ -3,15 +3,16 @@ package aws
import (
"fmt"
"math/rand"
"regexp"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/redshift"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"regexp"
)
func TestValidateRedshiftClusterDbName(t *testing.T) {
@ -136,10 +137,7 @@ func TestAccAWSRedshiftCluster_enhancedVpcRoutingEnabled(t *testing.T) {
func TestAccAWSRedshiftCluster_loggingEnabled(t *testing.T) {
var v redshift.Cluster
ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_loggingEnabled, ri)
postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_loggingDisabled, ri)
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -147,18 +145,18 @@ func TestAccAWSRedshiftCluster_loggingEnabled(t *testing.T) {
CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Config: testAccAWSRedshiftClusterConfig_loggingEnabled(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "enable_logging", "true"),
resource.TestCheckResourceAttr(
"aws_redshift_cluster.default", "bucket_name", "tf-redshift-logging-test-bucket"),
"aws_redshift_cluster.default", "bucket_name", fmt.Sprintf("tf-redshift-logging-%d", rInt)),
),
},
{
Config: postConfig,
Config: testAccAWSRedshiftClusterConfig_loggingDisabled(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
@ -204,10 +202,7 @@ func TestAccAWSRedshiftCluster_iamRoles(t *testing.T) {
func TestAccAWSRedshiftCluster_publiclyAccessible(t *testing.T) {
var v redshift.Cluster
ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_notPubliclyAccessible, ri)
postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_updatePubliclyAccessible, ri)
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -215,7 +210,7 @@ func TestAccAWSRedshiftCluster_publiclyAccessible(t *testing.T) {
CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Config: testAccAWSRedshiftClusterConfig_notPubliclyAccessible(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
@ -224,7 +219,7 @@ func TestAccAWSRedshiftCluster_publiclyAccessible(t *testing.T) {
},
{
Config: postConfig,
Config: testAccAWSRedshiftClusterConfig_updatePubliclyAccessible(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
resource.TestCheckResourceAttr(
@ -593,7 +588,8 @@ resource "aws_redshift_cluster" "default" {
}
`
var testAccAWSRedshiftClusterConfig_loggingDisabled = `
func testAccAWSRedshiftClusterConfig_loggingDisabled(rInt int) string {
return fmt.Sprintf(`
resource "aws_redshift_cluster" "default" {
cluster_identifier = "tf-redshift-cluster-%d"
availability_zone = "us-west-2a"
@ -604,12 +600,13 @@ resource "aws_redshift_cluster" "default" {
automated_snapshot_retention_period = 0
allow_version_upgrade = false
enable_logging = false
}`, rInt)
}
`
var testAccAWSRedshiftClusterConfig_loggingEnabled = `
func testAccAWSRedshiftClusterConfig_loggingEnabled(rInt int) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {
bucket = "tf-redshift-logging-test-bucket"
bucket = "tf-redshift-logging-%d"
force_destroy = true
policy = <<EOF
{
@ -622,7 +619,7 @@ resource "aws_s3_bucket" "bucket" {
"AWS": "arn:aws:iam::902366379725:user/logs"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket/*"
"Resource": "arn:aws:s3:::tf-redshift-logging-%d/*"
},
{
"Sid": "Stmt137652664067",
@ -631,7 +628,7 @@ resource "aws_s3_bucket" "bucket" {
"AWS": "arn:aws:iam::902366379725:user/logs"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket"
"Resource": "arn:aws:s3:::tf-redshift-logging-%d"
}
]
}
@ -649,7 +646,8 @@ resource "aws_redshift_cluster" "default" {
allow_version_upgrade = false
enable_logging = true
bucket_name = "${aws_s3_bucket.bucket.bucket}"
}`
}`, rInt, rInt, rInt, rInt)
}
var testAccAWSRedshiftClusterConfig_tags = `
resource "aws_redshift_cluster" "default" {
@ -683,7 +681,8 @@ resource "aws_redshift_cluster" "default" {
}
}`
var testAccAWSRedshiftClusterConfig_notPubliclyAccessible = `
func testAccAWSRedshiftClusterConfig_notPubliclyAccessible(rInt int) string {
return fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
@ -718,7 +717,7 @@ resource "aws_subnet" "foobar" {
}
}
resource "aws_redshift_subnet_group" "foo" {
name = "foo"
name = "foo-%d"
description = "foo description"
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}", "${aws_subnet.foobar.id}"]
}
@ -733,9 +732,11 @@ resource "aws_redshift_cluster" "default" {
allow_version_upgrade = false
cluster_subnet_group_name = "${aws_redshift_subnet_group.foo.name}"
publicly_accessible = false
}`
}`, rInt, rInt)
}
var testAccAWSRedshiftClusterConfig_updatePubliclyAccessible = `
func testAccAWSRedshiftClusterConfig_updatePubliclyAccessible(rInt int) string {
return fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
@ -770,7 +771,7 @@ resource "aws_subnet" "foobar" {
}
}
resource "aws_redshift_subnet_group" "foo" {
name = "foo"
name = "foo-%d"
description = "foo description"
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}", "${aws_subnet.foobar.id}"]
}
@ -785,7 +786,8 @@ resource "aws_redshift_cluster" "default" {
allow_version_upgrade = false
cluster_subnet_group_name = "${aws_redshift_subnet_group.foo.name}"
publicly_accessible = true
}`
}`, rInt, rInt)
}
var testAccAWSRedshiftClusterConfig_iamRoles = `
resource "aws_iam_role" "ec2-role" {