Terraform. Is it more flexible than CloudFormation
It is amazing to think that all the infrastructure you need can be created by just writing a single line of code in a time when there is so much focus on Operations automation and Infrastructure. Terraform and CloudFormation are key players in the Infrastructure as a code space. Which tool is best for you? This post will help you to either answer this question or to get enough information to continue your research.
Terraform is a HashiCorp tool that allows you to build, change and version infrastructure. Terraform creates an execution plan that outlines the actions required to achieve the goal before Terraform starts execution. Command-line Interface controls the entire infrastructure. Terraform can create and execute incremental plans to upgrade the infrastructure to a new state. The entire infrastructure is described in.tfstate as JSON, which can be used to document it. Terraform manages the infrastructure such as compute instances, storage, networking, DNS, and many other things.
Why Terraform will be a major player in the IaC tool industry?
CloudFormation will only have an impact on AWS. Multi-cloud workers need to define and define each cloud provider. However, Terraform allows us to create it once and reuse it across multiple cloud providers. Terraform can be described as a one-stop solution for IaC.
Terraform, on the other hand, provides software provisioning and management tools, such as Chef and Puppet.
Other tools can cause infrastructure to be altered, resulting in services being stopped. Imagine that you make a change to a version of software on a node. Then it starts producing a new changelog over time. Terraform does not have this issue.
Terraform’s rollback mechanism works in the following way: If a resource is created but fails provisioning, Terraform marks it as “tainted” and Terraform will execute the next execution plan to remove the tainted resources. This is unlike CloudFormation which rolls back completely.
CloudFormation requires us to define each instance when we want to launch additional instances. Terraform, however, does not require us to do this. All we need to do is mention the number of instances needed.
This launches 10 ec2 cases.
However, if we change it to 3 instances (we specify only what our requirement is, need not calculate), it kills 7 instances.
The instances are destroyed, it kills 7 instances and leaves 3 behind, unlike other tools
What is Terraform so special?
You can either write the code in a txt or JSON format. JSON format is preferred if the code is to be run programmatically.
Before you actually execute, you can visualize the plan. This can be useful in avoiding unintended steps (catching up bugs). We can see our plan as the following image if we run “Terraform Plan”.
dot -Tpng > graph.png”. This is how the graph will look.
Let’s say you have a few changes in mind and you write the changelog.tf accordingly. Then all you have to do is run the command “Terraform Apply” to see the changes take place. How Terraform maps changes to which resource? Terraform state is responsible for all of this. We can give it the command “Terraform Apply”. It also creates a file called “terafform.tfstate”. This file contains a JSON format custom to record a