Am fairly new to Terraform, I’m currently building an environment in Azure.
I’ve started using modules and using .tfvars files. When I go to deploy I hit this error
Error: Reference to undeclared input variable
on main.tf line 4, in module "rsgrp":
4: location = var.location
An input variable with the name "location" has not been declared. This
variable can be declared with a variable "location" {} block.
In my .tfvars file this is out how it’s set:
environment = "dev"
location = "uksouth"
failover = "ukwest"
My module is set out like this
resource "azurerm_resource_group" "rsgrp0" {
name = "rg-ngd-$(var.environment)-inf-01."
location = var.location
}
In my main.tf file is set out like this
module "rsgrp" {
source = "./rsgrp"
environment = var.environment
location = var.location
}
This is where I use >terraform plan -var-file="../../environments/dev.tfvars"
Don’t understand why I get the error when the variable is being called in the main.tf file.
Can someone please explain?
Thank You