From b92415191439a3156c05a3dce858e8737a58111a Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Tue, 22 Jul 2014 22:54:10 -0400 Subject: [PATCH] rds: add attribute checks --- .../providers/aws/resource_aws_db_instance.go | 2 - .../aws/resource_aws_db_instance_test.go | 41 +++++++++++++++---- .../aws/resource_aws_db_security_group.go | 2 - 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/builtin/providers/aws/resource_aws_db_instance.go b/builtin/providers/aws/resource_aws_db_instance.go index 763aebc37..e6c78f4fd 100644 --- a/builtin/providers/aws/resource_aws_db_instance.go +++ b/builtin/providers/aws/resource_aws_db_instance.go @@ -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) } - log.Printf("resp: %#v", resp.DBInstances) - if len(resp.DBInstances) != 1 || resp.DBInstances[0].DBInstanceIdentifier != id { if err != nil { diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index ebd8781e8..44fa1a4de 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -23,7 +23,25 @@ func TestAccAWSDBInstance(t *testing.T) { testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v), testAccCheckAWSDBInstanceAttributes(&v), 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 } -func testAccCheckAWSDBInstanceAttributes(group *rds.DBInstance) resource.TestCheckFunc { +func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFunc { 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 } @@ -108,9 +136,8 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC } const testAccAWSDBInstanceConfig = ` - resource "aws_db_security_group" "bar" { - name = "secgrouplol" + name = "secfoobarbaz-test-terraform" description = "just cuz" ingress { @@ -119,11 +146,11 @@ resource "aws_db_security_group" "bar" { } resource "aws_db_instance" "bar" { - identifier = "foobarbaz-test-terraform-2" + identifier = "foobarbaz-test-terraform" allocated_storage = 10 engine = "mysql" - engine_version = "5.6.13" + engine_version = "5.6.17" instance_class = "db.t1.micro" name = "baz" password = "barbarbarbar" diff --git a/builtin/providers/aws/resource_aws_db_security_group.go b/builtin/providers/aws/resource_aws_db_security_group.go index c00fdd2df..72be35b4c 100644 --- a/builtin/providers/aws/resource_aws_db_security_group.go +++ b/builtin/providers/aws/resource_aws_db_security_group.go @@ -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) } - log.Printf("resp: %#v", resp.DBSecurityGroups) - if len(resp.DBSecurityGroups) != 1 || resp.DBSecurityGroups[0].Name != id { if err != nil {