Hello Folk,
I am newbie in terraform and wanted to ask when we have different modules(refer below hierarchy) and inside modules in every main file we are calling variables.
├── main.tf
├── main.tfplan
├── modules
│ ├── network
│ │ ├── back
│ │ │ └── app-nic.tf
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── resource
│ │ ├── back
│ │ │ ├── output
│ │ │ └── output_resource.tf
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── storage
│ │ └── storage.tf
│ └── vm
│ ├── backup
│ │ └── linux_vm.tf
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
If i assign value to variable during runtime , it gives error.
terraform plan -var "app_region=Central India" -out main.tfplan
╷
│ Error: Value for undeclared variable
│
│ A variable named "app_region" was assigned on the command line, but the root module does not declare a variable of that name. To use
│ this value, add a "variable" block to the configuration.
╵
I have provided additional info , if anyone can provide their thoughts it will be learning for me
cat modules/resource/variables.tf
variable "resource_name" {
description = "Create resouce group"
type=string
default="app-grp"
}
variable "app-region" {
description = "Location of app resource"
type=string
default="Central India"
}
cat modules/resource/main.tf
resource "azurerm_resource_group" "app_resource_group" {
# lifecycle {
# create_before_destroy = true
# }
name = var.resource_name
location = var.app-region
timeouts{
create = "1m"
delete = "1m"
}
}