Import DigitalOcean DNS Records to Terraform

For the following step I assume that you have Terraform already configured and the DigitalOcean provider retrieves the authentication token from the DIGITALOCEAN_TOKEN environment variable.

If you have an old provider version you’ll need to upgrade the provider using terraform init -upgrade as the capability was added to provider as part of pull request #71 which is included in v1.0.0.

First we need to lookup the key id for the DNS resource record that we want to import through the DigitalOcean REST API:

http https://api.digitalocean.com/v2/domains/2i.at/records “Authorization:Bearer $DIGITALOCEAN_TOKEN”

We then use this ID to import the record into Terraform:
terraform import digitalocean_record.ns[0] 2i.at,25712647

Now you can execute terraform plan again and take it from there.

Written by

Software Engineer with an interest in Cloud Platforms and DevOps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store