Infrastructure as Code
-
Definition:
- Infrastructure as Code (IaC) allows to manage and provision infrastructure (networks,
servers, databases, etc.) through human-readable configuration files rather than manual processes
(UI or CLI) and treats infrastructure like application code: versioned, tested, repeatable, and automatable.
-
Approaches:
- Declarative (what you want) → You define what the infrastructure should look like.
IaC tools, like Terraform, figure out how build it.
- Imperative (how to do it) → You manually specify how to build infra step by step using scripts or CLI.
-
Core principle: Desired state is defined in code → IaC tools reconcile real infrastructure with this
desired state.
- Desired state → what you define in code.
- Current state → what exists in the environment.
What is Terraform?
HashiCorp Terraform is an infrastructure as code tool that lets you define both cloud and on-prem
resources in human-readable configuration files that you can version, reuse, and share.
Terraform creates and manages resources through plug-ins, called providers.
Providers enable Terraform to work with virtually any platform or service manageable though API.
HashiCorp and the Terraform community have already written thousands of providers to manage many different types of
resources and services. You can find all publicly available providers on the Terraform Registry, including
Amazon Web Services (AWS), Azure, Google Cloud Platform (GCP), Kubernetes, Helm, GitHub, Splunk, DataDog,
and many more.
Terraform configuration files are declarative, meaning that they describe the end state of your infrastructure.
Terraform handles all interactions and underlying logic necessary to create the resources.
It builds a resource graph to determine resource dependencies and creates or modifies non-dependent resources
in parallel.
Terraform supports reusable configuration components called modules that define configurable collections of
infrastructure. You can use publicly available modules from the Terraform Registry, or write your own.
Since your configuration is written in a file, you can commit it to a Version Control System (VCS) and use
HCP Terraform to efficiently manage Terraform workflows across teams. HCP Terraform runs Terraform in a
consistent, reliable environment and provides secure access to shared state and secret data, role-based access
controls, a private registry for sharing both modules and providers, and more.
Back to Top
Terraform is an infrastructure as code (IaC) tool that lets you define and manage infrastructure resources
through declarative, human-readable configuration files. You can manage infrastructure that spans multiple clouds,
on-prem, and SaaS - all from unified configurations.
- Provider-agnostic:
- Plugin-Based Architecture works with many platform and infrastructure providers.
- Utilizes same configuration language and unified workflow for management of different infra
resources and cloud platforms.
- Multi-cloud:
- Allows to manage different clouds in one config without cloud vendor lock-in.
- Consolidates management and orchestration for large-scale, multi-cloud infrastructures.
- Supports hybrid infra (cloud + on-prem + SaaS).
Comparing Terraform to Other IaC Tools
- Terraform vs Cloud-native Tools (e.g., AWS CloudFormation, Azure ARM, GCP Deployment Manager):
- Cloud-native tools → vendor-specific & single-cloud only.
- Terraform → Multi-cloud and provider-agnostic.
- Terraform supports composable modules and standard syntax across clouds.
- Terraform vs Configuration Management Tools (Ansible, Chef, Puppet, Salt):
- Terraform → Focuses on infra provisioning (VMs, networks, load balancers, storage, SaaS).
- Config management → Focuses on OS/software configuration inside servers.
- They can complement each other: Terraform builds infra, config management tool configures it.
Advantages of Terraform
- Multi-cloud support with a single workflow.
- Standardized language → human-readable and consistent.
- Infrastructure version control with version control systems (VCS).
- Reusability via modules.
- Extensibility with custom providers.
- Idempotency - same config applied multiple times leads to same result.
Back to Top
What is the main goal of Infrastructure as Code (IaC)?
Answer: The fundamental goal of Infrastructure as Code (IaC) is to enable the programmatic configuration and
management of infrastructure resources, which allows for automation, version control, and repeatability in
deployments.
What resources can be managed by Terraform?
Answer: Terraform can manage both cloud and on-prem resources, including AWS, Azure, GCP, OCI, Kubernetes, Docker,
DNS entries, SaaS configurations, and more.
How can you use infrastructure as Code (IaC) to resolve issues caused by inconsistent VM configuration across multiple
environments?
Answer: Implement a infrastructure provisioning pipeline that follows code review and testing practice and
automatically deploys VMs based on configurations stored in version control system.
Using Infrastructure as Code (IaC) ensures that infrastructure definitions are managed like software code -
versioned, reviewed, and deployed automatically. Storing configurations in a version control system provides a
single source of truth, enables rollbacks, and enforces consistency across environments. Automated provisioning
pipelines eliminate manual setup errors and ensure every compute instance is configured identically.
What is the main advantage of using Infrastructure as Code (IaC)?
Answer: IaC allows infrastructure to be managed and provisioned through code, ensuring consistent, repeatable,
and automated deployments.
This approach reduces manual configuration errors, improves collaboration, and enables version control and
rollback just like application code.
How does Infrastructure as Code (IaC) improve consistency in infrastructure deployments?
Answer: IaC ensures that all environments are created from the same configuration files, eliminating manual
setup differences.
This makes infrastructure predictable and reduces configuration drift across development, testing, and
production environments.
What is declarative Infrastructure as Code (IaC)?
Answer: Declarative IaC means defining the desired end state of your infrastructure, and letting the tool
figure out how to reach that state.
Terraform uses this approach, it automatically determines what actions to take to match the configuration with
the real environment.
How does version control support Infrastructure as Code (IaC) practices?
Answer: Version control allows teams to track and review infrastructure changes, roll back if needed, and maintain
an auditable history.
Storing Terraform configurations in a system like Git enables collaboration, testing, and approval workflows
for infrastructure updates.
You discovered that staging and production environments differ even though both should be identical. How can
Infrastructure as Code (IaC) help prevent this issue?
Answer: By applying the same version-controlled Terraform configuration to both environments, ensuring consistent
and repeatable deployments.
IaC enforces uniformity by managing configurations as code, so changes are reviewed, tested, and applied
consistently across environments.
What is the main purpose of Terraform?
Answer: Terraform is an Infrastructure as Code (IaC) tool that automates the provisioning, management, and
versioning of infrastructure across multiple cloud and on-premises providers.
It allows users to define infrastructure in configuration files and maintain it in a predictable, repeatable way.
How does Terraform differ from configuration management tools like Ansible or Chef?
Answer: Terraform focuses on provisioning and managing infrastructure - creating, updating, and destroying resources,
while tools like Ansible or Chef configure software and settings inside already-provisioned systems.
Terraform defines what infrastructure should exist, while configuration management tools define
how systems should be configured.
What makes Terraform "cloud-agnostic" compared to other IaC tools?
Answer: Terraform supports many providers through its plugin system, enabling management of resources across
AWS, Azure, Google Cloud, VMware, and many others with the same language and workflow.
This allows a single configuration to span multiple platforms, unlike some tools tied to a specific vendor.
How does Terraform's execution model differ from procedural tools like Ansible?
Answer: Terraform uses a declarative model,it compares your desired configuration to the current state and
determines the actions needed to reach that state.
Procedural tools like Ansible execute step-by-step instructions and do not maintain long-term awareness of the
infrastructure's state.
Why might a team choose Terraform over a cloud-specific tool like AWS CloudFormation?
Answer: Terraform supports multiple providers and can manage hybrid or multi-cloud environments, while
AWS CloudFormation works only within AWS.
Terraform's provider ecosystem, reusable modules, and consistent language make it ideal for organizations
managing diverse infrastructures.
Can Terraform manage both cloud resources and external services like GitHub or Datadog?
Answer: Yes. Terraform's provider framework extends beyond traditional infrastructure, allowing it to manage
SaaS and API-based services such as GitHub repositories, Datadog monitors, or Cloudflare DNS records, all using
the same configuration syntax.
Back to Top