Importing Linode resources to Terraform
Importing Linode resources to Terraform
-
Make sure your local copy of the Terraform CLI is up to date
-
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
-
Ensure that Python 3 and pip3 are both installed on your local machine (Linode API prerequisite)
-
Get a Linode API token
- Set environment variables
LINODE_TOKEN
andLINODE_CLI_TOKEN
with the value of the token
- Set environment variables
-
Install Linode CLI (you may want to define and activate a Python Virtual Environment first)
-
Get a list of your resources using CLI commands, e.g.
- servers -
linode-cli linodes list --json --pretty
- domains -
linode-cli domains list --json --pretty
- domain records -
linode-cli domains records-list DOMAINID --json --pretty
- node balancers -
linode-cli nodebalancers list --json --pretty
- node balancer config -
linode-cli nodebalancers configs-list NODEBALANCERID --json --pretty
- node balancer nodes -
linode-cli nodebalancers nodes-list NODEBALANCERID NODEBALANCERCONFIGID --json --pretty
- servers -
-
From the output of the previous command(s), make a note of the
id
for each resource -
For each resource
- create a placeholder in the Terraform model
- run
terraform import linode_instance.LABEL ID
- 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