Skip to content

Beginner Level

This section covers fundamental concepts of Infrastructure as Code, including basic principles, tools, and essential practices.

Terraform Questions

0 / 6 reviewed (0%)
  1. 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."

  2. 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 (.tf files), and Terraform works out how to create, update, or destroy resources to reach that state.

    The core workflow:

    bash
    terraform init      # download providers, configure backend/state
    terraform plan      # preview: what will be created/changed/destroyed
    terraform apply     # execute the plan
    hcl
    provider "aws" {
      region = "us-east-1"
    }
    
    resource "aws_instance" "web" {
      ami           = "ami-0abcdef1234567890"
      instance_type = "t3.micro"
    }

    The 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 plan a safe preview and re-runs idempotent.

  3. What is the difference between Terraform and Ansible?

    AspectTerraformAnsible
    Primary jobProvisioning infrastructureConfiguring what runs on it
    StateStateful — tracks resources it managesMostly stateless — re-runs against hosts
    ModelDeclarative end-state with a dependency graphDeclarative YAML tasks, executed procedurally
    Typical useCreate VMs, VPCs, load balancers, databasesInstall packages, configure OS, deploy apps
    IdempotencyGuaranteed by state diffingDepends on modules (most are idempotent)

    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.

  4. 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
    hcl
    provider "aws" {
      region = "us-west-2"
    }

    Each provider is versioned and downloaded by terraform init into .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.

  5. What is the Terraform state file, and why does it matter?

    terraform.tfstate is Terraform's record of the real world — a mapping between your configuration's resources and the actual infrastructure they created:

    • Diffing — plan compares 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 state commands), never commit it to Git (it belongs in remote storage — see the intermediate level), and one state per environment to keep blast radius small.

  6. What are Terraform variables and outputs?

    They're the input/output interface of a configuration — what makes code reusable:

    hcl
    variable "instance_type" {
      description = "EC2 instance size"
      type        = string
      default     = "t3.micro"
    }
    
    resource "aws_instance" "web" {
      instance_type = var.instance_type
    }
    
    output "public_ip" {
      value = aws_instance.web.public_ip
    }
    • Variables — parameterize the config; set via terraform.tfvars files, -var flags, 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.

Ansible Questions

0 / 3 reviewed (0%)
  1. 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.

  2. What are Ansible playbooks?

    A playbook is an ordered list of plays — each play mapping a group of hosts to tasks:

    yaml
    - name: Install and start nginx
      hosts: web
      become: yes                    # escalate to sudo
      tasks:
        - name: Install nginx
          apt:
            name: nginx
            state: present           # idempotent: installs only if missing
        - name: Start nginx
          service:
            name: nginx
            state: started
            enabled: yes

    Structure to name: plays define hosts + variables + tasks; tasks call modules; become handles 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.

  3. What is an Ansible inventory file?

    The inventory lists the hosts Ansible manages, grouped so plays can target them:

    ini
    [web]
    server1 ansible_host=192.168.1.10
    server2 ansible_host=192.168.1.11
    
    [db]
    db1 ansible_host=192.168.1.20
    
    [production:children]
    web
    db

    Points to know: groups can nest (:children), hosts can carry per-host variables, and group variables live in group_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

  1. 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.

    yaml
    Resources:
      MyBucket:
        Type: AWS::S3::Bucket
        Properties:
          BucketName: my-app-logs

    What 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.

  2. How do you create, update, and delete a CloudFormation stack?

    bash
    # Create
    aws cloudformation create-stack \
      --stack-name my-stack \
      --template-body file://template.yml \
      --parameters ParameterKey=Env,ParameterValue=prod
    
    # Preview the change (change set — the plan equivalent)
    aws cloudformation create-change-set --stack-name my-stack ...
    
    # Update
    aws cloudformation update-stack --stack-name my-stack --template-body file://template.yml
    
    # Delete (removes all stack resources)
    aws cloudformation delete-stack --stack-name my-stack

    Key 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