在创建实例和子网时遇到地形错误

问题描述 投票:1回答:1

我的实例子网代码创建如下:

resource "aws_vpc" "default" {
    cidr_block = "${var.vpc_cidr}"
    enable_dns_hostnames = true
    tags = {
        Name = "${var.vpc_name}"
    }
}

resource "aws_internet_gateway" "default" {
    vpc_id = "${aws_vpc.default.id}"
    tags = {
        Name = "${var.IGW_name}"
    }
}

resource "aws_subnet" "subnets" {
    count = 3 
    vpc_id = "${aws_vpc.default.id}"
    cidr_block = "${element(var.cidrs, count.index)}"
    availability_zone = "${element(var.azs, count.index)}"

    tags = {
        Name = "Public-Subnet-${count.index+1}"
    }
}

我的代码输出在函数调用中显示错误,即在下面,

Error: Error in function call

  on main.tf line 26, in resource "aws_subnet" "subnets":
  26:     cidr_block = "${element(var.cidrs, count.index)}"
    |----------------
    | count.index is 2
    | var.cidrs is empty list of string

Call to function "element" failed: cannot use element function with an empty
list.


Error: Error in function call

  on main.tf line 26, in resource "aws_subnet" "subnets":
  26:     cidr_block = "${element(var.cidrs, count.index)}"
    |----------------
    | count.index is 1
    | var.cidrs is empty list of string

Call to function "element" failed: cannot use element function with an empty
list.


Error: Error in function call

  on main.tf line 26, in resource "aws_subnet" "subnets":
  26:     cidr_block = "${element(var.cidrs, count.index)}"
    |----------------
    | count.index is 0
    | var.cidrs is empty list of string

Call to function "element" failed: cannot use element function with an empty
list.

我正在以下命令下运行地形:

terraform plan --var-filr tf.vars

好奇地知道为什么要报告这些错误以及如何解决。我认为它首先要使用子网而不是实例。

indexing count terraform subnet cidr
1个回答
0
投票
var.cidrs is empty list of string
© www.soinside.com 2019 - 2024. All rights reserved.