Skip to content

Commit

Permalink
resource/rds_cluster_instance: Support availability_zone (#2812)
Browse files Browse the repository at this point in the history
* Support availability_zone

* Add test

* Use aws_availability_zones

* Update
  • Loading branch information
atsushi-ishibashi authored and radeksimko committed Feb 16, 2018
1 parent a00abe3 commit ac13c5a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func resourceAwsRDSClusterInstance() *schema.Resource {

"availability_zone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

Expand Down Expand Up @@ -211,6 +213,10 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
Tags: tags,
}

if attr, ok := d.GetOk("availability_zone"); ok {
createOpts.AvailabilityZone = aws.String(attr.(string))
}

if attr, ok := d.GetOk("db_parameter_group_name"); ok {
createOpts.DBParameterGroupName = aws.String(attr.(string))
}
Expand Down
59 changes: 59 additions & 0 deletions aws/resource_aws_rds_cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ func TestAccAWSRDSClusterInstance_basic(t *testing.T) {
})
}

func TestAccAWSRDSClusterInstance_az(t *testing.T) {
var v rds.DBInstance

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterInstanceConfig_az(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterInstanceExists("aws_rds_cluster_instance.cluster_instances", &v),
testAccCheckAWSDBClusterInstanceAttributes(&v),
resource.TestMatchResourceAttr("aws_rds_cluster_instance.cluster_instances", "availability_zone", regexp.MustCompile("^us-west-2[a-z]{1}$")),
),
},
},
})
}

func TestAccAWSRDSClusterInstance_namePrefix(t *testing.T) {
var v rds.DBInstance
rInt := acctest.RandInt()
Expand Down Expand Up @@ -329,6 +349,45 @@ resource "aws_db_parameter_group" "bar" {
`, n, n, n)
}

func testAccAWSClusterInstanceConfig_az(n int) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}
resource "aws_rds_cluster" "default" {
cluster_identifier = "tf-aurora-cluster-test-%d"
availability_zones = ["${data.aws_availability_zones.available.names}"]
database_name = "mydb"
master_username = "foo"
master_password = "mustbeeightcharaters"
skip_final_snapshot = true
}
resource "aws_rds_cluster_instance" "cluster_instances" {
identifier = "tf-cluster-instance-%d"
cluster_identifier = "${aws_rds_cluster.default.id}"
instance_class = "db.t2.small"
db_parameter_group_name = "${aws_db_parameter_group.bar.name}"
promotion_tier = "3"
availability_zone = "${data.aws_availability_zones.available.names[0]}"
}
resource "aws_db_parameter_group" "bar" {
name = "tfcluster-test-group-%d"
family = "aurora5.6"
parameter {
name = "back_log"
value = "32767"
apply_method = "pending-reboot"
}
tags {
foo = "bar"
}
}
`, n, n, n)
}

func testAccAWSClusterInstanceConfig_namePrefix(n int) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_instance" "test" {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/rds_cluster_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ details on controlling this property.
enhanced monitoring metrics to CloudWatch Logs. You can find more information on the [AWS Documentation](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.html)
what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances.
* `monitoring_interval` - (Optional) The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60.
* `promotion_tier` - (Optional) Default 0. Failover Priority setting on instance level. The reader who has lower tier has higher priority to get promoter to writer.
* `promotion_tier` - (Optional) Default 0. Failover Priority setting on instance level. The reader who has lower tier has higher priority to get promoter to writer.
* `availability_zone` - (Optional, Computed) The EC2 Availability Zone that the DB instance is created in. See [docs](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html) about the details.
* `preferred_backup_window` - (Optional) The daily time range during which automated backups are created if automated backups are enabled.
Eg: "04:00-09:00"
* `preferred_maintenance_window` - (Optional) The window to perform maintenance in.
Expand Down

0 comments on commit ac13c5a

Please sign in to comment.