Infrastructure as Code
-
Definition:
- Infrastructure as Code (IaC) allows to manage and provision infrastructure through human-readable
configuration files rather than manual processes (UI or CLI).
- Treats infrastructure like application code: versioned, tested, repeatable.
-
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.
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.
Back to Top