Accessing variable from other module

Hi Everyone,

I am getting error while using module
mod/resource_group.tf

variable "region" {
    type=string
    default="Central India"
}

resource "azurerm_resource_group" "app_resource_group" {
  name     = "app_grp"
 location =var.region
}

app_nic.tf

module "test" {
    source="./mod"
}

resource "azurerm_virtual_network" "app-network" {
  name                = "app-vnet"
  address_space       = ["10.0.0.0/16"]
  location            = module.test.region
  resource_group_name = module.test.azurerm_resource_group.app_resource_group
}

I am getting below error on my VScode terminal

PS D:\terraform_practicals\terraform-begins> terraform plan
╷
│ Error: Unsupported attribute
│
│   on app-nic.tf line 8, in resource "azurerm_virtual_network" "app-network":
│    8:   location            = module.test.region
│     ├────────────────
│     │ module.test is a object
│
│ This object does not have an attribute named "region".
╵
╷
│ Error: Unsupported attribute
│
│   on app-nic.tf line 9, in resource "azurerm_virtual_network" "app-network":
│    9:   resource_group_name = module.test.azurerm_resource_group.app_resource_group
│     ├────────────────
│     │ module.test is a object
│
│ This object does not have an attribute named "azurerm_resource_group".
PS D:\terraform_practicals\terraform-begins> 

I have main.tf file also , there i have mentioned credentials of azure

Terraform is pretty strict about references across states or modules. You can’t directly refefence things in the module without creating an output. So to reference something from a module elsewhere, you’ll need to create an output in your module. Then you can reference it.

For example, if you wanted to reference the ID, in your module (by convention, in outputs.tf, though it could go anywhere):

output "resource_group_id" {
  description = "The resource group"
  value       = azurerm_resource_group.app_resource_group.id

and then you’d reference it via module.test.resource_group_id