Automating Go-Daddy CNAME creation with PowerShell

Posted by

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.

References

4 comments

  1. 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?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s