How to pass variables to different modules

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"
}
}

If the top-level directory in your tree is the one where you are running terraform plan then you should create a variables.tf file in that directory which contains its own variable "app_region" block, so that the root module also expects a variable of that name.

Then in your module block that calls the modules/resource module you can pass the value of that variable down into the child module, similar to passing arguments to a function in a general-purpose programming language:

module "example" {
  source = "./modules/resource"

  # ...
  app_region = var.app_region
  # ...
}

Each module has its own input variables, independent of all others. The -var command line option is for specifying values for the input variables declared in the root module. Variable values for child modules are defined only in the module block that calls the module, but those values can be derived from variables declared in the root module.