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)