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:
parent
ccb6cefca9
commit
268f935386
|
@ -3,6 +3,7 @@ package aws
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/aws-sdk-go/aws"
|
"github.com/hashicorp/aws-sdk-go/aws"
|
||||||
|
@ -87,12 +88,23 @@ func resourceAwsDbSubnetGroupRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(describeResp.DBSubnetGroups) != 1 ||
|
if len(describeResp.DBSubnetGroups) == 0 {
|
||||||
*describeResp.DBSubnetGroups[0].DBSubnetGroupName != d.Id() {
|
|
||||||
return fmt.Errorf("Unable to find DB Subnet Group: %#v", describeResp.DBSubnetGroups)
|
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("name", *subnetGroup.DBSubnetGroupName)
|
||||||
d.Set("description", *subnetGroup.DBSubnetGroupDescription)
|
d.Set("description", *subnetGroup.DBSubnetGroupDescription)
|
||||||
|
|
|
@ -103,16 +103,22 @@ resource "aws_subnet" "foo" {
|
||||||
cidr_block = "10.1.1.0/24"
|
cidr_block = "10.1.1.0/24"
|
||||||
availability_zone = "us-west-2a"
|
availability_zone = "us-west-2a"
|
||||||
vpc_id = "${aws_vpc.foo.id}"
|
vpc_id = "${aws_vpc.foo.id}"
|
||||||
|
tags {
|
||||||
|
Name = "tf-dbsubnet-test-1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "bar" {
|
resource "aws_subnet" "bar" {
|
||||||
cidr_block = "10.1.2.0/24"
|
cidr_block = "10.1.2.0/24"
|
||||||
availability_zone = "us-west-2b"
|
availability_zone = "us-west-2b"
|
||||||
vpc_id = "${aws_vpc.foo.id}"
|
vpc_id = "${aws_vpc.foo.id}"
|
||||||
|
tags {
|
||||||
|
Name = "tf-dbsubnet-test-2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_db_subnet_group" "foo" {
|
resource "aws_db_subnet_group" "foo" {
|
||||||
name = "foo"
|
name = "FOO"
|
||||||
description = "foo description"
|
description = "foo description"
|
||||||
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
|
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue