-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/aws: Add AWS RDS Read Replica #1946
Changes from 4 commits
d755fbd
f346187
dc164c4
6b6aa86
6de8f9d
7292386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,26 @@ func TestAccAWSDBInstance(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSDBInstanceReplica(t *testing.T) { | ||
var s, r rds.DBInstance | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSDBInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccReplicaInstanceConfig(rand.New(rand.NewSource(time.Now().UnixNano())).Int()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use the unique ID generator that Paul made recently #1632 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, forget it, probably not a good idea to make tests depending on more things... |
||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &s), | ||
testAccCheckAWSDBInstanceExists("aws_db_instance.replica", &r), | ||
testAccCheckAWSDBInstanceReplicaAttributes(&s, &r), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).rdsconn | ||
|
||
|
@@ -103,6 +123,17 @@ func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFu | |
} | ||
} | ||
|
||
func testAccCheckAWSDBInstanceReplicaAttributes(source, replica *rds.DBInstance) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
|
||
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 | ||
} | ||
} | ||
|
||
func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
|
@@ -156,3 +187,38 @@ resource "aws_db_instance" "bar" { | |
|
||
parameter_group_name = "default.mysql5.6" | ||
}`, 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}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation here. |
||
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need these
\n\n------\n
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, no, that's my debugging statements 😆 fixed in 6de8f9d