iac-env / Part 1 - Introduction
Marcel Braghetto 3 May 2020
Welcome to my learning adventure about infrastructure as code! At the time of authoring these articles I had just begun some work that required me to skill up a bit with Amazon Web Services and learn some tools that can assist with automation of provisioning cloud resources. All of this was very new to me and I started to experiment with tools and techniques to build up my knowledge - I figured I could write up my experience here and share the knowledge I’ve gathered. No doubt some of this stuff will seem very basic to those who have been in the profession for a while but we all gotta start somewhere!
In these articles I will explain the approach I took to create a self contained Docker image that acts as both a developer sandbox for writing cloud stuff locally, as well as being a build agent in a Jenkins build pipeline to perform the building, testing and deployment of cloud resources.
We will I use a bunch of interesting tools in this experiment, a number of which I had never used before:
- Docker: This will be the tool we use to create and run the self contained environment which we shall lovingly know as iac-env (Infrastructure as Code - Environment). https://www.docker.com
- Terraform: We will use the Terraform product from HashiCorp as a cloud agnostic scripting language for describing our cloud resources. We will only target AWS (Amazon Web Services) but it can be used for many provisioning tasks. https://www.terraform.io
- TFLint: This is an open source tool that can help us perform static code analysis on our Terraform scripts. https://github.com/terraform-linters/tflint
- Terraform Kitchen: This is a test orchestration wrapper that sits on top of Chef InSpec to make it easy to run Terraform test suites. https://newcontext-oss.github.io/kitchen-terraform
- AWS CLI: The Amazon Web Services command line interface (AWS CLI) will allow us to run arbitrary AWS commands from the command line. https://aws.amazon.com/cli
- Bitbucket: We will use a local standalone instance of Bitbucket to be our Git repository. The info in these articles could be applied to other Git providers too such as Github etc. https://confluence.atlassian.com/bitbucketserver
- Jenkins: This will be our build pipeline system that will detect code changes in our Git repository and run a sequence of build, test and deployment steps on our infrastructure code, using the iac-env environment to do it. https://www.jenkins.io
The goals are:
- Create a Docker image named iac-env which will package up all the command line tools we need to do local development as well as behave as a build agent in a Jenkins build pipeline.
- Create a simple Terraform based project that describes how to provision some AWS resources.
- Write some automated testing that we can run on our Terraform project through Terraform Kitchen to verify it.
- Setup an automated build pipeline in Jenkins which orchestrates checking and testing our code, then deploys it on demand. We will configure Bitbucket to notify Jenkins when Git changes happen to trigger this build pipeline.
What you will need
An AWS account: You can follow quite a lot of this without having an AWS account but you will need one if you want to try out actually running Terraform code to test and deploy AWS resources.
Linux or MacOS: It’s possible this stuff can be done on Windows as well but I didn’t investigate that too much, though I actually did do most of the development for these articles on my Windows machine, but within Linux Mint running in VirtualBox! So if you only have a Windows machine and want to follow along, just install Linux in VirtualBox like I did and you can do it too!
Although I did most of the dev for this series in Linux Mint, I wrote up these blog articles on my MacBook Air testing it along the way on MacOS and found a bunch of differences running Docker on MacOS compared to Linux! I’ve tried my best to make sure this experiment can be run on MacOS as well as Linux but to be honest I found doing it on MacOS to be a pain compared to Linux.
Source code can be found at: https://github.com/MarcelBraghetto/iac-env
Continue to Part 2: Create iac-env Docker image.
End of part 1