provider/aws: Convert db security group test

This commit is contained in:
Clint Shryock 2015-02-26 15:36:38 -06:00
parent ac8da7a988
commit 561e92e65d
1 changed files with 22 additions and 20 deletions

View File

@ -4,9 +4,10 @@ import (
"fmt"
"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/terraform"
"github.com/mitchellh/goamz/rds"
)
func TestAccAWSDBSecurityGroup(t *testing.T) {
@ -37,7 +38,7 @@ func TestAccAWSDBSecurityGroup(t *testing.T) {
}
func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).rdsconn
conn := testAccProvider.Meta().(*AWSClient).awsRDSconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_db_security_group" {
@ -46,19 +47,19 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
// Try to find the Group
resp, err := conn.DescribeDBSecurityGroups(
&rds.DescribeDBSecurityGroups{
DBSecurityGroupName: rs.Primary.ID,
&rds.DescribeDBSecurityGroupsMessage{
DBSecurityGroupName: aws.String(rs.Primary.ID),
})
if err == nil {
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")
}
}
// Verify the error
newerr, ok := err.(*rds.Error)
newerr, ok := err.(aws.APIError)
if !ok {
return err
}
@ -72,24 +73,25 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
func testAccCheckAWSDBSecurityGroupAttributes(group *rds.DBSecurityGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
if len(group.CidrIps) == 0 {
return fmt.Errorf("no cidr: %#v", group.CidrIps)
if len(group.IPRanges) == 0 {
return fmt.Errorf("no cidr: %#v", group.IPRanges)
}
if group.CidrIps[0] != "10.0.0.1/24" {
return fmt.Errorf("bad cidr: %#v", group.CidrIps)
if *group.IPRanges[0].CIDRIP != "10.0.0.1/24" {
return fmt.Errorf("bad cidr: %#v", group.IPRanges)
}
if group.CidrStatuses[0] != "authorized" {
return fmt.Errorf("bad status: %#v", group.CidrStatuses)
ipSt := flattenIPRangeStatuses(group.IPRanges)
if ipSt[0] != "authorized" {
return fmt.Errorf("bad status: %#v", ipSt)
}
if group.Name != "secgroup-terraform" {
return fmt.Errorf("bad name: %#v", group.Name)
if *group.DBSecurityGroupName != "secgroup-terraform" {
return fmt.Errorf("bad name: %#v", *group.DBSecurityGroupName)
}
if group.Description != "just cuz" {
return fmt.Errorf("bad description: %#v", group.Description)
if *group.DBSecurityGroupDescription != "just cuz" {
return fmt.Errorf("bad description: %#v", *group.DBSecurityGroupDescription)
}
return nil
@ -107,10 +109,10 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
return fmt.Errorf("No DB Security Group ID is set")
}
conn := testAccProvider.Meta().(*AWSClient).rdsconn
conn := testAccProvider.Meta().(*AWSClient).awsRDSconn
opts := rds.DescribeDBSecurityGroups{
DBSecurityGroupName: rs.Primary.ID,
opts := rds.DescribeDBSecurityGroupsMessage{
DBSecurityGroupName: aws.String(rs.Primary.ID),
}
resp, err := conn.DescribeDBSecurityGroups(&opts)
@ -120,7 +122,7 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
}
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")
}