Importing Digital Ocean Resources to Terraform
Importing Digital Ocean Resources to Terraform
Prerequisites
-
Make sure your local copy of the Terraform CLI is up to date
-
Ensure you have the Digital Ocean CLI installed and working
-
Make sure your Terraform definition files include a backend definition, e.g (for Terraform cloud).
terraform { cloud { organization = "MYORG" workspaces { name = "MYWORKSPACE" } } }
-
If you haven't already, run
terraform init
in the Terraform model directory -
List your Digital Ocean resources using commands from the Digital Ocean CLI
e.g. to list all servers (droplets) use:doctl compute droplet list
-
Make a note of the IDs of relevant resources
-
For each resource
- create a placeholder in the Terraform model
- run
terraform import -var "do_token=${DIGITALOCEAN_TOKEN}" TERRAFORM_RESOURCE_IDENTIFIER ID
assuming DO access token is in variableDIGITALOCEAN_TOKEN
- fill in the details of the resource definition based on data from
terraform show
-
test your model by running
terraform plan
- should get zero changes proposed when your model is complete