1

我对 DataBricks 完全陌生,并尝试使用 DataBricks 提供的示例 Terraform 代码部署 E2 工作区。我刚刚开始使用 VPC 部分:

data "aws_availability_zones" "available" {}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  # version = "3.2.0"

  name = local.prefix
  cidr = var.cidr_block
  azs  = data.aws_availability_zones.available.names

  enable_dns_hostnames = true
  enable_nat_gateway   = true
  single_nat_gateway   = true
  create_igw           = true

  private_subnets = [cidrsubnet(var.cidr_block, 3, 1),
                     cidrsubnet(var.cidr_block, 3, 2)]

  manage_default_security_group = true
  default_security_group_name = "${local.prefix}-sg"

  default_security_group_egress = [{
    cidr_blocks = "0.0.0.0/0"
  }]

  default_security_group_ingress = [{
    description = "Allow all internal TCP and UDP"
    self        = true
  }]
}

当我运行时,terraform plan我收到此错误:

│ Error: Error in function call
│
│   on .terraform/modules/vpc/main.tf line 1090, in resource "aws_nat_gateway" "this":
│ 1090:   subnet_id = element(
│ 1091:     aws_subnet.public.*.id,
│ 1092:     var.single_nat_gateway ? 0 : count.index,
│ 1093:   )
│     ├────────────────
│     │ aws_subnet.public is empty tuple
│     │ count.index is 0
│     │ var.single_nat_gateway is true
│
│ Call to function "element" failed: cannot use element function with an empty list.

真的很感激任何关于这里出了什么问题的指示。

4

1 回答 1

2

您设置了您想要的互联网网关create_igw = true,但您没有指定 public_subnetspublic_subnets如果你有,你必须有igw

于 2021-12-26T07:25:05.233 回答