I would like to run terraform plan -var-file -out and then apply the plan but I get the following error.
Here's my main.tf, variable.tf and networking.tfvars file below:
###### 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}"
Variables File
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"
Command that I'm trying to execute:
terraform plan -var-file="networking.tfvars" -out="networkingplan.out"
Error message:
azurerm_subnet.subnet1: "address_prefix": required field is not set azurerm_subnet.subnet1: : invalid or unknown key: address_space azurerm_subnet.subnet2: "address_prefix": required field is not set azurerm_subnet.subnet2: : invalid or unknown key: address_space azurerm_subnet.subnet3: "address_prefix": required field is not set azurerm_subnet.subnet3: : invalid or unknown key: address_space azurerm_subnet.subnet4: "address_prefix": required field is not set azurerm_subnet.subnet4: : invalid or unknown key: address_space azurerm_subnet.subnet5: "address_prefix": required field is not set azurerm_subnet.subnet5: : invalid or unknown key: address_space azurerm_subnet.subnet6: "address_prefix": required field is not set azurerm_subnet.subnet6: : invalid or unknown key: address_space azurerm_virtual_network.vnet: address_space: should be a list