Attach a DNS Zone Entry to Resource Group So It Deletes when Resource Group Deletes

Mike-E-angelo 481 Reputation points
2024-01-27T13:38:20.23+00:00

I am attempting to create an App Service via Bicep that has a custom name + certificate bound to it. This involves setting up CNAME and A records in a DNS Zone hosted on Azure. What I need to do now is that when I delete the Resource Group that hosts this environment, I would like a clean/elegant way of also removing the associated records.
It does not appear that records have a resource group, and the closest thing I found was a Child DNS Zone but that does not seem to apply to this scenario. I'd appreciate any pointers/insight.

Azure DNS
Azure DNS
An Azure service that enables hosting Domain Name System (DNS) domains in Azure.
603 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,140 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,002 questions
{count} votes

Accepted answer
  1. KapilAnanth-MSFT 36,396 Reputation points Microsoft Employee
    2024-01-30T06:33:01.3433333+00:00

    @Mike-E-angelo

    In that case, I am afraid this won't be possible.

    The CNAME inherently takes the RG of the DNS Zone in which it resides. We cannot change this behavior.

    Instead, we must take the precaution to delete the CNAME record either manually or programmatically when you delete the App Service or App Service's custom domain. In Powershell,

    Remove-AzDnsRecordSet -Name "<CNAMERECORDNAME>" -RecordType CNAME -ZoneName "<DNSZONENAME>" -ResourceGroupName "<RGNAME>"
    
    Remove-AzDnsRecordSet -Name "<TXTRECORDNAME>" -RecordType TXT -ZoneName "<DNSZONENAME>" -ResourceGroupName "<RGNAME>"
    
    
    

    Hope this helps.

    Should there be any follow-up questions or concerns, please let us know and we shall try to address them.

    Thanks,

    Kapil

    0 comments No comments

0 additional answers

Sort by: Most helpful