Create NEW Azure RG

I’m creating new VNET in Azure and it works fine if I’m reusing an existing Resource group name. If try to create new Resource Group it fails the code. Are you able to create new Resource group?

variable “resource_group_name” {
description = “Resource group name”
type = string
default = “myrg”
}

module “vnet-main” {
source = “Azure/vnet/azurerm”
resource_group_name = azurerm_resource_group.myrg.name #Calling the variable.
#location = var.location
vnet_name = var.vnet_name
address_space = [“10.0.0.0/24”]
subnet_prefixes = var.subnet_prefixes
subnet_names = var.subnet_names
nsg_ids = {}
tags = {
environment = “dev”
}

}

Error being received.

terraform plan -var resource_group_name=myrg -out vnet.tfplan


│ Error: Error: Resource Group “myrg” was not found

│ with module.vnet-main.data.azurerm_resource_group.vnet,
│ on .terraform/modules/vnet-main/main.tf line 2, in data “azurerm_resource_group” “vnet”:
│ 2: data azurerm_resource_group “vnet” {

Already fixed. Using resource instead of module for creating new VNET is working fine.
See the code I used.
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network