How abednahouli/terraform_seed works
Main Components
• Terraform Configuration: Files like main.tf, provider.tf, variables.tf, outputs.tf, and terraform.tfvars.example.md form the core of the infrastructure provisioning. They define resources such as the DigitalOcean droplet and firewall.
• Python Management Script: The manage_terraform.py script acts as a wrapper to initialize, apply, and destroy Terraform configurations. It is also responsible for updating the Ansible inventory file.
• Ansible Configuration: The setup.yml playbook and ansible_vars_example.yml (to be copied as ansible_vars.yml) represent the configuration management side for setting up the web server.
• Ansible Inventory: The dynamic inventory.ini file (updated automatically) lists the target hosts (the new droplet) for Ansible to work with.
• External Services & Dependencies: DigitalOcean as the cloud provider, along with dependencies like Terraform, Ansible, and Python, which are prerequisites for running the project.
Relationships and Interactions
• The Terraform component interacts with the DigitalOcean API to provision infrastructure (droplets and firewall rules).
• Once infrastructure is provisioned, the manage_terraform.py script updates the Ansible inventory (inventory.ini) with the IP address of the new droplet.
• The Ansible playbook (setup.yml) then connects to the droplet using SSH (leveraging the updated inventory) to configure the server (installing/configuring Nginx and MySQL).
• The system thus flows from infrastructure provisioning (Terraform) → inventory update (Python script) → configuration management (Ansible).
Architectural Patterns and Design Principles
• Infrastructure as Code (IaC): The use of Terraform demonstrates declarative resource provisioning.
• Configuration Management: Ansible automates server configuration post-provisioning.
• Automation and Integration: The Python script bridges Terraform’s provisioning phase with Ansible’s configuration phase.
• Modularity: The separation of Terraform and Ansible components highlights a modular approach, allowing each stage (provisioning and configuration) to be independently managed and maintained.
Relevant Technologies, Frameworks, or Libraries
• Terraform: For provisioning DigitalOcean infrastructure.
• Ansible: For configuring and managing the server environment.
• Python: For automating Terraform operations and updating the Ansible inventory dynamically.
• DigitalOcean API: The cloud provider’s API is a key external interaction point.
• Nginx and MySQL: As part of the web server configuration, represented in the Ansible playbook and nginx.conf.j2 template.