How to deploy a blog with 2 commands using Terraform and Ansible
I am running my blog on Linode, behind Cloudflare and deployed with Ansible. To speed up deployment and make it easily repeatable, I wrote a ton of Python to automate the Cloudflare and Linode configurations. Some for fun, and some because I thought it was a good learning experience.
Don’t get me wrong, I learned a ton about creating repeatable configurations. My issue is that when people say Infrastructure as code (IAC), they don’t mean infrastructure as Python. They mean IAC tools. I got sick of reinventing the wheel so I thought it was time for a change.
I had 2 goals in mind:
Moving away from Python to manage my infra
End-to-end HTTPS from Cloudflare to Linode’s edge
By the end of it, I wanted it all to look like this:
</img>
So when I said “deploy a blog with 2 commands”, it fails to mention a bit of configuration beforehand. We’ll get into the 2 commands a bit later, but let’s address the configurations first.
Automated initial server configuration
Linode, sadly, doesn’t use cloud-init (at the time of writing anyway), so I use their offering, stackscripts.
I showed off the stackscript in my last post so I won’t go into too much detail again here stackscripts/configurealpineweb.sh
Stack script to upload to linode
Cloud services configuration
I had heard of this magical tool terraform before but for some reason, never used it. Something at work popped up and I had an opportunity to play with it. It was love at first sight. It’s such a smooth experience and being able to rapidly scale deployments is incredibly satisfying. I have attached my configurations and explained them in the accompanying Youtube video.
These don’t have to be in separate files. I just like to do it so it is easier to find things later.
The Github action and Ansible
The ansible and GitHub actions configurations haven’t changed since my initial post. I’ll just put the configurations here and you can learn more from the original post or from watching the video.
Finally, we are ready for the commands. To deploy the cloud servers, we need to run:
Then to start the ansible job:
Now the blog is deployed and your infrastructure is managed, when you push new content to the blog, re-run the Ansible playbook and let it do its magic.
I hope you all enjoyed this and someone finds it useful. Please email me or send me a DM on Twitter to let me know what you think!