My Digital Garden

Importing Digital Ocean Resources to Terraform

Importing Digital Ocean Resources to Terraform

Prerequisites

  1. Make sure your local copy of the Terraform CLI is up to date

  2. Ensure you have the Digital Ocean CLI installed and working

  3. Make sure your Terraform definition files include a backend definition, e.g (for Terraform cloud).

    terraform {
      cloud {
        organization = "MYORG"
    
        workspaces {
          name = "MYWORKSPACE"
        }
      }
    }
  4. If you haven't already, run terraform init in the Terraform model directory

  5. List your Digital Ocean resources using commands from the Digital Ocean CLI
    e.g. to list all servers (droplets) use:

    doctl compute droplet list
    
  6. Make a note of the IDs of relevant resources

  7. For each resource

    1. create a placeholder in the Terraform model
    2. run terraform import -var "do_token=${DIGITALOCEAN_TOKEN}" TERRAFORM_RESOURCE_IDENTIFIER ID
      assuming DO access token is in variable DIGITALOCEAN_TOKEN
    3. fill in the details of the resource definition based on data from terraform show
  8. test your model by running terraform plan - should get zero changes proposed when your model is complete

See also