When migrating from an existing infrastructure to an infrastructure managed by Terraform it's possible to import the present configuration. The only thing the importer does not do: It does not write the configuration for you.
This script is intended to access a DNSimple account through the APIv2 and fetch all resource records for all domains in that account. The records are written into a Terraform configuration file using one file per domain.
- Create an APIv2 token in the DNSimple web interface
- Get your account ID for the account you want to export
- Let the script create your configuration:
# export token=<your token> # export account=<your account id> # python fetch.py Fetching records for domain "example.com"... ...
- Review the configuration written by the script (Manual review,
terraform validate
, ...) - Remove all resource records you don't want to manage through Terraform
- Import all the references from your account (remove the
echo
after reviewing the script):IFS=$'\n' for i in $(grep -h 'terraform import' dnsimple* | sed 's/^# //'); do echo eval $i done
- Execute a
terraform plan
to ensure everything is in sync
Now you do have a copy of your existing DNSimple infrastructure inside your Terraform folder and you can start to work on it.