получение ошибки в terraform при создании экземпляров и подсетей - PullRequest
1 голос
/ 14 марта 2020

Создание моего кода подсетей экземпляра ниже:

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 ниже команды:

terraform plan --var-filr tf.vars

Любопытно узнать, почему он сообщает об этих ошибках и как их решить. я думаю, что это сначала берет подсети, а не экземпляр.

1 Ответ

0 голосов
/ 15 марта 2020
var.cidrs is empty list of string

Он говорит, что переменная cidrs пуста.

...