Skip to content

Jurfest/iac-mba-activity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IaC MBA Activity

Jurfest Apps Logo

Infraestructure as Code MBA Activity

Last commit on GitHub Made by Jurfest Project top programing language GitHub license

Technologies   |    Automated setup   |    How to run Terraform and Ansible   |    License   |    Get in touch



💻 Technologies

This project was developed with the following technologies:

Initial Configuration Steps

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

Automated setup

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

How to run Terraform and Ansible

To manually provide and configure infrastructure and deploy the full-stack app, you can follow the following steps.

Running Terraform

# Go to terraform folder
$ cd terraform

# Run necessary terraform commands
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
$ cd ..

Running Ansible

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

🔬 How to inspect the result

Inside the browser:

http://public_ip

Connect to the Virtual Machine using SSH (Linux/Mac):

# 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

Preview

Printscreen resultado do docker ps com terminal conectado na maquina virtual

Vote application running on browser

Vote application running on browser

Destroying Infrastructure with Terraform

# 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

Acknowledgment

This Infrastructure as Code (IaC) exercise is built upon an Azure Sample showcasing a comprehensive full stack application called Azure Voting App.

📄 License

This project is under the MIT license.

📬 Get in touch!

LinkedIn

Thats it ! 👋


by Diego Jurfest 🎉