Cloud Computing has changes the dynamics of software development processes. Also, many new tools and process has been developed for controlled management and improvement of software development life cycle. Infrastructure as Code is one of the processes, that has become integral to development operations. Multiple tools comes up to provide functional features for building infrastructure using code.
Terraform is an open source infrastructure as code software tool to build, change and version infrastructure efficiently and effectively. This is created by HashiCorp and is maintained along with several other cloud service providers. Terraform is capable of creating new and managing the existing infrastructure. Terraform provides functional features & support for major & popular cloud services in coordination with cloud service providers like Amazon Web Services, Microsoft Azure, Google Cloud Platform, Oracle Cloud Platform, Digital Ocean etc.
Terraform is fairly a new tool as compared to other provisioning & configuration management tools like Ansible, Chef, Puppet etc. It popularity is fast growing as preferred tool for infrastructure provisioning and orchestration. Terraform provides many benefits as IaC tool:
- Platform Agnostic
- Infra State Management
- Operator Confidence
Cloud Computing market is vast and broadly distributed. There are several cloud service providers each having significant market share. Also, cloud providers are broadly distributed and can be categorized based on their service offerings. A good IaC tool has to be competitive and should provide support for multiple service providers.
Terraform is a tool which is platform agnostic. It means it can be used on any platform. Underlying (backend) platform does not constraint its usage. This is because, Terraform provides support for several cloud providers. The list is very vast and broadly distributed.
This gives an added advantage to Terraform, compared to the tools provides by cloud service providers itself, which are specific to their platform only like CloudFormation for AWS, Azure Resource Manager. Some popular providers supported by Terraform:
- Major cloud – AWS, Azure, Azure Stack, Google Cloud Platform, Oracle Cloud Platform etc.
- Cloud – Digital Ocean, Cloud Stack, Open Stack, Heroku etc.
- Infrastructure Software – Chef, Docker, Kubernetes, RabbitMQ, Terraform, Terraform Cloud
- Network (DNS, Routing, Firewall) – Cisco ASA, Akamai, DNS, DNSimple, HTTP, PowerDNS
- Version Control Systems – Bitbucket, GitHub, GitLab
- Monitoring & System Management – Grafana, Datadog, LogicMonitor
- Database – MySQL, PostgreSQL, MongoDB Atlas, InfluxDB
- Other capabilities – Archive, Local, Random, Template
Infra State Management
State file is configuration properties of the current running infrastructure. Terraform creates a state file on its initialization. State file is used in creation of plan and verification of changes to infrastructure. Before any operation, Terraform does refresh to update the state file to real infrastructure. This way, what changes to be performed to the infrastructure can be shown and can be verified before its actual implementation. Terraform state files are also used in collaboration among different environments like development, testing, integration & release environments.
This way of comparing the real infrastructure & to show changes helps operator to rectify their mistakes before its actually done. This gives confidence to the operator in performing their tasks.
Terraform also provides some benefits as compared to other IaC tools like Chef, Puppet, Salt & Ansible:
- Orchestration tool, Not just configuration management
Terraform is more of an orchestration tool, not just provisioning & configuration tool. Orchestration means, it provides coordination between multiple resources. Other tools main focus is to install software on pre configured machines in desired states, Terraform can perform server provisioning itself with other tasks left to docker or packer.
- Declarative approach, not procedural
Terraform syntax files are written with declarative approach, instead of procedural approach. It means, declaration of resources matters rather than their sequence. Dependency of resources is managed by Terraform itself. With this approach, less templates are required to manage the complete infrastructure. Declarative approach is more independent & have less chances of failure as compared to procedural approach. Multiple independent tasks can be performed simultaneously.
- Immutable Infrastructure
Terraform uses immutable infrastructure approach, which means it creates complete infra every time it is applied. It does refresh to take initial state of infra into consideration. This ensures infrastructure will be same every time it is applied regardless of its initial state.
But with other tools following mutable approach, means they perform the update operation on the existing state. Problem with mutable approach is, it has a possibility to environmental drift problem, which over a period of time creates environment snowflakes & inconsistency.
With Terraform immutable approach, environment drift problems can be avoided, gives confidence to operator.
- Masterless and Agentless
Terraform uses client only architecture, leveraging cloud providers APIs for infrastructure provisioning. This avoids the requirement for security checks (which are performed with providers APIs), running separate tool or script as master node or running multiple agents. Terraform can run on any client machine with its connection to provider APIs will do the job. This enhances the capability of tasks that can be performed with Terraform. Ansible does use client only with SSH connection but have limited capability.
This helps in faster execution of task with less dependent resources..
- Large Community Support
Terraform provide support in coordination with many cloud service providers. This increase their provider support along with the community support with those providers. This combined provides it large community support.