Merge pull request #1067 from hashicorp/aws-go-db-subnet

provider/aws: convert aws rds subnet to aws-sdk-go
This commit is contained in:
Clint 2015-02-27 10:50:21 -06:00
commit a222eb183b
3 changed files with 37 additions and 28 deletions

View File

@ -197,9 +197,7 @@ func resourceAwsDbSecurityGroupRetrieve(d *schema.ResourceData, meta interface{}
if len(resp.DBSecurityGroups) != 1 ||
*resp.DBSecurityGroups[0].DBSecurityGroupName != d.Id() {
if err != nil {
return nil, fmt.Errorf("Unable to find DB Security Group: %#v", resp.DBSecurityGroups)
}
return nil, fmt.Errorf("Unable to find DB Security Group: %#v", resp.DBSecurityGroups)
}
v := resp.DBSecurityGroups[0]

View File

@ -5,10 +5,11 @@ import (
"log"
"time"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/rds"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/goamz/rds"
)
func resourceAwsDbSubnetGroup() *schema.Resource {
@ -44,7 +45,7 @@ func resourceAwsDbSubnetGroup() *schema.Resource {
}
func resourceAwsDbSubnetGroupCreate(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn
rdsconn := meta.(*AWSClient).awsRDSconn
subnetIdsSet := d.Get("subnet_ids").(*schema.Set)
subnetIds := make([]string, subnetIdsSet.Len())
@ -52,10 +53,10 @@ func resourceAwsDbSubnetGroupCreate(d *schema.ResourceData, meta interface{}) er
subnetIds[i] = subnetId.(string)
}
createOpts := rds.CreateDBSubnetGroup{
DBSubnetGroupName: d.Get("name").(string),
DBSubnetGroupDescription: d.Get("description").(string),
SubnetIds: subnetIds,
createOpts := rds.CreateDBSubnetGroupMessage{
DBSubnetGroupName: aws.String(d.Get("name").(string)),
DBSubnetGroupDescription: aws.String(d.Get("description").(string)),
SubnetIDs: subnetIds,
}
log.Printf("[DEBUG] Create DB Subnet Group: %#v", createOpts)
@ -64,16 +65,16 @@ func resourceAwsDbSubnetGroupCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error creating DB Subnet Group: %s", err)
}
d.SetId(createOpts.DBSubnetGroupName)
d.SetId(*createOpts.DBSubnetGroupName)
log.Printf("[INFO] DB Subnet Group ID: %s", d.Id())
return resourceAwsDbSubnetGroupRead(d, meta)
}
func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) error {
rdsconn := meta.(*AWSClient).rdsconn
rdsconn := meta.(*AWSClient).awsRDSconn
describeOpts := rds.DescribeDBSubnetGroups{
DBSubnetGroupName: d.Id(),
describeOpts := rds.DescribeDBSubnetGroupsMessage{
DBSubnetGroupName: aws.String(d.Id()),
}
describeResp, err := rdsconn.DescribeDBSubnetGroups(&describeOpts)
@ -82,12 +83,20 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro
}
if len(describeResp.DBSubnetGroups) != 1 ||
describeResp.DBSubnetGroups[0].Name != d.Id() {
*describeResp.DBSubnetGroups[0].DBSubnetGroupName != d.Id() {
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
}
d.Set("name", describeResp.DBSubnetGroups[0].Name)
d.Set("description", describeResp.DBSubnetGroups[0].Description)
d.Set("subnet_ids", describeResp.DBSubnetGroups[0].SubnetIds)
subnetGroup := describeResp.DBSubnetGroups[0]
d.Set("name", *subnetGroup.DBSubnetGroupName)
d.Set("description", *subnetGroup.DBSubnetGroupDescription)
subnets := make([]string, 0, len(subnetGroup.Subnets))
for _, s := range subnetGroup.Subnets {
subnets = append(subnets, *s.SubnetIdentifier)
}
d.Set("subnet_ids", subnets)
return nil
}
@ -107,16 +116,16 @@ func resourceAwsDbSubnetGroupDelete(d *schema.ResourceData, meta interface{}) er
func resourceAwsDbSubnetGroupDeleteRefreshFunc(
d *schema.ResourceData,
meta interface{}) resource.StateRefreshFunc {
rdsconn := meta.(*AWSClient).rdsconn
rdsconn := meta.(*AWSClient).awsRDSconn
return func() (interface{}, string, error) {
deleteOpts := rds.DeleteDBSubnetGroup{
DBSubnetGroupName: d.Id(),
deleteOpts := rds.DeleteDBSubnetGroupMessage{
DBSubnetGroupName: aws.String(d.Id()),
}
if _, err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil {
rdserr, ok := err.(*rds.Error)
if err := rdsconn.DeleteDBSubnetGroup(&deleteOpts); err != nil {
rdserr, ok := err.(aws.APIError)
if !ok {
return d, "error", err
}

View File

@ -6,7 +6,9 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/rds"
"github.com/hashicorp/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/rds"
)
func TestAccAWSDBSubnetGroup(t *testing.T) {
@ -34,7 +36,7 @@ func TestAccAWSDBSubnetGroup(t *testing.T) {
}
func testAccCheckDBSubnetGroupDestroy(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_subnet_group" {
@ -43,7 +45,7 @@ func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
// Try to find the resource
resp, err := conn.DescribeDBSubnetGroups(
&rds.DescribeDBSubnetGroups{DBSubnetGroupName: rs.Primary.ID})
&rds.DescribeDBSubnetGroupsMessage{DBSubnetGroupName: aws.String(rs.Primary.ID)})
if err == nil {
if len(resp.DBSubnetGroups) > 0 {
return fmt.Errorf("still exist.")
@ -53,7 +55,7 @@ func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
}
// Verify the error is what we want
rdserr, ok := err.(*rds.Error)
rdserr, ok := err.(aws.APIError)
if !ok {
return err
}
@ -76,9 +78,9 @@ func testAccCheckDBSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.Te
return fmt.Errorf("No ID is set")
}
conn := testAccProvider.Meta().(*AWSClient).rdsconn
conn := testAccProvider.Meta().(*AWSClient).awsRDSconn
resp, err := conn.DescribeDBSubnetGroups(
&rds.DescribeDBSubnetGroups{DBSubnetGroupName: rs.Primary.ID})
&rds.DescribeDBSubnetGroupsMessage{DBSubnetGroupName: aws.String(rs.Primary.ID)})
if err != nil {
return err
}