As part of creating pull request details, we needed to create a CNAME for the new pull request resource group in script. Enter the GoDaddy API. (Link back to main post)
Here we can create API keys to access the GoDaddy API. We need to create two keys, the first is an OTE/Test key, required before you can create the production key. We load the production API key and secret into our Key Vault for usage in our script later.

The new PowerShell script creates the actual DNS entry.
- On lines 1-9, we specify the parameters, including:
- The root domain (e.g. SamLearnsAzure.com)
- The sub domain we need to create (e.g. PR439)
- The website name (e.g. samsapp-pr439-eu-web)
- The type (e.g. cname)
- The GoDaddy key and secret from Key Vault
- Line 11-13 setup the authorization header, using the GoDaddy key and secret
- Lines 16-18 call the GoDaddy API to get the current CNAME –
- Lines 21-22 process the results and establish if the CNAME already exists
- If the CNAME does not exist, lines 24-29 create a new CNAME request array, and “PUT” it back into GoDaddy to create the CNAME DNS record

With the script done, we pass in the parameters, and can create a CNAME entry. The result can be seen below in the DNS settings for SamLearnsAzure.com

Wrap-Up
Today we auto-magically created our DNS records, very useful for our DevOps process. There is one piece we are not able to automate – we can’t delete the CNAME with the API, but we’ve put in a feature request with GoDaddy, and until then, will have to manage it manually.
Update: Deletes have been added to the API. Our implementation is here: https://github.com/samsmithnz/WebhookReceiver/pull/18
References
- GoDaddy API reference: https://developer.godaddy.com/
- The PowerShell Script used in this post: https://dev.azure.com/samsmithnz/_git/SamLearnsAzure?path=%2FSamLearnsAzure%2FSamLearnsAzure.Environment.ARMTemplate%2FPowerShell%2FGoDaddyDNSSetup.ps1
This is fantastic! Is there anyway you can modify the script to pull the subdomain from a .csv so we can create CNAME’s in bulk for the same domain and website?
LikeLike
That’s a great question – I think you can replace all records with the https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceType API entry – but I haven’t used it yet, because I wanted to update each sub-domain separately with automation by environment, not all records together. I could definitely see a situation where this would be useful.
LikeLike