0% found this document useful (0 votes)
14 views7 pages

Understanding Infrastructure as Code (IaC)

Uploaded by

eclipse6123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Understanding Infrastructure as Code (IaC)

Uploaded by

eclipse6123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Module I: Foundations of Orchestration and IaC

1. What is Infrastructure as Code (IaC)?

 Definition:
Infrastructure as Code (IaC) is the process of managing and provisioning computing
infrastructure (servers, networks, databases, etc.) through machine-readable configuration
files rather than manual setup.

 Goal: Automate and standardize infrastructure deployment to make it faster, consistent, and
repeatable.

 Example:

o Writing a .tf file in Terraform to create an AWS EC2 instance.

o Using Ansible playbooks to configure servers.

2. Benefits of IaC

a. Speed

 Automation allows rapid provisioning of infrastructure.

 Reduces manual steps and human intervention.

 Enables quick setup for testing, staging, and production environments.

b. Repeatability

 Same code can create identical environments every time.

 Prevents configuration drift (differences between environments).

 Makes deployment predictable and reliable.

c. Versioning

 IaC files can be stored in version control systems (e.g., Git).

 Changes can be tracked, rolled back, or reviewed like application code.

 Improves collaboration and auditing.

d. Testing

 Infrastructure configurations can be tested before deployment.

 Tools (like Terraform plan) allow previewing changes.

 Reduces risk of errors and downtime.

3. Declarative vs Imperative Approach


Aspect Declarative Imperative

Define what the desired final state should


Definition Define how to achieve the final state
be

Focus End state Step-by-step instructions

Example Tools Terraform, CloudFormation Ansible (partially), Shell scripts

“Run these commands to create VPC and


Example Code “Create a VPC with 2 subnets”
subnets”

Advantage Simpler and consistent More control and flexibility

4. Mutable vs Immutable Infrastructure

Aspect Mutable Infrastructure Immutable Infrastructure

Existing infrastructure is modified or


Definition Infrastructure is replaced instead of modified
updated

Change Handling Update running servers Deploy new servers and discard old ones

Tools Example Ansible, Puppet Terraform, Docker, Kubernetes

Reduces configuration drift, ensures


Advantages Easier for small changes
consistency

Use Case Long-running VMs Cloud-native & containerized apps

5. Popular IaC Tools Overview

Tool Type Description / Use

Open-source IaC tool by HashiCorp; supports multi-cloud


Terraform Declarative
(AWS, Azure, GCP).

AWS AWS-native IaC tool; provisions AWS resources using


Declarative
CloudFormation YAML/JSON templates.

Imperative/Declarative Configuration management and automation tool using


Ansible
mix YAML playbooks.

IaC using familiar programming languages (Python,


Pulumi Declarative
TypeScript, Go, etc.).

Mutable Infrastructure
1. Definition

 Mutable Infrastructure refers to infrastructure where existing servers or resources are


modified or updated after deployment.

 Changes (like software updates, patches, configuration tweaks) are applied directly to
running systems.

Immutable Infrastructure

1. Definition

 Immutable Infrastructure means that once a server or component is deployed, it is never


modified or updated.

 Any change (update, patch, configuration) is done by creating a new instance and replacing
the old one.

Terraform (based on ) — Notes

1. Introduction / Why Terraform

 Terraform is an open-source Infrastructure as Code (IaC) tool used to provision


infrastructure across cloud platforms.

 Uses HCL (HashiCorp Configuration Language) — declarative, human-readable.

 Solves shortcomings of existing tools: many IaC or config tools are cloud-specific (e.g.
CloudFormation only works with AWS) or more focused on software/configuration (Ansible,
Puppet)

 Enables teams to define infrastructure in code, version it, reuse, and automate deployments.

2. Terraform Architecture (Components)

From the article, the architecture consists of:

Component Role / Description

Configuration Files .tf files which define resources, variables, outputs, modules. Written in HCL.

[Link] stores the current state of resources managed by Terraform


State File
— used to track created/modified/destroyed resources.

Providers / Terraform uses providers (cloud, services, APIs) to manage resources. It


Infrastructure APIs interacts with cloud APIs (AWS, Azure, etc.).

Reusable bundles of configuration (set of resources) that you can reference in


Modules
other configurations.

Let you run scripts / commands on resources after creation (for


Provisioners
bootstrapping). (Though use with caution)
Component Role / Description

CLI / Terraform The Terraform command-line tool, which you run to execute commands and
executable control infrastructure.

Private Module Organizations can host private module registries (internally) for sharing
Registry modules securely.

3. Working / Terraform Workflow

The article describes how Terraform works: users define infrastructure declaratively, then Terraform
creates/modifies/destroys resources as needed. +1

The typical workflow (implied from commands and usage) is:

1. Write configuration: define resources in .tf files (e.g. resource "aws_instance" "web" { … })
+1

2. Initialize: terraform init to set up the working directory and download provider plugins

3. Validate: terraform validate checks syntax and configuration correctness

4. Plan / Preview: Though the article doesn’t deeply define “plan,” it is implicit in change
handling — preview what changes will be made

5. Apply: terraform apply to make the changes (create, update, destroy) in real infrastructure

6. Destroy: terraform destroy to tear down the resources defined in the configuration

7. Other commands:

o terraform import to import existing resources into Terraform’s state

o terraform console to evaluate expressions inside configuration

o terraform refresh to sync Terraform state with actual infrastructure

4. Terraform Commands (from the article)

Here’s a summary (as per ) of key Terraform commands and their use:

Command Purpose / What it does

terraform init Initializes the working directory, downloads & configures provider plugins.

terraform validate Validates the syntax and internal consistency of .tf files.

Applies changes to real infrastructure — create/update/destroy resources per


terraform apply
config.

terraform destroy Destroys all resources defined by the config in the current working directory.

terraform import Imports an existing resource into the Terraform state so Terraform can manage it.
Command Purpose / What it does

terraform console Opens an interactive shell to evaluate expressions and test interpolation / logic.

terraform refresh Updates the Terraform state to match the actual real-world resources (sync).

There are also secondary commands like formatting, state management, etc. implied via the CLI /
help.

5. Core Elements of Terraform (per article)

The article defines the following as core building blocks:

 Terraform CLI / Executable: The single binary you run that contains all Terraform commands.

 Terraform Language (HCL): Used to define infrastructure elements — resources, variables,


etc.

 Providers: Plugins that allow Terraform to interact with specific services / platforms (cloud,
APIs).

 Modules: Units of reusable infrastructure — group related resources and allow reuse and
abstraction.

 Provisioners: To execute commands on resources after creation (e.g. configuration scripts) —


but used sparingly.

 Terraform State: The state file tracks what infrastructure Terraform knows about, for future
operations.

6. Advantages & Disadvantages (from the article)

Advantages:

 Declarative configuration: You define what the infrastructure should be, not how.

 Multi-cloud support: Terraform works across AWS, Azure, GCP, on-premises, etc.

 Reusable infrastructure code: Using modules, variables, etc., you can reuse parts of
configurations.

 Collaboration / version control: Configurations can be kept in Git, enabling teams to track
and revert changes.

 Efficient resource management: Dependencies, ordering, etc. are handled to reduce


duplication and errors.

Disadvantages / Challenges:

 Complexity: Steep learning curve, many features and constructs.

 State management issues: If state file is lost, corrupted, or out-of-sync (changes made
outside Terraform), problems arise.
 Performance overhead: For large deployments, it may be slower due to state and multiple
API calls.

 Limited rollback: Terraform lacks a built-in “undo” — cannot fully roll back changes
automatically.

7. Comparisons: Terraform vs Others (from article)

You might also like