Terraform Explanation with Installation
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions which has been developed by HashiCorp.
A provider is responsible for understanding API interactions and exposing resources.
Most of the available providers correspond to one cloud or on-premises infrastructure platform and offers resource types that correspond to each of the features of that platform.
To make a provider available on Terraform, we need to make a terraform init, these commands download any plugins we need for our providers. If for example, we need to copy the plugin directory manually, we can do it, moving the files to .terraform.d/plugins
provider "aws" {
region = "us-east-1"
}
If the plugin is already installed, terraform init will not download again unless to upgrade the version, run terraform init -upgrade.
Multiple Providers
You can optionally define multiple configurations for the same provider and select which one to use on a per-resource or per-module basis.
#default configuration
provider "aws" {
region = "us-east-1"
}
# reference this as `aws.west`.
provider "aws" {
alias = "west"
region = "us-west-2"
}
Versioning
The required_version setting can be used to constrain which version of the Terraform CLI can be used with your configuration. If the running version of Terraform doesn't match the constraints specified, Terraform will produce an error and exit without taking any further actions.
terraform {
required_version = ">= 0.12"
}
The value for required_version is a string containing a comma-separated list of constraints. Each constraint is an operator followed by a version number, such as > 0.12.0.
Now we will see how to install Terraform on Linux:
Go to your Linux terminal and paste the command:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Now we will install it for MacOS users :
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Now for Windows users, we need to install the package and add it to your path
https://developer.hashicorp.com/terraform/downloads
Now to check if Terraform installed successfully we will use the command:
terraform --version
Now to configure it with AWS use the command
aws configure
After using this command you will be asked for your credentials of AWS access key which you will get from your AWS account easily.
That's a wrap..............