Infrastructure as Code: The New Normal

Tasks such as creating a repository, adding a new user, provisioning or configuring a server are processes that could be codified — and are reusable and reproducible.

Yea sure automation of operations and system administrative task by way of infrastructure as code may seem daunting and to most like a waste of time.

However the gains of including this as a must do in your software development workflow is priceless.

It gives one the liberty to make best decisions of what they need, and puts you in charge by giving a well documented model of what works, and a potential to improve on it just like the applications we code.

In this walk-through we have demoed a kind of “hello, world” of infrastructure as code to give a quick view of this domain.

I have made a few assumptions that you have an AWS account and have retrieved an API access id and secret key.

See https://bit.

ly/2D0OOxN and https://bit.

ly/2TGVNBG for signing up and creating an AWS user account.

I also assumed that you have downloaded and installed the terraform binary for your operating system.

To do so please follow this link https://bit.

ly/2FhGM65The repo for this demo can be found here https://github.

com/knoxknot/iaac So we have just a folder with four .

tf files and one .

sh file which respectively represents the terraform and bash scripts.

These files exemplifies a series of task an operator would perform in standing a single web server and provisioning it with an application.

Doing this in production is a little more complex than this though; never to worry you will get there believe me.

Let us get you to understand what the lines of codes within these files intendsThe resources.

tf is where we create the actual resources and components we desire.

The “provider” object sets our specific cloud provider and the authentication mechanism to gaining access to it.

The “data” object collects existing resource on our cloud provider.

In this case we are getting an amazon machine image of ubuntu OS.

The “resources” objects creates the actual resources — key pair, security group (firewall) to controls inbound and outbound traffics into our server and finally the webserver.

In the variables.

tf we defined and initialized some variable http_port, ssh_port to avoid hot coding these values within the resources.

tf and essential keep things modular.

The inputs.

auto.

tfvars is where you pass in the values to variables declared in variables.

tf especially values subject to modification.

I could choose to use a new instance type instead of t2.

micro and that I would not want to be initialized within the variables.

tfThe outputs.

tf here we state the attributes we could like to be returned after the process has being ran successfully.

So we want to get the public ip and domain name of the instances after it has being provisioned.

User-data.

sh is a bash script with which to bootstrap the instance on launch.

So we are simply printing the sentence into an index.

html file created on the fly.

Then using busybox we orchestrate some sort of server implementation listening on port 80 and running in the background.

Workflow Proceduresstep 1: open the folder in your editor of choice ( make sure to have an integrated terminal to it)step 2: export your aws credentials into the environment variable namespaceRun: export TF_VAR_secret_key=”insert your secret key here”export TF_VAR_access_key=” insert your secret key here”step 3: believing you have the openssh application within the terminal create a directory “keys” within the IAAC folder and run the underlisted commands to generate key pair for your server.

Run: ssh-keygen -t rsa -b 4096 -C “webserver key”on promptType: .

/keys/server_keystep 4: download the terraform aws provider pluginRun: terraform initstep 5: validate the codes are syntactically correctRun: terraform validatestep 6: get an overview of the resources to be deployed and its attributedRun: terraform planstep 7: deploy these resources on the cloud providers platformRun: terraform applystep 8: copy either of the outputs — server_ip or server_dns — unto an internet enabled browser to observer the results.

Voila you have your Hello world of infrastructure as code up and running.

.

. More details

Leave a Reply