Skip to content

ciro-mota/terra-linode

Repository files navigation

Terra Linode

License Linode Terraform OpenTofu Ansible Debian Ubuntu AlmaLinux Rocky Linux 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 modules/linode/variables.tf files if you wish.
  • Run terraform init, terraform plan -out= name-of-the-plan and terraform apply. At the end, terraform destroy.

Tip

If you receive the following error when connecting to your instance:

Received disconnect from 45.xx.xx.xx port 22:2: Too many authentication failures
Disconnected from 45.xx.xx.xx port 22

Run the following command to access:

ssh -o IdentitiesOnly=yes [email protected] -i .ssh/id_rsa.pub

🔧 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 upload it to the instance via the .sh file that will be called on line 12 of the modules/linode/resources.tf file.

To work with these settings uncomment line 10 in the modules/linode/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.
  • Uncomment and 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.

About

Provision instances on Linode with Terraform or OpenTofu.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Contributors