* Traditional Deployment and Challenges
- Using Infrastructure as code (IAC), we can define infrastructure as code using simple, human readable, high level
language.
,i) Configuration Management Tools
- Commonly used to install and manage software on existing infrastructure resources such as servers, databases, etc.
- Unlike ad-hoc shell scripts, these maintains a consistent and standard structure of code.
- Designed to run on multiple remote resources at once.
- can be checked into version Control repository. This allows to us to reuse and distribute as needed.
- Idempotent
- E.g: Ansible, chef, puppet, saltstack
ii) Server Templating Tools
- can be used to create custom image of a virtual machine or container. These image contains pre-installed softwares and
dependencies.
- Virtual Machine or Docker Images
- Immutable infrastructure
- E.g: Docker, Vagrant, Packer
iii) Provisioning Tools
- used to provision infrastructure using simple declarative code.
- These infrastructure components can range from servers, VMs, databases, network components, etc.
- CloudFormation is used to deploy services in AWS while Terraform is vendor agnostic and provides plugins for all major
cloud providers.
- e.g: Terraform, CloudFormation
* Why Terraform
- Infrastructure Provisioning Tool
- Free and open source, developed by Hashicorp
- can be used to deploy infrastructure across various platforms (public and private cloud)
- uses HashiCorp Configuration Language (HCL)
- File has .tf extension
- work in three phases: init -> plan -> apply
> Init phase – initializes the project and identifies the provider to be used for the target environment.
> Plan phase – terraform drafts a plan to achieve the target state.
> Apply phase – makes the necessary changes required on the target environment to bring it to the desired state.
,- Every object that terraform manages is called resource. Terraform manages the lifecycle of the resource form
provisioning to configuration to decommissioning.
- Makes sure that the infrastructure is in desired state at all times.
* Installing Terraform
$ wget https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip
$ unzip terraform_0.13.0_linux_amd64.zip
$ mv terraform /usr/local/bin
$ terraform version
Terraform v0.13.
* HashiCorp Configuration Language (HCL) Basics
- consists of blocks (defined within curly braces, contains a set of arguments in key = value pair format representing the
configuration data) and arguments
> What is a block? What arguments does it contains?
- A block in terraform contains information about infrastructure platform and a set of resources within that platform that
we want to create.
- Each resource type expects different types of arguments that they expect.
, * Terraform Workflow
- A simple terraform workflow consists of four steps:
i) Write the configuration file
ii) Run terraform init command
iii) Review the execution plan using terraform plan command. It will not create any resource at this step.