Beginner Level
This section covers fundamental concepts of Infrastructure as Code, including basic principles, tools, and essential practices.
Terraform Questions
What is Infrastructure as Code (IaC), and why is it important?
IaC is the practice of managing and provisioning infrastructure — servers, networks, load balancers, databases — through machine-readable definition files instead of manual console clicks or ad-hoc scripts.
Why it's foundational to DevOps:
- Reproducibility — the same code provisions identical environments; no "snowflake" servers
- Reviewability — infrastructure changes go through pull requests like application code
- Drift visibility — manual changes become detectable deviations from the declared state
- Speed + rollback — environments spin up in minutes from code, and roll back to the last reviewed version
The interview one-liner: "IaC makes infrastructure changes reviewable, repeatable, and reversible — the same properties that version control gives application code."
What is Terraform, and how does it work?
Terraform is HashiCorp's open-source, multi-cloud IaC tool. You declare the desired infrastructure in HCL (
.tffiles), and Terraform works out how to create, update, or destroy resources to reach that state.The core workflow:
bashhclThe key concept is declarative: you describe the end state, and Terraform computes the diff between desired and actual (recorded in its state file) — which is what makes
plana safe preview and re-runs idempotent.What is the difference between Terraform and Ansible?
The correction to a common myth: Ansible is declarative too (you declare desired state, e.g.,
state: present) — the real difference is lifecycle: Terraform manages the full lifecycle of cloud resources (create/update/destroy via state), while Ansible configures what's already running. They're complementary: Terraform builds the VM, Ansible configures it — though with containers and cloud-init, the overlap increasingly lands in image builds.What are Terraform providers?
Providers are Terraform's plugins — the adapters that translate HCL resource definitions into API calls for a specific platform:
- Infrastructure — aws, azurerm, google, vsphere
- SaaS/platform — kubernetes, helm, datadog, github, cloudflare
- Local/utility — local, random, tls
hclEach provider is versioned and downloaded by
terraform initinto.terraform/, and version constraints (required_providers) pin them for reproducibility. The breadth of the provider registry (3,000+) is Terraform's superpower — one workflow manages AWS, Azure, GCP, and your SaaS stack together.What is the Terraform state file, and why does it matter?
terraform.tfstateis Terraform's record of the real world — a mapping between your configuration's resources and the actual infrastructure they created:- Diffing —
plancompares desired config vs state vs real cloud; without state, Terraform wouldn't know what to update or destroy - Metadata — resource dependencies, IDs, and attributes (outputs of one resource become inputs to another)
- Sensitive by default — state can contain secrets (database passwords, keys), so it must be protected
Beginner rules that matter immediately: never hand-edit the state file (use
terraform statecommands), never commit it to Git (it belongs in remote storage — see the intermediate level), and one state per environment to keep blast radius small.- Diffing —
What are Terraform variables and outputs?
They're the input/output interface of a configuration — what makes code reusable:
hcl- Variables — parameterize the config; set via
terraform.tfvarsfiles,-varflags, or environment variables (TF_VAR_name). Types, defaults, and validation rules document the contract - Outputs — expose values after apply (IPs, ARNs, IDs) for humans and for other configurations/modules to consume
Together they turn a hardcoded template into a parameterized, reusable building block — the gateway to modules.
- Variables — parameterize the config; set via
Ansible Questions
What is Ansible, and how does it work?
Ansible is an agentless automation tool that connects to machines over SSH (Linux) or WinRM (Windows) and executes tasks to bring them to a desired state:
- No agents — nothing to install on targets; control machine pushes over standard protocols (the ops-simplicity advantage over Puppet/Chef)
- Playbooks — YAML files defining ordered tasks against inventoried hosts
- Modules — the idempotent building blocks (
apt,copy,service): each checks current state and changes only what's needed
The mental model: inventory (which hosts) + playbook (what state) + modules (how to enforce it). It's the configuration-management layer that complements Terraform's provisioning.
What are Ansible playbooks?
A playbook is an ordered list of plays — each play mapping a group of hosts to tasks:
yamlStructure to name: plays define hosts + variables + tasks; tasks call modules;
becomehandles privilege escalation; and task names matter (they're the log output humans read when a run fails). Playbooks are the executable documentation of your server configuration.What is an Ansible inventory file?
The inventory lists the hosts Ansible manages, grouped so plays can target them:
iniPoints to know: groups can nest (
:children), hosts can carry per-host variables, and group variables live ingroup_vars/<group>.yml. Production inventories are usually dynamic — generated from cloud APIs (AWS dynamic inventory, CMDBs) instead of hand-maintained files, so new instances appear automatically.
CloudFormation Questions
What is AWS CloudFormation?
CloudFormation is AWS's native IaC service: you declare resources in YAML/JSON templates, and AWS provisions and manages them as a stack.
yamlWhat the stack model gives you: atomic create/update/delete of the whole resource set, automatic rollback on failure, change sets (preview before execute — Terraform's plan equivalent), and drift detection. Being native, it supports new AWS services on day one — Terraform providers sometimes lag.
The comparison to have ready: CloudFormation is free and AWS-integrated (no state file to manage); Terraform is multi-cloud with a richer ecosystem. Both are legitimate choices; AWS-only shops often standardize on CloudFormation.
How do you create, update, and delete a CloudFormation stack?
bashKey concepts: updates are diffed against the running stack (some properties trigger replacement — resources are recreated — and CloudFormation tells you which in the change set); failed updates roll back automatically to the last stable state; and
RetainResources/ deletion policies (DeletionPolicy: Retain) protect critical resources like databases from accidental stack deletion.
Contribute & Stay Updated
Want to contribute? We welcome contributions! If you have insights, new tools, or improvements, feel free to submit a pull request.
How to Contribute?
- Read the CONTRIBUTING.md guide.
- Fix errors, add missing topics, or suggest improvements.
- Submit a pull request with your updates.
Community & Support
GitHub: @NotHarshhaa Blog: ProDevOpsGuy Telegram Community: Join Here