Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script to add CAA records to Azure DNS
#More info: https://geertdegraaf.nl/adding-caa-records-to-azure-dns
#login with Azure Account
Login-AzureRmAccount
#select subscription with Azure DNS
Get-AzureRmSubscription
Set-AzureRmContext -SubscriptionId "xxxx-xxxx-xxxx-xxxx"
#List all ResourceGroups in Subscription
Get-AzureRmResourceGroup
#List all DNS zones in ResourceGroup
Get-AzureRmDnsZone -ResourceGroupName %ResourceGroupName%
#List all CAA records for DNS zone
Get-AzureRmDnsRecordSet -ResourceGroupName DNSExample -ZoneName example.com -RecordType CAA
#Preparing
records
$caaRecords = @()
$caaRecords += New-AzureRmDnsRecordConfig -CaaFlag "0" -CaaTag "iodef" -CaaValue "mailto:admin@example.com"
$caaRecords += New-AzureRmDnsRecordConfig -CaaFlag "0" -CaaTag "issue" -CaaValue "letsencrypt.org"
#for wildcard uncomment next line
#$caaRecords += New-AzureRmDnsRecordConfig -CaaFlag "0" -CaaTag "issuewild" -CaaValue "letsencrypt.org"
#Adding CAA records
New-AzureRmDnsRecordSet -Name "@" -RecordType CAA -ZoneName "example.com" -ResourceGroupName DNSExample -Ttl 3600 -DnsRecords $caaRecords
#Verify CAA records are added in the DNS zone
Get-AzureRmDnsRecordSet -ResourceGroupName DNS -ZoneName example.com -RecordType CAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment