Terraform is an open-source IaC (Infrastructure-as-Code) tool for configuring and deploying cloud infrastructure. It codifies infrastructure in configuration files that describe the desired state for your topology. Terraform allows you to use a consistent workflow over your infrastructure lifecycle, regardless of the resource provider. The infrastructure as code workflow lets your declaratively manage a variety of services and automate your changes to them, reducing the risk of human error through manual operations.
Advantages:
IAC is crucial because it helps to speed deployment and release of software
Terraforms support provide multi-cloud platforms like AWS, AZURE and Google etc..
IAC assist to restrict user to delete resources accidentally
Provide template to write code and use it many times
Unified template also provide security
Workflows
In HCP Terraform, your resources are organized by workspaces, which contain your resource definitions, environment and input variables, and state files. A Terraform operation occurs within a workspace, and Terraform uses the configuration and state for that workspace to modify your infrastructure.
HCP Terraform supports three workflows for your Terraform runs:
The CLI-driven workflow, which uses Terraforms standard CLI tools to execute runs in HCP Terraform.
The UI/Version Control System(VCS)-driven workflow, in which changes pushed to version control repositories trigger runs in the associated workspace.
The API-driven workflow, which allows you to create tooling to interact with the HCP Terraform API programmatically
Init: Validate working directory consisting of terraform config file. This is the first command to be executed after writing new file
Validate: Check for syntax and validate config file
Plan: Create execution plan
Apply: Apply changes and execute command to create resources
Destroy: Remove terraform managed resources. It will ask for confirmation before removing resources
In the below example we will deplyoing resource group using terraform modules with real world scenario
Terraform Module Definition
A Terraform module is a container for multiple resources that are used together.
A module can be as simple as a single resource or as complex as a complete infrastructure stack.
Modules provide a modular structure with a clear separation of concerns, making infrastructure easier to manage, reuse, and maintain.
Example: Deploying a Resource Group with Terraform Modules
In this example, we use Terraform modules to deploy a Resource Group.
The project repository for the Resource Group creation is available here:
https://github.com/uttamchaturvedi9/terraformforcommunity
├── main.tf # Main Terraform configuration
├── variables.tf # Variable definitions
├── terraform.tfvars # variable values
├── modules/ # Terraform modules
│ └── resource-group/ # Resource Group module
│ ├── main.tf # Module main configuration
│ ├── variables.tf # Module variables
│ └── outputs.tf # Module outputs
└── README.md # This file
This repository demonstrates how to:
Define a Terraform module for Resource Group creation.
Use input variables for flexibility.
Apply modular structure for better reusability.
Summary
Terraform, as an Infrastructure as Code (IAC) tool, allows infrastructure provisioning and management through declarative configuration files. By defining resources in reusable modules, teams achieve:
Consistency: Repeatable deployments across environments.
Modularity : Clear separation of concerns, making code reusable and maintainable.
Scalability: Ability to orchestrate simple to complex infrastructure stacks.
Collaboration: Version-controlled infrastructure code shared across teams.
Conclusion
Using Terraform as IAC empowers organizations to manage infrastructure in the same way they manage application code. This approach reduces manual effort, minimizes errors, and accelerates delivery. With its modular design, state management, and provider ecosystem, Terraform provides a scalable, reliable, and automated way to orchestrate infrastructure, making it a cornerstone of modern DevOps practices.
Top comments (0)