provider.tf
How I setup terraform for my homelab on a Digital Ocean VPS
I was watching a Youtube video and the guy in the video mentioned that, "Every DevOps Engineer needs a Homelab". This is something I may agree with but, what did I know about Homelabs? So naturally, I accepted the challenge to create one.
So to get started with, where I wanted to host it.
Now, this debate sparked in my mind because when people hear Homelabs, they think, "oh a nice little server room inside your house". Well, I would love to have one of those, but I don't really need one, so just a simple DigitalOcean Droplet will suffice for my needs.
And the basic idea of what I want to generally accomplish is, I want to have a simple server that I can use to manage a kubernetes cluster and maintain it.
The primary motive is so I can learn how to debug production level issues and get to learn a lot more technologies. The secondary motive is to just have fun.
FYI, I am a mere software engineer and I'm in my DevOps phase :)
So to get started, I used Terraform to set up the whole thing so I can use nginx and stuff like that. In this blog, we'll try to simply show an HTML page on the server. Nothing more.
Let's first start with Terraform.
Above are a few guides that I found useful. You can use them or not. Just be aware my method of learning is trial and error (basically bruteforcing until everything works correctly), I read the documentation afterwards.
First things first, created a Github Repo to upload all my files regarding the Homelab.
Step two, creating the terraform files.
A simple provider.tf configures what our Infrastucture provider is and the general Terraform configuration. This is my second time using Terraform, so some of them might still not be optimized.
and next a homelab.tf file to specify what and where our droplet is.
Now then you'll need a DigitalOcean API key and an SSH key configured into your account, My SSH key is named id_rsa bigchungus and I have a DigitalOcean API key generated, which is a secret.
Now you need to get terraform installed. This is the official guide
And then you need to run a few commands and you'll have a server up and running.
While executing it will ask for the DigitalOcean API key and the SSH key path.
And after a few seconds your server will be up and running.
Next we'll have to install ngnix. My plan is to display a simple html page on the server.
First we'll need to access the server,
So I SSHed into the server and installed ngnix.
Then after the ngnix server is restarted, I went to /var/www/html/ and added my static html file.
You can make the HTML file however you want, you can get it via git, or copy and paster it, whaterver you want.
Now we need to check and fix some permissions.
Basically what this does is, it changes the owner of the directory to the ngnix user and gives the user read, write and execute permissions.
Then get the default ngnix configuration
Make sure it's somewhat like the configuration below:
Then test and restart the ngnix server
Now if I go to the Server's IP address, I can see the static site. Yay!
But a big part of why I'm learning this is so I can automate it, so let's automate this whole thing in Terraform by changing the homelab.tf file.
The whole setting up thing will be automated now.
If you want to try out the thing, the whole thing is in the git repo, feel free to clone it and run with your own config