I have the following directory/files structure:
.
├── main.tf
├── modules
│ └── Resource_group
│ ├── main.tf
│ └── vars.tf
Configuration files
./main.tf
module "app-rg" {
source = "./modules/Resource_Group"
}
./modules/resource_group/main.tf
provider "azurerm" {
version = "=2.11.0"
features { }
}
resource "azurerm_resource_group" "rg" {
name = "${lookup(var.resource_group, var.env)}"
location = "${lookup(var.location, var.env)}"
}
./modules/resource_group/vars.tf
variable "env" {
description = "env : dev or prod"
}
variable "resource_group" {
type = "map"
default = {
dev = "rg-dev"
prod = "rg-prod"
}
}
variable "location" {
type = "map"
default = {
dev = "westindia"
prod = "westeurope"
}
}
When I run a "terraform plan" I will get a below error.
Error: Missing required argument
on main.tf line 6, in module "app-rg": 6: module "app-rg" {
The argument "env" is required, but no definition was found.
Why do I get The argument "env" is required, but no definition was found?
env
as a required, non defaulted argument and you haven't provided it when calling the module (you only pass the source argument to link to the module and no other arguments). – ydaetskcoR