How to terraform a read replica in a different region?

4,270 views
Skip to first unread message

Romano Aquino

unread,
Nov 19, 2015, 8:45:48 PM11/19/15
to Terraform
I'm able to use the following to create an RDS instance and a read replica in the same region, but how would I create a read replica in a different region? The AWS Console has this ability, but I don't see how to create this using Terraform:

resource "aws_db_instance" "default" {
  identifier = "${var.identifier}"
  allocated_storage = "${var.storage}"
  engine = "${var.engine}"
  engine_version = "${lookup(var.engine_version, var.engine)}"
  instance_class = "${var.instance_class}"
  name = "${var.db_name}"
  username = "${var.username}"
  password = "${var.password}"
  vpc_security_group_ids = ["${aws_security_group.default.id}"]
  db_subnet_group_name = "${aws_db_subnet_group.default.id}"
  backup_retention_period = "1"
}

resource "aws_db_instance" "default_replica1" {
  identifier = "replica1"
  replicate_source_db = "${aws_db_instance.default.identifier}"
  availability_zone = "ap-northeast-1a"
  allocated_storage = "${var.storage}"
  engine = "${var.engine}"
  engine_version = "${lookup(var.engine_version, var.engine)}"
  instance_class = "${var.instance_class}"
  name = "${var.db_name}"
  username = "${var.username}"
  password = "${var.password}"
  vpc_security_group_ids = ["${aws_security_group.default.id}"]
  db_subnet_group_name = "${aws_db_subnet_group.default.id}"

Clint Shryock

unread,
Dec 3, 2015, 12:39:54 PM12/3/15
to terrafo...@googlegroups.com
Hello Romano –

Can you clarify about the different region, via the console? I just attempted this and was only able to chose a different availability zone in the same region. If by chance you meant that, then you can specify the `availability_zone` in the replica, but I don't see a means of doing a separate region. 

Regards,
Clint

--
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/e465d098-fef1-4a3f-a019-20ffb3ef3b05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Clint

Romano Aquino

unread,
Dec 3, 2015, 1:38:42 PM12/3/15
to Terraform
Hi Clint,

I was referring to this:

https://aws.amazon.com/blogs/aws/cross-region-read-replicas-for-amazon-rds-for-mysql/

In the AWS Management Console, you can set a read replica in a different region, I was wondering if Terraform had this ability as well.

Clint Shryock

unread,
Dec 7, 2015, 4:30:00 PM12/7/15
to terrafo...@googlegroups.com
Hey Romano – 

It turns out that due to a bug in Terraform you can't do this yet:


I have an idea for the patch though, and I'll try to get to it shortly :)

Thanks!
Clint


For more options, visit https://groups.google.com/d/optout.



--
Clint

Clint Shryock

unread,
Dec 9, 2015, 10:57:14 AM12/9/15
to terrafo...@googlegroups.com
Hello –

I just merged https://github.com/hashicorp/terraform/pull/4215 , which allows you to create a read replica in another region. It will go out in the next release, or you could build Terraform from the master branch.

You must use the Primary database's ARN as the `replicate_source_db` (not just the name/id).

Thanks!
Clint
--
Clint

Dharmendra Kumar

unread,
Feb 17, 2020, 1:34:11 AM2/17/20
to Terraform
Hello Romano,

Could you please share the code for creating oracle rds instance. that will be an great help for me.

Thanks,
Dharmendra

chengkai liang

unread,
Feb 19, 2020, 12:37:02 PM2/19/20
to terrafo...@googlegroups.com
If you read the terraform document - aws_db_instance, you will find that the attribute, availability_zone - (Optional) The AZ for the RDS instance, will allow you to set shard zone ...

--
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.
Reply all
Reply to author
Forward
0 new messages