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 pullThis 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.txtFor 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
doneExecute the script:
./get_dnsimple_ids.sh < dnsimple_records.txt > dnsimple_record_ids.txtNow 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"
doneRun that script using the previously generated ID dump:
./import_records.sh < dnsimple_record_ids.txtNow, everything should be back in sync and terraform should list your state as "No updates needed". 🎉