Merge pull request #11827 from hashicorp/f-redshift-sg-acctests

provider/aws: Update Redshift SG Acctests
This commit is contained in:
Jake Champlin 2017-02-09 11:19:44 -05:00 committed by GitHub
commit 057341acf8
2 changed files with 204 additions and 187 deletions

View File

@ -4,6 +4,7 @@ import (
"os"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
@ -11,6 +12,7 @@ func TestAccAWSRedshiftSecurityGroup_importBasic(t *testing.T) {
oldvar := os.Getenv("AWS_DEFAULT_REGION")
os.Setenv("AWS_DEFAULT_REGION", "us-east-1")
defer os.Setenv("AWS_DEFAULT_REGION", oldvar)
rInt := acctest.RandInt()
resourceName := "aws_redshift_security_group.bar"
@ -19,11 +21,11 @@ func TestAccAWSRedshiftSecurityGroup_importBasic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidr,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidr(rInt),
},
resource.TestStep{
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,

View File

@ -7,24 +7,26 @@ import (
"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"
)
func TestAccAWSRedshiftSecurityGroup_ingressCidr(t *testing.T) {
var v redshift.ClusterSecurityGroup
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidr,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidr(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
"aws_redshift_security_group.bar", "name", "redshift-sg-terraform"),
"aws_redshift_security_group.bar", "name", fmt.Sprintf("redshift-sg-terraform-%d", rInt)),
resource.TestCheckResourceAttr(
"aws_redshift_security_group.bar", "description", "Managed by Terraform"),
resource.TestCheckResourceAttr(
@ -39,14 +41,15 @@ func TestAccAWSRedshiftSecurityGroup_ingressCidr(t *testing.T) {
func TestAccAWSRedshiftSecurityGroup_updateIngressCidr(t *testing.T) {
var v redshift.ClusterSecurityGroup
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidr,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidr(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
@ -54,8 +57,8 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressCidr(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidrAdd,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidrAdd(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
@ -63,8 +66,8 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressCidr(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidrReduce,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressCidrReduce(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
@ -77,24 +80,23 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressCidr(t *testing.T) {
func TestAccAWSRedshiftSecurityGroup_ingressSecurityGroup(t *testing.T) {
var v redshift.ClusterSecurityGroup
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgId,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgId(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
"aws_redshift_security_group.bar", "name", "redshift-sg-terraform"),
"aws_redshift_security_group.bar", "name", fmt.Sprintf("redshift-sg-terraform-%d", rInt)),
resource.TestCheckResourceAttr(
"aws_redshift_security_group.bar", "description", "this is a description"),
resource.TestCheckResourceAttr(
"aws_redshift_security_group.bar", "ingress.#", "1"),
resource.TestCheckResourceAttr(
"aws_redshift_security_group.bar", "ingress.2230908922.security_group_name", "terraform_redshift_acceptance_test"),
),
},
},
@ -103,14 +105,15 @@ func TestAccAWSRedshiftSecurityGroup_ingressSecurityGroup(t *testing.T) {
func TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup(t *testing.T) {
var v redshift.ClusterSecurityGroup
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRedshiftSecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgId,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgId(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
@ -118,8 +121,8 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgIdAdd,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgIdAdd(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
@ -127,8 +130,8 @@ func TestAccAWSRedshiftSecurityGroup_updateIngressSecurityGroup(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgIdReduce,
{
Config: testAccAWSRedshiftSecurityGroupConfig_ingressSgIdReduce(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftSecurityGroupExists("aws_redshift_security_group.bar", &v),
resource.TestCheckResourceAttr(
@ -239,26 +242,29 @@ func TestResourceAWSRedshiftSecurityGroupNameValidation(t *testing.T) {
}
}
const testAccAWSRedshiftSecurityGroupConfig_ingressCidr = `
func testAccAWSRedshiftSecurityGroupConfig_ingressCidr(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_redshift_security_group" "bar" {
name = "redshift-sg-terraform"
name = "redshift-sg-terraform-%d"
ingress {
cidr = "10.0.0.1/24"
}
}`
}`, rInt)
}
const testAccAWSRedshiftSecurityGroupConfig_ingressCidrAdd = `
func testAccAWSRedshiftSecurityGroupConfig_ingressCidrAdd(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_redshift_security_group" "bar" {
name = "redshift-sg-terraform"
name = "redshift-sg-terraform-%d"
description = "this is a description"
ingress {
@ -272,15 +278,17 @@ resource "aws_redshift_security_group" "bar" {
ingress {
cidr = "10.0.20.1/24"
}
}`
}`, rInt)
}
const testAccAWSRedshiftSecurityGroupConfig_ingressCidrReduce = `
func testAccAWSRedshiftSecurityGroupConfig_ingressCidrReduce(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_redshift_security_group" "bar" {
name = "redshift-sg-terraform"
name = "redshift-sg-terraform-%d"
description = "this is a description"
ingress {
@ -290,15 +298,17 @@ resource "aws_redshift_security_group" "bar" {
ingress {
cidr = "10.0.10.1/24"
}
}`
}`, rInt)
}
const testAccAWSRedshiftSecurityGroupConfig_ingressSgId = `
func testAccAWSRedshiftSecurityGroupConfig_ingressSgId(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "redshift" {
name = "terraform_redshift_acceptance_test"
name = "terraform_redshift_test_%d"
description = "Used in the redshift acceptance tests"
ingress {
@ -310,22 +320,24 @@ resource "aws_security_group" "redshift" {
}
resource "aws_redshift_security_group" "bar" {
name = "redshift-sg-terraform"
name = "redshift-sg-terraform-%d"
description = "this is a description"
ingress {
security_group_name = "${aws_security_group.redshift.name}"
security_group_owner_id = "${aws_security_group.redshift.owner_id}"
}
}`
}`, rInt, rInt)
}
const testAccAWSRedshiftSecurityGroupConfig_ingressSgIdAdd = `
func testAccAWSRedshiftSecurityGroupConfig_ingressSgIdAdd(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "redshift" {
name = "terraform_redshift_acceptance_test"
name = "terraform_redshift_test_%d"
description = "Used in the redshift acceptance tests"
ingress {
@ -337,7 +349,7 @@ resource "aws_security_group" "redshift" {
}
resource "aws_security_group" "redshift2" {
name = "terraform_redshift_acceptance_test_2"
name = "terraform_redshift_test_2_%d"
description = "Used in the redshift acceptance tests #2"
ingress {
@ -349,7 +361,7 @@ resource "aws_security_group" "redshift2" {
}
resource "aws_security_group" "redshift3" {
name = "terraform_redshift_acceptance_test_3"
name = "terraform_redshift_test_3_%d"
description = "Used in the redshift acceptance tests #3"
ingress {
@ -361,7 +373,7 @@ resource "aws_security_group" "redshift3" {
}
resource "aws_redshift_security_group" "bar" {
name = "redshift-sg-terraform"
name = "redshift-sg-terraform-%d"
description = "this is a description"
ingress {
@ -378,15 +390,17 @@ resource "aws_redshift_security_group" "bar" {
security_group_name = "${aws_security_group.redshift3.name}"
security_group_owner_id = "${aws_security_group.redshift.owner_id}"
}
}`
}`, rInt, rInt, rInt, rInt)
}
const testAccAWSRedshiftSecurityGroupConfig_ingressSgIdReduce = `
func testAccAWSRedshiftSecurityGroupConfig_ingressSgIdReduce(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "redshift" {
name = "terraform_redshift_acceptance_test"
name = "terraform_redshift_test_%d"
description = "Used in the redshift acceptance tests"
ingress {
@ -398,7 +412,7 @@ resource "aws_security_group" "redshift" {
}
resource "aws_security_group" "redshift2" {
name = "terraform_redshift_acceptance_test_2"
name = "terraform_redshift_test_2_%d"
description = "Used in the redshift acceptance tests #2"
ingress {
@ -410,7 +424,7 @@ resource "aws_security_group" "redshift2" {
}
resource "aws_redshift_security_group" "bar" {
name = "redshift-sg-terraform"
name = "redshift-sg-terraform-%d"
description = "this is a description"
ingress {
@ -422,4 +436,5 @@ resource "aws_redshift_security_group" "bar" {
security_group_name = "${aws_security_group.redshift2.name}"
security_group_owner_id = "${aws_security_group.redshift.owner_id}"
}
}`
}`, rInt, rInt, rInt)
}