rds: add attribute checks
This commit is contained in:
parent
dc0ec11ec9
commit
b924151914
|
@ -281,8 +281,6 @@ func resource_aws_db_instance_retrieve(id string, conn *rds.Rds) (*rds.DBInstanc
|
||||||
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)
|
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("resp: %#v", resp.DBInstances)
|
|
||||||
|
|
||||||
if len(resp.DBInstances) != 1 ||
|
if len(resp.DBInstances) != 1 ||
|
||||||
resp.DBInstances[0].DBInstanceIdentifier != id {
|
resp.DBInstances[0].DBInstanceIdentifier != id {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -23,7 +23,25 @@ func TestAccAWSDBInstance(t *testing.T) {
|
||||||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
||||||
testAccCheckAWSDBInstanceAttributes(&v),
|
testAccCheckAWSDBInstanceAttributes(&v),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_db_instance.bar", "instance_identifier", "some_name"),
|
"aws_db_instance.bar", "instance_identifier", "foobarbaz-test-terraform"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "allocated_storage", "foobarbaz-test-terraform"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "engine", "mysql"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "engine_version", "5.6.17"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "instance_class", "db.t1.micro"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "name", "baz"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "password", "barbarbarbar"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "username", "foo"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "skip_final_snapshot", "true"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_db_instance.bar", "security_group_names.0", "secfoobarbaz-test-terraform"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -64,10 +82,20 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckAWSDBInstanceAttributes(group *rds.DBInstance) resource.TestCheckFunc {
|
func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
// check attrs
|
if len(v.DBSecurityGroupNames) == 0 {
|
||||||
|
return fmt.Errorf("no sec names: %#v", v.DBSecurityGroupNames)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Engine != "mysql" {
|
||||||
|
return fmt.Errorf("bad engine: %#v", v.Engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Engine != "5.6.17" {
|
||||||
|
return fmt.Errorf("bad engine_version: %#v", v.Engine)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -108,9 +136,8 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccAWSDBInstanceConfig = `
|
const testAccAWSDBInstanceConfig = `
|
||||||
|
|
||||||
resource "aws_db_security_group" "bar" {
|
resource "aws_db_security_group" "bar" {
|
||||||
name = "secgrouplol"
|
name = "secfoobarbaz-test-terraform"
|
||||||
description = "just cuz"
|
description = "just cuz"
|
||||||
|
|
||||||
ingress {
|
ingress {
|
||||||
|
@ -119,11 +146,11 @@ resource "aws_db_security_group" "bar" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_db_instance" "bar" {
|
resource "aws_db_instance" "bar" {
|
||||||
identifier = "foobarbaz-test-terraform-2"
|
identifier = "foobarbaz-test-terraform"
|
||||||
|
|
||||||
allocated_storage = 10
|
allocated_storage = 10
|
||||||
engine = "mysql"
|
engine = "mysql"
|
||||||
engine_version = "5.6.13"
|
engine_version = "5.6.17"
|
||||||
instance_class = "db.t1.micro"
|
instance_class = "db.t1.micro"
|
||||||
name = "baz"
|
name = "baz"
|
||||||
password = "barbarbarbar"
|
password = "barbarbarbar"
|
||||||
|
|
|
@ -193,8 +193,6 @@ func resource_aws_db_security_group_retrieve(id string, conn *rds.Rds) (*rds.DBS
|
||||||
return nil, fmt.Errorf("Error retrieving DB Security Groups: %s", err)
|
return nil, fmt.Errorf("Error retrieving DB Security Groups: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("resp: %#v", resp.DBSecurityGroups)
|
|
||||||
|
|
||||||
if len(resp.DBSecurityGroups) != 1 ||
|
if len(resp.DBSecurityGroups) != 1 ||
|
||||||
resp.DBSecurityGroups[0].Name != id {
|
resp.DBSecurityGroups[0].Name != id {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue