Skip to content

Commit

Permalink
update read replica acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed May 20, 2015
1 parent dc164c4 commit 6b6aa86
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
4 changes: 4 additions & 0 deletions builtin/providers/aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ func resourceAwsDbInstanceStateRefreshFunc(
return nil, "", nil
}

if v.DBInstanceStatus != nil {
log.Printf("[DEBUG] DB Instance status for instance %s: %s", d.Id(), *v.DBInstanceStatus)
}

return v, *v.DBInstanceStatus, nil
}
}
Expand Down
83 changes: 41 additions & 42 deletions builtin/providers/aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,19 @@ func TestAccAWSDBInstance(t *testing.T) {
}

func TestAccAWSDBInstanceReplica(t *testing.T) {
// var v rds.DBInstance
var r rds.DBInstance
var s, r rds.DBInstance

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
// resource.TestStep{
// Config: testAccAWSDBInstanceConfig,
// Check: resource.ComposeTestCheckFunc(
// testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
// ),
// },

resource.TestStep{
Config: testAccAWSDBInstanceReplicaConfig,
Config: testAccReplicaInstanceConfig(rand.New(rand.NewSource(time.Now().UnixNano())).Int()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &s),
testAccCheckAWSDBInstanceExists("aws_db_instance.replica", &r),
resource.TestCheckResourceAttr(
"aws_db_instance.replica", "replicate_source_db", "tf-update-more"),
testAccCheckAWSDBInstanceReplicaAttributes(&r),
testAccCheckAWSDBInstanceReplicaAttributes(&s, &r),
),
},
},
Expand Down Expand Up @@ -132,23 +123,11 @@ func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFu
}
}

func testAccCheckAWSDBInstanceReplicaAttributes(r *rds.DBInstance) resource.TestCheckFunc {
func testAccCheckAWSDBInstanceReplicaAttributes(source, replica *rds.DBInstance) resource.TestCheckFunc {
return func(s *terraform.State) error {

// if *v.Engine != "mysql" {
// return fmt.Errorf("bad engine: %#v", *v.Engine)
// }

// if *v.EngineVersion != "5.6.21" {
// return fmt.Errorf("bad engine_version: %#v", *v.EngineVersion)
// }

// if *v.BackupRetentionPeriod != 0 {
// return fmt.Errorf("bad backup_retention_period: %#v", *v.BackupRetentionPeriod)
// }

if r.ReadReplicaSourceDBInstanceIdentifier != nil && *r.ReadReplicaSourceDBInstanceIdentifier != "tf-update-more" {
return fmt.Errorf("bad source identifier for replica, got: %#v, expected: 'tf-update-more'", *r.ReadReplicaSourceDBInstanceIdentifier)
if replica.ReadReplicaSourceDBInstanceIdentifier != nil && *replica.ReadReplicaSourceDBInstanceIdentifier != *source.DBInstanceIdentifier {
return fmt.Errorf("bad source identifier for replica, expected: '%s', got: '%s'", *source.DBInstanceIdentifier, *replica.ReadReplicaSourceDBInstanceIdentifier)
}

return nil
Expand Down Expand Up @@ -209,17 +188,37 @@ resource "aws_db_instance" "bar" {
parameter_group_name = "default.mysql5.6"
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())

var testAccAWSDBInstanceReplicaConfig = fmt.Sprintf(`
resource "aws_db_instance" "replica" {
identifier = "tf-replica-db-%d"
replicate_source_db = "tf-update-more"
allocated_storage = 5
engine = "mysql"
engine_version = "5.6.19b"
instance_class = "db.t1.micro"
password = "fofofofxx"
username = "foo"
tags {
Name = "tf-replica-db"
}
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
func testAccReplicaInstanceConfig(val int) string {
return fmt.Sprintf(`
resource "aws_db_instance" "bar" {
identifier = "foobarbaz-test-terraform-%d"
allocated_storage = 5
engine = "mysql"
engine_version = "5.6.21"
instance_class = "db.t1.micro"
name = "baz"
password = "barbarbarbar"
username = "foo"
backup_retention_period = 1
parameter_group_name = "default.mysql5.6"
}
resource "aws_db_instance" "replica" {
identifier = "tf-replica-db-%d"
backup_retention_period = 0
replicate_source_db = "${aws_db_instance.bar.identifier}"
allocated_storage = "${aws_db_instance.bar.allocated_storage}"
engine = "${aws_db_instance.bar.engine}"
engine_version = "${aws_db_instance.bar.engine_version}"
instance_class = "${aws_db_instance.bar.instance_class}"
password = "${aws_db_instance.bar.password}"
username = "${aws_db_instance.bar.username}"
tags {
Name = "tf-replica-db"
}
}
`, val, val)
}

0 comments on commit 6b6aa86

Please sign in to comment.