In this part of the serie, we will see how to create in one Terraform script and in a single execution, how to create elements in multiple regions.
This kind of tips is really helpful if you want to create at once all your infra and/or if you want to setup some disaster recovery.
How to do it?
To do it, it's pretty simple. We have 2 steps to follow :
- declare multiple providers
- declare which provider we want to use for each resource
Declare multiple providers
In your current script to create something on AWS, you should have an AWS Provider with the region where it should be created.
So, copy/paste this block for all your regions. Then add an alias to each of them to be able to differentiate them.
provider "aws" {
alias = "frankfurt"
region = "eu-central-1"
}
provider "aws" {
alias = "sydney"
region = "ap-southeast-2"
}
Declare which provider we want to use for each resource
In each resource you have, add the provider parameter to link each of them to the correct provider.
resource "aws_rds_cluster_instance" "test_frankfurt" {
provider = aws.frankfurt
...
}
resource "aws_rds_cluster_instance" "test_sydney" {
provider = aws.sydney
...
}
And that's it! You are now able to deploy your complete infra on multiple regions at once!
I hope it will help you! 🍺
And see you soon for the next part of this serie. 😀
Serie link
- 1 - Start : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-1-1ko7
- 2 - Definitions : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-2-definitions-93p
- 3 - Simple database : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-3-simple-database-a9o
- 4 - HA Database : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-4-ha-database-4kek
- 5 - DR database : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-5-dr-database-278b
- 6 - Create from snapshot : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-6-create-from-snapshot-2mbf
- 7 - Dynamic Terraform backend definition : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-7-dynamic-terraform-backend-definition-3aga
- 8 - Multiple instances in multiple regions : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-8-multiple-instances-in-multiple-regions-210d
- 9 - Generate a random value : https://dev.to/adaendra/how-to-setup-a-hadr-database-in-aws-9-generate-a-random-value-5g8a
Top comments (0)