In case you’re not aware, Terraform is pretty cool. It is super powerful, providing the ability to provision infrastructure in seconds using code. Linode and it’s Terraform provider are no exception to this ability. Let’s dive into that…
Requirements
- A machine with Terraform installed
- A Linode account
- With an API token, here’s how you can get this
- This will need at least
Read/Write
access toLinodes
- This will need at least
- With the ability to create nodes (such as with free credits, or with an added bank account)
- With an API token, here’s how you can get this
If you do need to add your bank account, don’t worry! Because of the awesomeness of Terraform, this will only cost a few cents as long as you destroy the infrastructure when it’s all said and done.
GitHub Repo
All configuration files and example files can be found on my Overture repo, under Terraform/Compute/Linode/SimpleLinode.
Create some Terraform files
First thing’s first, let’s create the Terraform files that will define this project.
- Note: You’ll want to make sure you’re in an empty directory
provider.tf
- Defines the necessary provider to use: linode/linode
|
|
variables.tf
- Defines the variables Terraform will use
|
|
credentials.auto.tfvars
- Places values on the variables
- You will need to fill in these values as you see fit, make sure to provide your Linode token
- Note: This should not be a tracked file for anyone to see, it contains sensitive information
|
|
Define the linode_instance
Now, the big (yet small) file that will do the cool stuff:
createSimpleInstance.tf
|
|
Note that there are a few commented lines in case you would like to use them.
This file will take the values of the variables set in credentials.auto.tfvars and create a linode instance based on those values.
Apply configuration
Now, you’re ready to apply!
Go ahead and run
|
|
To see what Terraform will do
And run
|
|
To actually make the changes in Linode
Check your work
Now, log into the Linode console, and watch the magic happen! You should see a new Linode create with the settings you have in the credentials.auto.tfvars file.
Destroy Infrastructure
If you’re like me, you may be paying for this to be up and running. And unless you want to use this server you just created for something, you’ll want to destroy it so no extra charges come into your account.
To destroy your infrastructure with Terraform, run
|
|
And you can watch it magically disappear!