Skip to content

Provision instances on Linode with Terraform or OpenTofu.

Notifications You must be signed in to change notification settings

ciro-mota/terra-linode

Repository files navigation

Terra Linode

License Linode Terraform OpenTofu Ansible AlmaLinux Rocky Linux CentOS Debian Ubuntu Alpine Shell Script

This project aims to provision instances on Linode with the help of Terraform.

⚠️ Caution!

Linode charges you for the use of VMs even if they are in a powered off state and this can cause a huge cost issue for some people. So you can never forget to destroy your instances after some testing.

📌 Before executing:

Note

It is necessary to get credentials for Terraform execution.

  1. Create a Linode Personal Access Token.

  2. Add two variables to your .bashrc or .zshrc file:

export TF_VAR_LINODE_CLI_TOKEN=<your-personal-access-token>
export TF_VAR_public_key_path=$(cat /home/your-username/.ssh/id_rsa.pub)

💻 Usage

  • Clone this repo.
  • By default an instance with Debian 12 with g6-nanode-1 will be provisioned, if you want another OS or machine, modify the variables.tf files if you wish.
  • Run terraform init, terraform plan -out= name-of-the-plan and terraform apply. At the end, terraform destroy

🔧 Stackscripts

You can also apply post-installation scripts to your Linode instance through Stackscripts. This project counts as example scripts for nginx provisioning provided by Ansible Galaxy.

You can create your own script and send it into the instance via the bash <(curl -sk URL) line in the resources.tf file.

To work with these settings, uncomment line 10 in the instance.tf file.

💾 Remote state

By default this block will be commented. Uncomment if you use it.

You must manually create a bucket in Object Storage and create Access Keys for it.

Linode Object Storage supports S3-compatible applications, so the aws cli is supported for file handling with Linode.

  • Install aws cli.
  • Run the command aws configure --profile linode for configuration.
  • When prompted, enter the access_key_id and secret_access_key provided values obtained earlier. The region field can be left blank.
  • Add the same variables to your .bashrc or .zshrc file by filling them in with the Access Keys values obtained earlier:
export TF_VAR_access_key_id=<your credentials>
export TF_VAR_secret_access_key=<your credentials>
  • Uncomment lines 8 to 13 of the variables.tf file.
  • Edit lines 11, 17 and 19 of the main.tf file with the information about your bucket and the region in which it was created.

🎁 Sponsoring

If you like this work, give me it a star on GitHub, and consider supporting it buying me a coffee:

PayPal