so below is my project file structure:
├── main.tf
├── tunnel
│ ├── main.tf
│ └── variables.tf
└── variables.tf
I am trying to use multiple providers in Terraform 0.15.1 as described here -> https://www.terraform.io/docs/language/modules/develop/providers.html
After following the example I am not able to get it work. I have now simplified my code down to just use one single provider alias(keep it as simple as possible). The error I am getting is:
╷
│ Error: Missing required argument
│
│ The argument "region" is required, but was not set.
╵
My main.tf file in root directory:
module "tunnel" {
source = "./tunnel"
providers = {
aws.r = aws.requester
}
}
my variables.tf in root directory:
provider "aws" {
alias = "requester"
region = "ap-southeast-2"
profile = "benchmark"
}
my tunnel/variables.tf file:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.7.0"
configuration_aliases = [ aws.r ]
}
}
}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
my tunnel/main.tf file:
# Requester's side of the connection.
resource "aws_vpc_peering_connection" "peer" {
vpc_id = "vpc-xxxxxxxxxxxxxxxxx"
peer_vpc_id = "vpc-xxxxxxxxxxxxxxxxx"
peer_owner_id = data.aws_caller_identity.current.account_id
peer_region = data.aws_region.current.name
auto_accept = false
tags = {
Side = "Requester"
}
}
I don't understand why I am getting this error? The goal with this code eventually is to automate both sides of the vpc peering as shown here -> https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_accepter . But I am currently stuck on getting two aws providers working with different credentials (one provider in the example above to simplify things).
When I remove alias = "requester"
from the root main.tf:
provider "aws" {
// alias = "requester"
region = "ap-southeast-2"
profile = "benchmark"
}
and the provider config from main.tf in root path:
module "tunnel" {
source = "./tunnel"
// providers = {
// aws.r = aws.requester
// }
}
and the alias config from tunnel/variables.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.7.0"
// configuration_aliases = [ aws.r ]
}
}
}
plan works fine:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.tunnel.aws_vpc_peering_connection.peer will be created
+ resource "aws_vpc_peering_connection" "peer" {
+ accept_status = (known after apply)
+ auto_accept = false
+ id = (known after apply)
+ peer_owner_id = "xxxxxxx"
+ peer_region = "ap-southeast-2"
+ peer_vpc_id = "vpc-xxxxxxxxxxxxxxxxx"
+ tags = {
+ "Side" = "Requester"
}
+ vpc_id = "vpc-xxxxxxxxxxx"
+ accepter {
+ allow_classic_link_to_remote_vpc = (known after apply)
+ allow_remote_vpc_dns_resolution = (known after apply)
+ allow_vpc_to_remote_classic_link = (known after apply)
}
+ requester {
+ allow_classic_link_to_remote_vpc = (known after apply)
+ allow_remote_vpc_dns_resolution = (known after apply)
+ allow_vpc_to_remote_classic_link = (known after apply)
}
}
Plan: 1 to add, 0 to change, 0 to destroy.