What is Terraform Terraform is an open-source Infrastructure as a code(IAC) tool, it was developed and managed by...
What is Terraform
Terraform is an open-source Infrastructure as a code(IAC) tool, it was developed and managed by Hashicorp.
Terraform has automated the provisioning, configuring, and managing of the infrastructure. Mainly it is used for provisioning the infrastructure. can deploy the apps.
Terraform defines and provides the complete infrastructure using an easy-to-learn declarative language Hashicorp configuration language(HCL).
Terraform's main advantage was supporting multiple cloud providers such as AWS, Azure, Google Cloud, Kubernetes, and Oracle Cloud.
Why do we need to terraform?
Terraform is basically a server orchestration tool. So it will mostly concentrate on the server provisioning with the software container deployment tools like docker and packer.
It is an immutable Infrastructure, so it identifies the issues by utilizing the immutable infrastructure approach to create the separate configuration snapshots, using this method development environment goes smoothly and is completely workable.
It is a Declarative Code style so that terraform prefers describing the desired state of the system and the tool itself reaching the goal state, terraform orders the tool to do the current active state of the system. It has a small code base, easily understandable.
Terraform is a client-only architecture, It leverages the cloud provider API to
Provisioning the infrastructure, which removes the need for an additional security check, running a separate configuration management server, multiple software agents, and ansible does this by connecting through the SSL, yet the capability is limited.
Benefits of Terraform:
Easy, quick to create an infrastructure in multiple clouds.
Flexibility to launch the infrastructure, when theory is needed.
Reduce the time to push the code in production using automation.
Automated the backups of the database
How to install Terraform?
Download the latest version of the file from the terraform website.
It has multiple operating systems such as Windows,macOS, Linux, OpenBSD, FreeBSD, and Solaris.
In our case, we are going to install the terraform in the RHEL Linux machine.
the Terraform website itself provides the installation steps for Linux.
Repository configuration:
Before installing the terraform need to install add the required repo in the machine, here we are using RHEL, so using the Yum package manager, add the repo using the yum-config-manager.
Command: sudo yum install -y yum-utils Command: sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/$release/hashicorp.repo
The above command in the $relase we need to give the Linux distributions.
For Redhat enterprise Linux: RHEL
For Fedora Linux: fedora
For Amazon Linux: AmazonLinux
Here, we are using RHEL so below command we are going to use
Command: sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repoNow we are ready to install terraform using the below command
Command: yum install terraformTerraform commands:
Terraform CLI the basic five commands everyone needs to know
1. init - Initialize the working directory consisting of all the configuration files
2. validate - Check whether the configuration is valid
3. plan - Show changes required by the current configuration
4. apply - It applies then makes the changes in the infrastructure as defined in the plan, and comes to the desired state.
5. destroy - Destroy previously-created infrastructure
Other than four terraform had some other commands also listed below
6. console -Try Terraform expressions at an interactive command prompt
7. fmt -Reformat your configuration in the standard style
8. force-unlock -Release a stuck lock on the current workspace
9. get -Install or upgrade remote Terraform modules
10. graph -Generate a Graphviz graph of the steps in an operation
11. import -Associate existing infrastructure with a Terraform resource
12. login -Obtain and save credentials for a remote host
13. logout -Remove locally-stored credentials for a remote host
14. output -Show output values from your root module
15. providers -Show the providers required for this configuration
16. refresh -Update the state to match remote systems
17. show -Show the current state or a saved plan
18. state -Advanced state management
19. taint -Mark a resource instance is not fully functional
20. untaint -Remove the 'tainted' state from a resource instance
21. version -Show the current Terraform version
22. workspace -Workspace management