Setting up a new aws_rds_cluster in 2 availability zones

1,599 views
Skip to first unread message

Albert Guðmundsson

unread,
Jan 7, 2016, 9:55:37 AM1/7/16
to Terraform
Hi,

I'm trying to set up a new Aurora DB cluster on AWS, and want it in 2 availability zones.

Creating it is no problem and everything is correct, but if I try to run terraform apply again it tells me that the DB cluster has changed and deletes it and re-creates.

If I run plan for it, this is what is logged out:

-/+ aws_rds_cluster.rds
    apply_immediately:                "" => "<computed>"
    availability_zones.#:             "3" => "2" (forces new resource)
    availability_zones.2050015877:    "us-west-2c" => ""
    availability_zones.221770259:     "us-west-2b" => "us-west-2b" (forces new resource)
    availability_zones.2487133097:    "us-west-2a" => "us-west-2a" (forces new resource)

Nothing has changed in the configuration between the two times I run terraform.

Is there anything I can do so it will not constantly delete and re-create the database every time I make some changes to the configuration?


My configuration is like this:


variable "availabiliy_zones" {
default = "us-west-2a,us-west-2b"
}

### RDS ###
resource "aws_db_subnet_group" "db-subnet-group" {
name = "${var.environment_name}-db-subnet-group"
description = "${var.environment_name} DB Subnet group"
subnet_ids = ["${aws_subnet.data-subnet.*.id}"]

tags {
Name = "${var.environment_name}-db-subnet-group"
Environment = "${var.environment_name}"
}
}

resource "aws_rds_cluster" "rds" {
cluster_identifier = "${var.environment_name}-aurora-cluster"
master_username = "user"
master_password = "userpass"
availability_zones = ["${split(",", var.availabiliy_zones)}"]
backup_retention_period = 14
preferred_backup_window = "04:00-05:00"
vpc_security_group_ids = ["${element(aws_security_group.public.*.id, count.index)}"]
db_subnet_group_name = "${aws_db_subnet_group.db-subnet-group.id}"
}

resource "aws_rds_cluster_instance" "rds-instance" {
identifier = "${var.environment_name}-aurora-instance-${count.index}"
cluster_identifier = "${aws_rds_cluster.rds.cluster_identifier}"
instance_class = "db.r3.large"
publicly_accessible = true
db_subnet_group_name = "${aws_db_subnet_group.db-subnet-group.id}"
count = "${length(split(",", var.availabiliy_zones))}"
tags {
Name = "${var.environment_name}-rds-instance-${count.index}"
Environment = "${var.environment_name}"
}
}

Regards,
Albert

Clint Shryock

unread,
Jan 7, 2016, 11:13:54 AM1/7/16
to terrafo...@googlegroups.com
Hey Albert – 

How many subnets are in your subnet group? 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/2b098b13-5086-405f-b732-de38fff7e6bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Clint

Albert Guðmundsson

unread,
Jan 7, 2016, 11:18:40 AM1/7/16
to Terraform
Hi,

There are 2 subnets in the group:

# Data Subnet
resource "aws_subnet" "data-subnet" {
vpc_id = "${aws_vpc.vpc.id}"
  count = "${length(split(",", var.availabiliy_zones))}"
  cidr_block = "${element(split(",", var.data_subnet_ips), count.index)}"
availability_zone = "${element(split(",", var.availabiliy_zones), count.index)}"

tags {
Name = "${var.environment_name}-subnet-data-${count.index}"
Environment = "${var.environment_name}"
}
}

Chris Mosetick

unread,
Jan 16, 2016, 6:53:09 AM1/16/16
to Terraform
You seem to be experiencing the same issue I'm getting at the moment. This bug report seems to indicate that the issue is caused by the AWS API itself, and not something wrong with Terraform:

Terraform 0.6.9 deletes database_name from rds_cluster in state, causing destruction and recreation of cluster & instances

Albert Guðmundsson

unread,
Jan 18, 2016, 5:02:14 AM1/18/16
to Terraform
Thank you for the letting me know. 
I will be monitoring this issue closely.

Anton Koldaev

unread,
Apr 24, 2016, 2:22:02 PM4/24/16
to Terraform
Hi,

Have you figured it out?
I'm seeing just the same issue with

availability_zones.#:             "3" => "2" (forces new resource)

Anton Koldaev

unread,
Apr 24, 2016, 2:28:46 PM4/24/16
to Terraform
Actually as a workaround I bumped it to 3 availability zones in terraform config and it's not re-creating rds instance every time anymore:
 resource "aws_rds_cluster_instance" "cluster-instances" {
-  count              = 2
+  count              = 3


 resource
"aws_rds_cluster" "project-production" {
-  availability_zones = ["us-east-1a", "us-east-1b"]
+  availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
Reply all
Reply to author
Forward
0 new messages