diff --git a/builtin/providers/aws/resource_aws_db_subnet_group.go b/builtin/providers/aws/resource_aws_db_subnet_group.go index a7bbc7b47..1c1b49a71 100644 --- a/builtin/providers/aws/resource_aws_db_subnet_group.go +++ b/builtin/providers/aws/resource_aws_db_subnet_group.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strings" "time" "github.com/hashicorp/aws-sdk-go/aws" @@ -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) diff --git a/builtin/providers/aws/resource_aws_db_subnet_group_test.go b/builtin/providers/aws/resource_aws_db_subnet_group_test.go index 2bee3a3ff..dd4b2d58f 100644 --- a/builtin/providers/aws/resource_aws_db_subnet_group_test.go +++ b/builtin/providers/aws/resource_aws_db_subnet_group_test.go @@ -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}"] }