Issue:-
While creating the multiple region vpc through the terraform getting the error during terraform apply when it tries to create the subnets in 2nd vpc.
Error:-
module.vpc2.aws_subnet.public[0]: Creating...
╷
│ Error: creating EC2 Subnet: InvalidParameterValue: Value (us-west-2b) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f.
│ status code: 400, request id: 79a19b0b-93d1-4a78-9c0c-124e429c78de
│
│ with module.vpc2.aws_subnet.public[1],
│ on .terraform/modules/vpc2/main.tf line 359, in resource "aws_subnet" "public":
│ 359: resource "aws_subnet" "public" {
Cause:-
Even though i mentioned the providers still the terraform was trying to create the us-west-2b subnet in the wrong region i.e. us-east-1 and it was not able to find those subnets and thats why aws is throughing the error that only us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f subnets are available to create the subnets.
Solution:-
Solution is to provider the multiple providers as
provider "aws" {
region = "us-east-1"
}
module "vpc1" {
providers = { aws = aws }
source = "terraform-aws-modules/vpc/aws"
provider "aws" {
alias = "secondary"
region = "us-west-2"
}
module "vpc2" {
providers = { aws = aws.secondary }
source = "terraform-aws-modules/vpc/aws"
Once you mention the providers like i have done above than the terraform would pick the multiple regions and wont through the error mentioned above and that should solve the issue.
0 comments:
Post a Comment