I have a similar Problem. I am trying to deploy the following code listed below (sectioned by folder) and I receive the following error codes:
Error messages:
Error: Reference to undeclared input variable
on main.tf line 12, in resource "azurerm_virtual_network" "web_server_vnet":
12: name = "${var.resource_prefix}-vnet"
An input variable with the name "resource_prefix" has not been declared. This
variable can be declared with a variable "resource_prefix" {} block.
Error: Reference to undeclared input variable
on main.tf line 15, in resource "azurerm_virtual_network" "web_server_vnet":
15: address_space = [var.web_server_address_space]
An input variable with the name "web_server_address_space" has not been
declared. This variable can be declared with a variable
"web_server_address_space" {} block.
Main.tf:
provider “azurerm”{
version = “2.2.0”
features {}
}
resource "azurerm_resource_group" "web_server_rg" {
name = var.web_server_rg
location = var.web_server_location
}
resource "azurerm_virtual_network" "web_server_vnet"{
name = "${var.resource_prefix}-vnet"
location = var.web_server_location
resource_group_name = azurerm_resource_group.web_server_rg.name
address_space = [var.web_server_address_space]
}
variables.tf:
variable “web_server_location” {
type = string
}
variable "web_server_rg" {
type = string
}
variable "resource_prefix" {
type = string
}
variable "web_server_address_space" {
type = string
}
terraform.tfvars:
web_server_location = “westus2”
web_server_rg = “web-rg”
resource_prefix = “web-server”
web_server_address_space = “1.0.0.0/22”