Blog

How to migrate domain names to Google Cloud DNS

26 May, 2022
Xebia Background Header Wave

When you want to migrate DNS domains to the Google Cloud DNS, you need to migrate the content of your domain name servers first. In this blog, I will introduce you to a small utility which helps you to do just that!

Google Cloud DNS is a managed domain name server service, with a 100% uptime guarantee. To get that, you need to create a DNS managed zone in Cloud DNS and recreate all dns records. But migrating dns records is tricky. If you make a mistake, your systems may be down for prolonged periods of time.

To reduce the probability of errors, we created the zonefile-migrate utility. The tool parses a zonefile and generates a Terraform template.

In this way, you can reliability migrate your domain names to Cloud DNS in three simple steps:

  1. request the zonefiles from your registrar
  2. convert the zonefiles to terraform
  3. deploy the managed zones.

It is as simple as that. After this, you can change the name server registration and start the domain name transfer process.

request the zonefiles

Normally you request the zonefiles at your registrar. In this case, we use our two example domains: asample.or and land-5.com. To download these, type:

$ git clone  https://gitlab.com/binxio/zonefile-migrate.git
$ cd zonefile-migrate/example

convert to Terraform

To convert the zonefiles to terraform, type:

$ zonefile-migrate to-terraform --provider google ./zones ./templates/dns
INFO: reading zonefile zones/asample.org
INFO: reading zonefile zones/land-5.com

deploy the managed zones

To deploy these managed zones to Google Cloud Platform, type:

$ terraform init
$ export GOOGLE_PROJECT=$(gcloud config get-value core/project)
$ terraform apply -auto-approve
...
Terraform will perform the following actions:

# module.asample_org.google_dns_managed_zone.managed_zone will be created
+ resource "google_dns_managed_zone" "managed_zone" {
    + description   = "Managed by Terraform"
    + dns_name      = "asample.org."
    + force_destroy = false
    + id            = (known after apply)
    + name          = "asample-org"
    + name_servers  = (known after apply)
    + project       = (known after apply)
    + visibility    = "public"
      }
...
Plan: 49 to add, 0 to change, 0 to destroy.
module.land-5_com.google_dns_managed_zone.managed_zone: Creating...
module.asample_org.google_dns_managed_zone.managed_zone: Creating...
...

That is it. It is that simple!

Installation

To install the utility, type:

pip install zonefile-migrate

After you successfully created the managed zones, you can change the nameservers at your registrar and optionally move the registration of the domain to Google too.

Conclusion

By using zonefiles to generate the Terraform template, you minimize the potential for errors when migrating domain names to Google Cloud DNS. As an extra bonus, you have the basis for maintaining your zones as code!

Image by Gordon Johnson from Pixabay

Mark van Holsteijn
Mark van Holsteijn is a senior software systems architect at Xebia Cloud-native solutions. He is passionate about removing waste in the software delivery process and keeping things clear and simple.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts