amazon-web-services - 调用模块中的提供者
问题描述
在我的模块中调用提供程序时遇到一些问题,我是否需要在我的networking/main.tf 中更改提供程序?
调用似乎不起作用的模块时,我是否只是在 main.tf 中声明。
任何帮助都会很棒,我想调整我的工作并且需要使用多个 aws 帐户和区域。TGW等
# --- root/main.tf ---
module "networking" {
source = "./networking"
provider = aws.first
vpc_cidr = local.vpc_cidr1
access_ip = var.access_ip
security_groups = local.security_groups
public_sn_count = 2
private_sn_count = 3
max_subnets = 20
public_cidrs = [for i in range(2, 255, 2) : cidrsubnet(local.vpc_cidr1, 8, i)]
private_cidrs = [for i in range(1, 255, 2) : cidrsubnet(local.vpc_cidr1, 8, i)]
nat_gw_eip_count = 0
nat_gw_count = 0
}
terraform {
required_version = ">= 0.12"
}
# Defines the 1st account provider.
provider "aws" {
alias = "first"
region = var.aws_first_region
access_key = var.aws_first_access_key
secret_key = var.aws_first_secret_key
}
# Defines the 2nd account provider.
provider "aws" {
alias = "second"
region = var.aws_second_region
access_key = var.aws_second_access_key
secret_key = var.aws_second_secret_key
}
data "aws_caller_identity" "first" {
provider = aws.first
}
data "aws_caller_identity" "second" {
provider = aws.second
}
data "aws_caller_identity" "third" {
provider = aws.third
}
# --- networking/main.tf ---
data "aws_availability_zones" "available" {}
resource "random_integer" "random" {
min = 1
max = 100
}
resource "random_shuffle" "public_az" {
input = data.aws_availability_zones.available.names
result_count = var.max_subnets
}
resource "aws_vpc" "wash_VPC" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "wash_VPC-${random_integer.random.id}"
}
lifecycle {
create_before_destroy = true
}
}
这是错误还有什么?
│ Error: Unsupported argument
│
│ on main.tf line 5, in module "networking":
│ 5: provider = aws.first
│
│ An argument named "provider" is not expected her
解决方案
为整个模块指定提供者的语法与为资源指定提供者略有不同。这是因为一个模块可能声明了使用多个提供程序的多个资源,因此您提供了一个模块的提供程序映射。您的代码应如下所示:
module "networking" {
source = "./networking"
providers = {
aws = aws.first
}
vpc_cidr = local.vpc_cidr1
access_ip = var.access_ip
security_groups = local.security_groups
public_sn_count = 2
private_sn_count = 3
max_subnets = 20
public_cidrs = [for i in range(2, 255, 2) : cidrsubnet(local.vpc_cidr1, 8, i)]
private_cidrs = [for i in range(1, 255, 2) : cidrsubnet(local.vpc_cidr1, 8, i)]
nat_gw_eip_count = 0
nat_gw_count = 0
}
推荐阅读
- python - 使用 python uvdev 设置绝对光标位置
- css - 将div放在导航栏下方
- mysql - 连接前端到后端
- mysql - 如何更新sequelize中的deletedAt时间戳?
- javascript - 为什么我的toggle()的两个选项都执行了?
- go - Beego端点找不到模板文件...但我没有使用模板
- ssis - 如何在扩展事件中自动将数据从分析服务导出到数据库
- python - 以正确的方式更新 Pandas Dataframe 中的列值
- microsoft-graph-api - 如何在共享邮箱中创建带有大附件的电子邮件
- python-3.x - Python Zeep WSDL 意外元素回溯