Technologies | Automated setup | How to run Terraform and Ansible | License | Get in touch
This project was developed with the following technologies:
Note
Preparation steps before manual or automated setup
Clone repository
# Clone the repository
$ git clone https://github.com/jurfest/iac-mba-activity.git
# Go to project's folder
$ cd https://github.com/Jurfest/iac-mba-activity
# Open vscode - if wanted - or continue in the terminal or open another IDE
$ code .
Connect to your Azure account
# Opens a new window to connect to the Azure cloud provider
$ az login
Generate ssh-keys folder
# Create ssh-keygen folder
$ mkdir ssh-keygen
$ cd ssh-keygen
# Generate public and private key files by responding to prompt questions
$ ssh-keygen
$ cd ..
This Bash script automates the deployment of a full-stack application infrastructure using Terraform and Ansible. It provisions and configures a VM instance in Azure using Terraform, then configures the VM with Ansible, and finally executes a set of Docker containers using Docker Compose.
# Ensure Terraform, Ansible, netcat (nc), and jq are installed.
# After running the command bellow you can follow the prompts and monitor the logs for deployment progress.
bash setup.sh
# Remember to destroy infrastructure after use
To manually provide and configure infrastructure and deploy the full-stack app, you can follow the following steps.
# Go to terraform folder
$ cd terraform
# Run necessary terraform commands
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
$ cd ..
# Go to ansible folder
$ cd ansible
# Generate inventory file
$ bash create_hosts.sh
# Run playbook with verbosity
$ ansible-playbook -i inventory.ini playbook.yml -vvv
# Go back to main directory
$ cd ..
Inside the browser:
http://public_ip
# Connect to remote VM in the cloud (ssh azureadmin@11.111.111.11 -i ../ssh-keys/swarm-cluster)
$ ssh azureadmin@public_ip -i /path/to/your/private_key
# Verify if the containers are correctly being executed inside de VM
$ docker ps
# Disconnect from VM
$ exit # or press: ctrl + d
# Navigate to the Terraform configuration directory
$ cd terraform
# If you haven't already done so, initialize Terraform
$ terraform init
# Optional step to preview the changes Terraform will make to destroy the infrastructure
$ terraform plan -destroy
# Perform the destruction of resources. Terraform will prompt you to confirm this operation
$ terraform destroy
This Infrastructure as Code (IaC) exercise is built upon an Azure Sample showcasing a comprehensive full stack application called Azure Voting App.
This project is under the MIT license.
by Diego Jurfest 🎉