Skip to content

Commit

Permalink
Merge pull request #1377 from hashicorp/b-aws-fix-db-subnet-group-check
Browse files Browse the repository at this point in the history
provider/aws: Fix issue finding db subnets
  • Loading branch information
catsby committed Apr 3, 2015
2 parents ccb6cef + 268f935 commit 0cff04a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 15 additions & 3 deletions builtin/providers/aws/resource_aws_db_subnet_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/aws-sdk-go/aws"
Expand Down Expand Up @@ -87,12 +88,23 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro
return err
}

if len(describeResp.DBSubnetGroups) != 1 ||
*describeResp.DBSubnetGroups[0].DBSubnetGroupName != d.Id() {
if len(describeResp.DBSubnetGroups) == 0 {
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
}

subnetGroup := describeResp.DBSubnetGroups[0]
var subnetGroup rds.DBSubnetGroup
for _, s := range describeResp.DBSubnetGroups {
// AWS is down casing the name provided, so we compare lower case versions
// of the names. We lower case both our name and their name in the check,
// incase they change that someday.
if strings.ToLower(d.Id()) == strings.ToLower(*s.DBSubnetGroupName) {
subnetGroup = describeResp.DBSubnetGroups[0]
}
}

if subnetGroup.DBSubnetGroupName == nil {
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
}

d.Set("name", *subnetGroup.DBSubnetGroupName)
d.Set("description", *subnetGroup.DBSubnetGroupDescription)
Expand Down
8 changes: 7 additions & 1 deletion builtin/providers/aws/resource_aws_db_subnet_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,22 @@ resource "aws_subnet" "foo" {
cidr_block = "10.1.1.0/24"
availability_zone = "us-west-2a"
vpc_id = "${aws_vpc.foo.id}"
tags {
Name = "tf-dbsubnet-test-1"
}
}
resource "aws_subnet" "bar" {
cidr_block = "10.1.2.0/24"
availability_zone = "us-west-2b"
vpc_id = "${aws_vpc.foo.id}"
tags {
Name = "tf-dbsubnet-test-2"
}
}
resource "aws_db_subnet_group" "foo" {
name = "foo"
name = "FOO"
description = "foo description"
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
}
Expand Down

0 comments on commit 0cff04a

Please sign in to comment.