我想运行terraform plan -var-file -out,然后应用该计划,但是出现以下错误。
这是我的 main.tf , variable.tf 和以下network.tfvars文件:
###### Resource Group ##############
resource "azurerm_resource_group" "resourcegroupname" {
name = "${var.resourcegrouprefix}-RG"
location = "${var.location}"
}
###### VNET ##############
resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet-prefix}-vnet"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
location = "${azurerm_resource_group.resourcegroupname.location}"
address_space = "${var.vnetcidr}"
}
# address_space = ["10.0.0.0/20"]
###### Subnets ##############
resource "azurerm_subnet" "subnet1" {
name = "${var.subnet1-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_space = "${var.subnet1cidr}"
}
resource "azurerm_subnet" "subnet2" {
name = "${var.subnet2-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_space = "${var.subnet2cidr}"
}
resource "azurerm_subnet" "subnet3" {
name = "${var.subnet3-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_space = "${var.subnet3cidr}"
变量文件
variable "resourcegrouprefix" {
description = "The prefix used for all resources in VNET RG"
default = ""
}
variable "vnet-prefix" {
description = "The prefix used for VNET resource"
default = ""
}
variable "vnetcidr" {
default = ""
}
variable "subnet1cidr" {
default = ""
}
variable "subnet2cidr" {
default = ""
}
variable "subnet3cidr" {
default = ""
}
Networking.tfvars
resourcegrouprefix = "networking"
vnet-prefix = "networking"
vnetcidr = "10.0.0.0/20"
subnet1-prefix = "untrust"
subnet2-prefix = "trust"
subnet3-prefix = "mgmt"
subnet1cidr = "10.0.0.0/24"
subnet2cidr = "10.0.1.0/24"
subnet3cidr = "10.0.2.0/24"
我要执行的命令:
terraform plan -var-file="networking.tfvars" -out="networkingplan.out"
错误消息:
azurerm_subnet.subnet1:“地址前缀”:必填字段未设置 azurerm_subnet.subnet1 ::无效或未知密钥:address_space azurerm_subnet.subnet2:“地址前缀”:必填字段未设置 azurerm_subnet.subnet2::无效或未知密钥:address_space azurerm_subnet.subnet3:“地址前缀”:必填字段未设置 azurerm_subnet.subnet3::无效或未知密钥:address_space azurerm_subnet.subnet4:“地址前缀”:必填字段未设置 azurerm_subnet.subnet4::无效或未知密钥:address_space azurerm_subnet.subnet5:“地址前缀”:必填字段未设置 azurerm_subnet.subnet5::无效或未知密钥:address_space azurerm_subnet.subnet6:“ address_prefix”:必填字段未设置 azurerm_subnet.subnet6::无效或未知密钥:address_space azurerm_virtual_network.vnet:address_space:应为列表
答案 0 :(得分:0)
修复了错误消息
###### Resource Group ##############
resource "azurerm_resource_group" "resourcegroupname" {
name = "${var.resourcegrouprefix}-RG"
location = "${var.location}"
}
###### VNET ##############
resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet-prefix}-vnet"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
location = "${azurerm_resource_group.resourcegroupname.location}"
address_space = ["${var.vnetcidr}"]
}
# address_space = ["10.0.0.0/20"]
###### Subnets ##############
resource "azurerm_subnet" "subnet1" {
name = "${var.subnet1-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_prefix = "${var.subnet1cidr}"
}
resource "azurerm_subnet" "subnet2" {
name = "${var.subnet2-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_prefix = "${var.subnet2cidr}"
}
resource "azurerm_subnet" "subnet3" {
name = "${var.subnet3-prefix}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.resourcegroupname.name}"
address_prefix = "${var.subnet3cidr}"
}