【发布时间】:2021-07-22 10:43:25
【问题描述】:
所以下面是我的项目文件结构:
├── main.tf
├── tunnel
│ ├── main.tf
│ └── variables.tf
└── variables.tf
我正在尝试在 Terraform 0.15.1 中使用多个提供程序,如此处所述 -> https://www.terraform.io/docs/language/modules/develop/providers.html
按照示例后,我无法使其工作。我现在已经简化了我的代码,只使用一个提供者别名(尽可能简单)。我得到的错误是:
╷
│ Error: Missing required argument
│
│ The argument "region" is required, but was not set.
╵
我在根目录下的 main.tf 文件:
module "tunnel" {
source = "./tunnel"
providers = {
aws.r = aws.requester
}
}
我的 variables.tf 在根目录中:
provider "aws" {
alias = "requester"
region = "ap-southeast-2"
profile = "benchmark"
}
我的隧道/variables.tf 文件:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.7.0"
configuration_aliases = [ aws.r ]
}
}
}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
我的隧道/main.tf 文件:
# 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"
}
}
我不明白为什么会出现此错误?这段代码的最终目标是自动化 vpc 对等的双方,如下所示 -> https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_peering_connection_accepter 。但我目前坚持让两个 aws 提供程序使用不同的凭据(上面示例中的一个提供程序以简化事情)。
当我从根 main.tf 中删除 alias = "requester" 时:
provider "aws" {
// alias = "requester"
region = "ap-southeast-2"
profile = "benchmark"
}
以及根路径中 main.tf 中的提供程序配置:
module "tunnel" {
source = "./tunnel"
// providers = {
// aws.r = aws.requester
// }
}
以及来自 tunnel/variables.tf 的别名配置:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.7.0"
// configuration_aliases = [ aws.r ]
}
}
}
计划运行良好:
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.
【问题讨论】:
标签: terraform terraform-provider-aws