provider/aws: Convert db security group test
This commit is contained in:
parent
ac8da7a988
commit
561e92e65d
|
@ -4,9 +4,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
|
"github.com/hashicorp/aws-sdk-go/gen/rds"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/goamz/rds"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAWSDBSecurityGroup(t *testing.T) {
|
func TestAccAWSDBSecurityGroup(t *testing.T) {
|
||||||
|
@ -37,7 +38,7 @@ func TestAccAWSDBSecurityGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
|
func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).awsRDSconn
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
if rs.Type != "aws_db_security_group" {
|
if rs.Type != "aws_db_security_group" {
|
||||||
|
@ -46,19 +47,19 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
// Try to find the Group
|
// Try to find the Group
|
||||||
resp, err := conn.DescribeDBSecurityGroups(
|
resp, err := conn.DescribeDBSecurityGroups(
|
||||||
&rds.DescribeDBSecurityGroups{
|
&rds.DescribeDBSecurityGroupsMessage{
|
||||||
DBSecurityGroupName: rs.Primary.ID,
|
DBSecurityGroupName: aws.String(rs.Primary.ID),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(resp.DBSecurityGroups) != 0 &&
|
if len(resp.DBSecurityGroups) != 0 &&
|
||||||
resp.DBSecurityGroups[0].Name == rs.Primary.ID {
|
*resp.DBSecurityGroups[0].DBSecurityGroupName == rs.Primary.ID {
|
||||||
return fmt.Errorf("DB Security Group still exists")
|
return fmt.Errorf("DB Security Group still exists")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the error
|
// Verify the error
|
||||||
newerr, ok := err.(*rds.Error)
|
newerr, ok := err.(aws.APIError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -72,24 +73,25 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
|
||||||
|
|
||||||
func testAccCheckAWSDBSecurityGroupAttributes(group *rds.DBSecurityGroup) resource.TestCheckFunc {
|
func testAccCheckAWSDBSecurityGroupAttributes(group *rds.DBSecurityGroup) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
if len(group.CidrIps) == 0 {
|
if len(group.IPRanges) == 0 {
|
||||||
return fmt.Errorf("no cidr: %#v", group.CidrIps)
|
return fmt.Errorf("no cidr: %#v", group.IPRanges)
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.CidrIps[0] != "10.0.0.1/24" {
|
if *group.IPRanges[0].CIDRIP != "10.0.0.1/24" {
|
||||||
return fmt.Errorf("bad cidr: %#v", group.CidrIps)
|
return fmt.Errorf("bad cidr: %#v", group.IPRanges)
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.CidrStatuses[0] != "authorized" {
|
ipSt := flattenIPRangeStatuses(group.IPRanges)
|
||||||
return fmt.Errorf("bad status: %#v", group.CidrStatuses)
|
if ipSt[0] != "authorized" {
|
||||||
|
return fmt.Errorf("bad status: %#v", ipSt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.Name != "secgroup-terraform" {
|
if *group.DBSecurityGroupName != "secgroup-terraform" {
|
||||||
return fmt.Errorf("bad name: %#v", group.Name)
|
return fmt.Errorf("bad name: %#v", *group.DBSecurityGroupName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.Description != "just cuz" {
|
if *group.DBSecurityGroupDescription != "just cuz" {
|
||||||
return fmt.Errorf("bad description: %#v", group.Description)
|
return fmt.Errorf("bad description: %#v", *group.DBSecurityGroupDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -107,10 +109,10 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
|
||||||
return fmt.Errorf("No DB Security Group ID is set")
|
return fmt.Errorf("No DB Security Group ID is set")
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
conn := testAccProvider.Meta().(*AWSClient).awsRDSconn
|
||||||
|
|
||||||
opts := rds.DescribeDBSecurityGroups{
|
opts := rds.DescribeDBSecurityGroupsMessage{
|
||||||
DBSecurityGroupName: rs.Primary.ID,
|
DBSecurityGroupName: aws.String(rs.Primary.ID),
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := conn.DescribeDBSecurityGroups(&opts)
|
resp, err := conn.DescribeDBSecurityGroups(&opts)
|
||||||
|
@ -120,7 +122,7 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.DBSecurityGroups) != 1 ||
|
if len(resp.DBSecurityGroups) != 1 ||
|
||||||
resp.DBSecurityGroups[0].Name != rs.Primary.ID {
|
*resp.DBSecurityGroups[0].DBSecurityGroupName != rs.Primary.ID {
|
||||||
return fmt.Errorf("DB Security Group not found")
|
return fmt.Errorf("DB Security Group not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue