provider/aws: Fix issue finding db subnets

AWS seems to lower case DB Subnet Group names, causing a failure in TF if your
name isn't all lower case.
This commit is contained in:
Clint Shryock 2015-04-03 09:19:20 -05:00
parent ccb6cefca9
commit 268f935386
2 changed files with 22 additions and 4 deletions

View File

@ -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)

View File

@ -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}"]
}