我的实例子网代码创建如下:
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
想知道为什么要报告这些错误以及如何解决。 我认为它首先要使用子网而不是实例。
答案 0 :(得分:0)
var.cidrs is empty list of string
它说cidrs变量为空。