As I’ve been working with the k3s machine, I have found myself enjoying the IT side of projects as much as the projects themselves. Working with k3s, I guess the natural next step is to think about how to set up resources with code. It also helps that I was looking at a job description and noticed the word “Terraform”.
What is Terraform?
It’s a way to declare and codify infrastructure such as servers, network, and other resources. It’s declarative so think of it as telling someone what you want the end result should be. ” I want to setup or use this VPS.”
Why Infrastructure as Code?
Reproducibility – If there’s a server outage or I need to move regions, I can run a command and we’re back exactly as it was.
Efficiency – I don’t have to traverse page after page of the console or dashboard and manually configure the basic rules.
Version control – I can see what I changed and roll it back if needed.
Audit – I can look up firewall rules, see what ports are open, etc.
That’s what I’ll be taking advantage of as I build the network out. For right now, I just wanted to start simple. I want to start with my VPS Server. One thing to note, I already have a VPS up and running. My first task was to import my existing VPS configs. I wanted to be careful as to not destroy or change what’s already running.
My first step was to create the main.tf
terraform {
required_providers {
provider = {
source =
version =
}
}
}
provider "provider" {
token = var.token
}
resource "resource_type" "local_name" {
name =
image =
server_type =
location =
firewall_ids =
}
After running ‘terraform plan’, I could see that there were no changes planned. The terraform configs match what the current state of the server is, and I now have a record for any changes made to it.
Should something happen to my VPS, I can run ‘terraform apply” and we’re back. Currently, this just spins up another VPS. I need to build it out so that it recreates the firewall rules. That’s next.

