Skip to content

Instantly share code, notes, and snippets.

@cfra
Created October 14, 2025 10:32
Show Gist options
  • Select an option

  • Save cfra/cbadb9feabc3ab6a96764f9425ce8e36 to your computer and use it in GitHub Desktop.

Select an option

Save cfra/cbadb9feabc3ab6a96764f9425ce8e36 to your computer and use it in GitHub Desktop.
Migrate from dnsimple_records to dnsimple_zone_records

Migrate dnsimple_records to dnsimple_zone_records

For some reason, DNSimple decided that they need to rename their DNS record resource from dnsimple_record to dnsimple_zone_record.

This requires a quite cumbersome migration on the user's side and the official migration guide leaves a lot to be desired if you have more than a handful of DNS records.

I won't go into the full details of the migration, as it will probably also be somewhat dependent on you exact setup.

Basically, with the old dnsimple provider still installed, first, create a backup of your state with:

terraform state pull

This is your way back if something goes wrong, so don't skip this step.

Now, create a listing of all the dnsimple_record resources that you have in your state:

terraform state list | grep dnsimple_record > dnsimple_records.txt

For these resources, we need to gather their ids, so that we can later re-import them.

Store this as get_ids.sh:

#!/bin/sh                                                                                           
                                                                                                    
while read RESOURCE; do                                                                             
    echo -n "$RESOURCE "                                                                            
    terraform state show "$RESOURCE" \                                                              
         | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" \                                 
         | sed -n \                                                                                 
               -e 's/^ *id *= "\(.*\)"$/\1/p' \                                                     
               -e 's/^ *domain *= "\(.*\)"$/\1/p' \                                                 
         | tr '\n' '_' \                                                                            
         | sed -e 's/_$//'                                                                              
    echo                                                                                            
done

Execute the script:

./get_dnsimple_ids.sh < dnsimple_records.txt > dnsimple_record_ids.txt

Now that you have all the information, delete the old records from the state:

terraform state rm $(cat dnsimple_records.txt)

Once this is done, update the dnsimple provider and replace all ocurrences of dnsimple_record with dnsimple_zone_record in your configuration, usually also replacing the domain property with zone_name.

Once that is done, you can now re-import the records into your state using the file you genrated previously.

Create a shell script import_records.sh:

#!/bin/sh                                                                                           
                                                                                                    
while read RESOURCE ID; do                                                                          
    terraform import "$(echo "$RESOURCE" | sed -e 's/dnsimple_record/dnsimple_zone_record/')" "$ID" 
done

Run that script using the previously generated ID dump:

./import_records.sh < dnsimple_record_ids.txt

Now, everything should be back in sync and terraform should list your state as "No updates needed". 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment