{"kind":"post","path":"/blog/terraform-ansible-final-ccgc","post":{"metadata":{"title":"Terraform \u0026 Ansible Scalable IaC Project","summary":"A college infrastructure project that uses Terraform to provision Azure resources and Ansible to configure the Linux VM fleet.","publishedAt":"2023-09-01","projectDate":"2023-08-21","ascent":"#EE0000","github":"surajmandalcell/automation-final-terraform-ansible","tags":["automation","college","ccgc","terraform","ansible","devops","infrastructure"],"weight":1},"slug":"terraform-ansible-final-ccgc","content":"This was the final project for the **2023 Humber College CCGC Automation course**. My classmates and I split cloud provisioning from server setup.\n\n## Architecture\n\n\u003cimg src=\"/images/blog/terraform-ansible-final-ccgc/cover.png\" alt=\"Terraform and Ansible infrastructure project cover\" /\u003e\n\n```mermaid\nflowchart TB\n accTitle: Terraform And Ansible Architecture\n accDescr: Terraform provisions the Azure network, Linux fleet, and shared services. Ansible configures the Linux hosts.\n terraform[\"\u003cstrong\u003eTerraform Modules\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eProvision Azure\u003c/small\u003e\"] --\u003e network[\"\u003cstrong\u003eNetwork Boundary\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eVirtual Network And Security\u003c/small\u003e\"]\n terraform --\u003e compute[\"\u003cstrong\u003eLinux Compute\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eVirtual Machine Fleet\u003c/small\u003e\"]\n terraform --\u003e services[\"\u003cstrong\u003eShared Services\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eData Protection And Monitoring\u003c/small\u003e\"]\n network --\u003e balance[\"\u003cstrong\u003eLoad Balancer\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eRoute Public Traffic\u003c/small\u003e\"]\n compute --\u003e hosts[\"\u003cstrong\u003eLinux Hosts\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eThree Configured Servers\u003c/small\u003e\"]\n balance --\u003e hosts\n ansible[\"\u003cstrong\u003eAnsible Roles\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eConfigure The Hosts\u003c/small\u003e\"] --\u003e hosts\n services --\u003e database[\"\u003cstrong\u003ePostgreSQL\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eManaged Database\u003c/small\u003e\"]\n services --\u003e storage[\"\u003cstrong\u003eStorage\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eShared Data\u003c/small\u003e\"]\n services --\u003e monitoring[\"\u003cstrong\u003eMonitoring\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eLogs And Health\u003c/small\u003e\"]\n services --\u003e recovery[\"\u003cstrong\u003eRecovery\u003c/strong\u003e\u003cbr/\u003e\u003csmall\u003eBackup Services\u003c/small\u003e\"]\n```\n\n**Terraform** owns the Azure resources. **Ansible** turns the Linux hosts into usable servers. This split made each failure easier to find.\n\n### Terraform Modules\n\n| Module | Purpose |\n|---|---|\n| `rgroup-RandomID` | Creates the resource group. |\n| `network-RandomID` | Creates the virtual network, subnet, and security group. |\n| `common-RandomID` | Creates monitoring, recovery, and storage services. |\n| `vmlinux-RandomID` | Creates Linux VMs across availability zones. |\n| `datadisk-RandomID` | Attaches 10 GB data disks to the VM fleet. |\n| `loadbalancer-RandomID` | Places the Linux VM fleet behind a public load balancer. |\n| `database-RandomID` | Creates Azure Database for PostgreSQL. |\n\nThe root module joins these modules and prints their outputs.\n\n### Ansible Roles\n\n| Role | Purpose |\n|---|---|\n| `datadisk-n01537188` | Partitions, formats, and mounts data disks. |\n| `profile-n01537188` | Updates system profile values and session timeouts. |\n| `user-n01537188` | Manages users, groups, SSH keys, and sudo access. |\n| `webserver-n01537188` | Installs Apache, deploys a page, and starts the service. |\n\n## Demo\n\n\u003ciframe\n width=\"100%\"\n height=\"100%\"\n src=\"https://www.youtube.com/embed/XJdShDMQDvc?si=D6YKQS5IRQZu1NHP\u0026amp;controls=0\u0026rel=0\"\n title=\"YouTube video player\"\n frameBorder=\"0\"\n allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\"\n referrerPolicy=\"strict-origin-when-cross-origin\"\n allowFullScreen\n\u003e\u003c/iframe\u003e\n\n\u003cdetails className=\"mt-6\"\u003e\n\u003csummary\u003eAdditional Videos\u003c/summary\u003e\n\n\u003ciframe\n width=\"100%\"\n height=\"100%\"\n src=\"https://www.youtube.com/embed/unSLXQDzgls?si=OUoId-js8EC3hlEN\u0026amp;controls=0\u0026rel=0\"\n title=\"YouTube video player\"\n frameBorder=\"0\"\n allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\"\n referrerPolicy=\"strict-origin-when-cross-origin\"\n allowFullScreen\n\u003e\u003c/iframe\u003e\n\n\u003ciframe\n width=\"100%\"\n height=\"100%\"\n className=\"bp-video-embed--spaced\"\n src=\"https://www.youtube.com/embed/8oUIRmX1yWo?si=A3MfPxoIVHqPUH71\u0026amp;controls=0\u0026rel=0\"\n title=\"YouTube video player\"\n frameBorder=\"0\"\n allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\"\n referrerPolicy=\"strict-origin-when-cross-origin\"\n allowFullScreen\n\u003e\u003c/iframe\u003e\n\n\u003c/details\u003e\n\n## Run The Project\n\n### Ansible\n\nInstall Ansible, then run the playbook from its project folder.\n\n```bash\nsudo apt update\nsudo apt install ansible\nansible-playbook --verbose n01537188-playbook.yaml\n```\n\n### Terraform\n\nRun these commands from the Terraform root module.\n\n```bash\nterraform init\nterraform validate\nterraform plan\nterraform apply\n```\n\nUse the detailed exit code in automation. Remove the lab resources when the work is complete.\n\n```bash\nterraform plan -detailed-exitcode\nterraform destroy\n```"}}