Terraform wont stop destroying resource groups before deploying new resources

I have vnet module and subnet module that I am using as layers and i am creating subnets through locals for the subnet prefixes and names. I am also using a data block to reference the outputs for the vnet resourcegroup and region, but when i do a tf apply its destroying the resource groups , is there a way to prevent this? i have also added lifecycle prevent destroy at the root module resource group.

Here is my code:

data "azurerm_subscription" "current" {}

data "terraform_remote_state" "resource-group" {
  backend = "azurerm"
  config = {
    resource_group_name  = cremote-state-config.resource_group_name
    storage_account_name = local.data.remote-state-config.storage_account_name
    container_name       = local.data.remote-state-config.container_name
    key                  = "resource-groups.tfstate"

module "vnet" {
  source              = "../modules/vnet"
  count               = local.data.inflate ? 1 : 0
  vnet-name           = local.data..vnet-name
  resource-group-name = data.terraform_remote_state.resource-group.outputs.hub.name
  region              = data.terraform_remote_state.resource-group.outputs.hub.location
  vnet-address-space  = local.data.address_prefix
  tags                = local.data.tags

module "subnet" {
  source                                         = "../modules/subnet"
  for_each                                       = local.subnets
  subnet-name                                    = each.value.subnet_name
  resource-group-name                            = data.terraform_remote_state.resource-group.outputs.hub.name
  vnet-name                                      = module.vnet[0].vnet.name
  subnet-prefixes                                = each.value.address_prefixes

destroy message am getting:

  # module.spoke-resourcegroup.azurerm_resource_group.rg will be destroyed
  # (because azurerm_resource_group.rg is not in configuration)

If you don’t want them to be destroyed, you shouldn’t be removing them from the configuration. Why have you done that?

Also, I don’t think you’ve shown enough of your configuration for people to really understand what is going on. For example, there is no mention of “spoke-resourcegroup” in the code you shared. You also mentioned using prevent_destroy but it doesn’t appear anywhere in the code you shared.