soniya.rayabagi
Wed Jan 31 2024
AWS - ami
If you want to create two instances in different regions within the same Terraform file, using the
For example :
If you want to create two instances in different regions within the same Terraform file, using the
same AMI,
you should first ensure that the AMI is available in both regions. If it's available in both regions (i.e.- "us-east-1" and "us-east-2")
, you can proceed to use the same AMI for both instances. Otherwise, you should use two different AMIs.For example :
provider "aws" {
alias = "us-east-2"
region = "us-east-2"
}
resource "aws_instance" "instance" {
provider = aws.us-east-2
ami = "ami-id-1"
instance_type = "t2.micro"
}
provider "aws" {
alias = "us-east-1"
region = "us-east-1"
}
resource "aws_instance" "instance1" {
provider = aws.us-east-1
ami = "ami-id-2"
instance_type = "t2.micro"
}