Transform all manual infrastructure setup from Projects 1–6 into code. Use Terraform to define and provision infrastructure declaratively, and Ansible to automate server configuration. Your entire ABC Retail environment will be reproducible with a single command.
Infrastructure as Code (IaC) treats server configuration and cloud resource provisioning the same way software developers treat application code — it is version controlled, peer reviewed, tested, and automated. The key benefit: any environment (dev, staging, production) can be created identically and reproducibly. Manual configurations that exist only in someone's memory are eliminated.
terraform version command shows the installed version. Terraform uses HCL (HashiCorp Configuration Language) — a human-friendly format for defining infrastructure. All Terraform files end with .tf extension..gitignore file prevents sensitive files from being committed. The terraform.tfstate file contains the current state of all managed infrastructure including resource IDs, IP addresses, and sometimes credentials — committing it to a repository would be a serious security incident. The *.tfvars files contain variable values (often including passwords) — these should also never be committed, even to private repositories.Since this course is done locally (no cloud account required), we use the Terraform Docker Provider to manage our Docker containers as Infrastructure as Code. The same Terraform concepts and workflow apply identically when using the AWS, Azure, or GCP providers — only the resource types change.
count.index trick automatically names and ports web containers sequentially. In production, this same structure would use aws_instance, aws_vpc, aws_security_group resources instead of Docker resources.terraform init command reads the provider requirements from main.tf and downloads the required provider plugins. You should see "Terraform has been successfully initialized!" A .terraform directory is created containing the downloaded provider binaries. This is analogous to npm install for JavaScript projects or pip install for Python — it sets up the local workspace with required dependencies.terraform plan command shows exactly what Terraform will do when applied — a "diff" of infrastructure changes. Green lines with + are resources that will be CREATED. Yellow lines with ~ are resources that will be MODIFIED. Red lines with - are resources that will be DESTROYED. This preview step is critical in production — always review the plan before applying to avoid unintended changes. The output shows exactly how many resources will be added, changed, and destroyed.terraform apply command executes the plan and creates all defined resources. After confirmation, watch as Terraform creates the network, volumes, images, and containers in the correct order (respecting dependencies — the network must exist before containers can join it). When complete, the output values are displayed. Run docker ps to verify the containers were created by Terraform — you should see the abc-retail-web-1, abc-retail-web-2, and database containers.terraform state list command shows all resources managed by Terraform. The terraform show command displays the full details of every resource in the state file. The state file is Terraform's database — it records the real-world IDs of every resource it manages so that on the next apply, it can calculate what changed. If the state file is lost, Terraform loses track of what it manages and may try to create duplicate resources.prod.tfvars with production-scale values (many replicas, larger instance types, multi-region) and dev.tfvars with minimal resources. To deploy to a specific environment: terraform apply -var-file="prod.tfvars".terraform destroy command removes ALL resources managed by this Terraform configuration — the reverse of apply. It shows a plan of what will be destroyed and asks for confirmation. This is the "tear down" operation — extremely useful for development environments that should be cleaned up at end of day. In production, terraform destroy would be protected by IAM policies, approval workflows, and backup requirements.While Terraform provisions infrastructure (creates servers, networks), Ansible configures the software on those servers (installs Nginx, configures firewall rules, creates users). Together they form a complete IaC solution. Ansible uses SSH to connect to servers and applies configuration steps described in YAML files called "playbooks."
[webservers] and [databases] groups allow you to target different sets of servers with different playbooks. ansible_host is the IP address, ansible_user is the SSH username, and ansible_ssh_private_key_file specifies the SSH key from Project 6. The [abc_retail:children] section creates a parent group containing both webservers and databases. In dynamic cloud environments, Ansible can automatically generate inventories from cloud APIs instead of static files.ansible all -m ping command runs the ping module on all servers in the inventory. This is not an ICMP ping — it's an Ansible connectivity test that: connects via SSH, verifies Python is available, and returns "pong" if everything works. If you see "pong" for all servers, Ansible can manage them. If you see connection errors, check the IP addresses in inventory and that the SSH key is correct.--check flag runs in "check mode" — Ansible simulates all tasks and reports what would change, without actually making any changes. This is the Ansible equivalent of terraform plan. After reviewing the dry-run output, run without --check to apply. Watch the play output: each task shows OK (no change needed), CHANGED (task made a change), or FAILED (task encountered an error). Green OK means the system is already in the desired state — Ansible is idempotent.type: short summary followed by a detailed body. The feat: type indicates a new feature. Other types include: fix: (bug fix), docs: (documentation), refactor: (code reorganization), chore: (maintenance). Good commit messages are a professional expectation in team environments.git log --oneline)terraform plan outputterraform apply success outputansible-playbook output (all tasks OK/CHANGED)terraform version)terraform init completes without errorterraform plan shows resources to createterraform apply creates all containersansible --version)ansible all -m ping returns pongterraform apply corrects it.terraform apply and ansible-playbook. This is the operational realization of the Disaster Recovery Plan from Project 5.git log query, not a mystery.