Professional Documents
Culture Documents
What is terraform?
Terraform is an open-source infrastructure as Code tool developed by HashiCorp.
It is used to define and provision the complete infrastructure using an easy-to-
learn declarative language.
Terraform Core
Providers
Terraform Core
So, what terraform core does is it takes the input, and it figures out the plan of
what needs to be done. It compares the state, what is the current state, and what
is the configuration that you desire in the end result. It figures out what needs to
be done to get to that desired state in the configuration file. It figures what needs
to be created, what needs to be updated, what needs to be deleted to create and
provision the infrastructure.
Providers
The second component of the architecture are providers for specific technologies.
This could be cloud providers like AWS, Azure, GCP, or other infrastructure as a
service platform. It is also a provider for more high-level components
like Kubernetes or other platform-as-a-service tools, even some software as a self-
service tool.
Terraform has over a hundred providers for different technologies, and each
provider then gives terraform user access to its resources. So through AWS
provider, for example, you have access to hundreds of AWS resources like EC2
instances, the AWS users, etc. With Kubernetes provider, you access to
commodities, resources like services and deployments and namespaces, etc.
So, this is how Terraform works, and this way, it tries to help you provision and
cover the complete application setup from infrastructure all the way to the
application.
Pre-Requisites:
• Install Terraform CLI
https://www.terraform.io/downloads
• Install AWS CLI
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
• Install VS Code Editor
https://code.visualstudio.com/
• Install HashiCorp Terraform plugin for VS Code
Installing Terraform
Step 1: Installing Terraform:
Head over to the link provided below and download the terraform executable
https://www.terraform.io/downloads
Step 2: Place the executable in any folder in your c:\\ directory.
Step 3: Edit the system environment variables and set the path to where you
placed you terraform.exe in c:\\ directory
The path is in the registry but usually you edit through this interface:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.28.0"
}
}
}
provider "aws" {
region = "us-east-1"
# Configuration options
}
In the above example our configuration begins with “terraform {}” block which is
used to configure the behavior of terraform itself. For example we can add
“terraform version = 1.0 “ .
Next is required provider where we define the provider we intent to use with
terraform, in our case its AWS.
Providers require source and version information which can be obtained from
terraform provider documentation.
Next is provider block where we define configurations that we wish to use with
the provider mentioned above under “required provider” block. For example if
you have mentioned “AWS” under required provider then over here in “provider
block” you have to mention “AWS” i.e the providers need to be the same in both
the blocks.
Inside provider block we can define region in which we intent to deploy our aws
resources.
Next is “resource block” where we have defined the ec2 resource so that we can
deploy our ec2 instance.
Note that all the supported arguments and attributes for this can be obtained
from resource documentation. For now “instance_type” and “ami” are defined.