Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

TERRAFORM

A U T O M A T I O N O N A W S
CHAPTER #2
Managing First Server
history
Terraform was first released in July 2014 by a company
named HashiCorp. It is the same company that brought
us tool, such as Vagrant, Packer, and Vault. Being the
fifth tool in the HashiCorp stack, it focused on
providing way to describe the complete infrastructure
as code.

Terraform is an open source tool released under


Mozilla Public License, version 2.0. The code is stored
(as all other tools by HashiCorp) on GitHub, and
anyone can contribute to its development.
history
As a part of its Atlas product, HashiCorp also offers a
hosted service named Terraform Enterprise, which
solves some of the problems that the open source
version doesn't handle well. This includes a central
facility to run Terraform from access control policies,
remote state file storage, notifications, built-in GitHub
integration, and more.

Despite the support of over 40 various providers, the


main focus of HashiCorp developers is on Amazon Web
Services, Google Cloud, and Microsoft Azure. Other
providers are developed & supported by the
community, so if you are not using the main three,
then you might have to contribute to the code base
yourself.
history
The code of Terraform is written in Go programming
language, and it is released as a single binary for
Windows, macOS X, FreeBSD, OpenBSD, Salaris, and
any Linux distribution are supported in both 32-bit and
64-bit versions.

Terraform is still a relatively new piece of tech, being


just a bit over 2 years old. It changes a lot over time
and gets new features with every release.
PREPARING
WORK ENVIRONMENT

We will use Terraform in a Linux


environment

You should have your AWS Free


Tier account ready

One Linux machine connected


to Internet

AWS CLI installed on Linux


machine

Lets Rock !!
download terraform
install terraform
install aws cli
configure aws cli
configure aws cli
When properly configured. You will get these two files
under your home directory. Cross check first, before
proceeding.
check aws cli
Now you should be able to get information from your
AWS account using AWS CLI
setting aws provider
Before using Terraform to create an instance, we need
to configure AWS provider

We need to tell Terraform, that these are my


credentials to be used on AWS for creating
infrastructure

This is the first piece of code we will write in our


template

Templates are written in a special language named


HashiCorp Configuration Language (HCL)
setting aws provider
Its always better not to hardcode your AWS key and
AWS secret key into any template file. Its good to use
environment variables to pass your AWS account
credentials to Terraform.
creating ec2 instance
Resources are components of your infrastructure. It
can be a complete virtual server, or something as
simple as a DNS record. Each resource belongs to
a provider (aws, google, azure), and the type of the
resource is suffixed with the provider name.

The configuration of a resource is like this:

resource "provider-name_resource-type" "resource-name" {


parameter_name = parameter_value
}
creating ec2 instance
For creating EC2 instance. The aws_instance resource
is used. To create an instance, we need to set at least
two parameters: ami and instance_type .

Some parameters are required, whereas others are


optional, ami and instance_type the required ones.

Get the list and description of all the aws_instance


resource parameters, check out: 

https://www.terraform.io/docs/providers/aws/r/instance.html
creating ec2 instance
Here we are creating a RHEL7 instance.
creating ec2 instance
Applying our first Terraform template, might result in
error, as provider scripts are not yet downloaded.
creating ec2 instance
Use the "terraform init" command to download and
install respective provider scripts.
creating ec2 instance
Lets apply the template now.
creating ec2 instance
creating ec2 instance
We can confirm the creation of EC2 instance using AWS
dashboard.
QUESTIONS

You might also like