Terraform aws:缺少必需的参数

时间:2021-05-20 07:36:22

标签: terraform

有人可以帮助澄清 Terraform 中的局部变量和全局变量是如何工作的吗?我现在面临这个问题:

<块引用>

错误:缺少必需的参数 │ │ 在 main.tf 第 46 行,在模块“pub-rt”中: │ 46:模块“pub-rt”{ │ │ 参数“vpc_cidr_block”是必需的,但没有找到定义。

我的代码结构是:

-- Dev
  -- main.tf
-- modules
  -- rt
    -- pub-rt.tf
    -- pri-rt.tf
    -- vars.tf

这是我的ma​​in.tf

module "pub-rt" {
  source            = "../modules/rt"
  id1               = var.id1         #id1 will be common for pub-rt.tf & pri-rt.tf resources
  id2               = var.id2         #id2 will be used only in pub-rt.tf resources
}

module "pri-rt" {
  source            = "../modules/rt"
  id3               = var.id3         #id3 will be common for pub-rt.tf & pri-rt.tf resources
  id4               = var.id4         #id4 will be used only in pri-rt.tf resources
}

我的 ../rt/vars.tf 包含:

variable "id1" { }
variable "id2" { }
variable "id3" { }
variable "id4" { }

为 main.tf 添加我的真实代码:

# Create Public Route Table
module "pub-rt" {
  source            = "../modules/rt"
  pub_rt_tag        = { Name = "prod-pub-rt" }
  vpc_id            = module.vpc.vpcId 
  ir_cidr           = var.ir_cidr                                 # routing inside the VPC
  gateway_id        = module.igw.igwId                            # routing to the internet through igw
}


# Create Private Route Table
module "pri-rt" {
  source            = "../modules/rt"
  pub_rt_tag        = { Name = "prod-pri-rt" }
  vpc_id            = module.vpc.vpcId 
  vpc_cidr_block    = var.vpc_cidr_block                          # routing inside the VPC
  nat_id            = module.nat.natId                            # routing to the internet NAT
}

0 个答案:

没有答案