Skip to content
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

resource/rds_cluster_instance: Support availability_zone #2812

Merged
merged 4 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.TestCheckResourceAttr("aws_rds_cluster_instance.cluster_instances", "availability_zone", "us-west-2a"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to check this more loosely, e.g.

resource.TestMatchResourceAttr("aws_rds_cluster_instance.cluster_instances", "availability_zone", regexp.MustCompile("^us-west-2[a-z]{1}$")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it👍

),
},
},
})
}

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