https://github.com/neckerfree/azure-fullstack-automation
This project automates the provisioning and deployment of a scalable cloud application on Microsoft Azure. It uses Terraform to create infrastructure, and Ansible to configure services like a backend API running on 2 VMs behind a Load Balancer, connected to an Azure MySQL database, along with a frontend deployed on Azure Web App.
https://github.com/neckerfree/azure-fullstack-automation
ansible api azure ci-cd mysql nodejs terraform
Last synced: 4 months ago
JSON representation
This project automates the provisioning and deployment of a scalable cloud application on Microsoft Azure. It uses Terraform to create infrastructure, and Ansible to configure services like a backend API running on 2 VMs behind a Load Balancer, connected to an Azure MySQL database, along with a frontend deployed on Azure Web App.
- Host: GitHub
- URL: https://github.com/neckerfree/azure-fullstack-automation
- Owner: NeckerFree
- Created: 2025-06-23T16:46:18.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-30T01:43:57.000Z (about 1 year ago)
- Last Synced: 2025-07-30T03:54:28.835Z (about 1 year ago)
- Topics: ansible, api, azure, ci-cd, mysql, nodejs, terraform
- Language: HCL
- Homepage:
- Size: 2.6 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Cloud Web App Deployment on Azure
# π Table of Contents
- [π About the Project](#about-project)
- [π Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [π Live Demo](#live-demo)
- [π» Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Provision Infrastructure (Terraform)](#terraform)
- [Configure Services (Ansible)](#ansible)
- [Deployment](#deployment)
- [π§ Customizing Variables](#custom-variables)
- [βοΈ Remote Terraform State in Azure](#οΈremote-terraform-state-in-azure)
- [π₯ Authors](#authors)
- [π Future Features](#future-features)
- [π€ Contributing](#contributing)
- [βοΈ Show your support](#support)
- [π Acknowledgements](#acknowledgements)
- [β FAQ](#faq)
- [π License](#license)
---
# π Azure Cloud Web App Deployment
This project automates the provisioning and deployment of a scalable cloud application on Microsoft Azure. It uses **Terraform** to create infrastructure, and **Ansible** to configure services like a backend API running on 2 VMs behind a Load Balancer, connected to an **Azure MySQL** database, along with a frontend deployed on **Azure Web App**.
Architecture Diagram
## π Built With
Infrastructure as Code
Configuration Management
Cloud Platform
Database
Deployment Targets
- Azure Virtual Machines
- Azure Load Balancer
- Azure App Service (Web App)
- π§ Automated infrastructure provisioning with Terraform
- π¦ Service configuration and app deployment using Ansible
- π MySQL database initialized via Ansible using `ansible/files/mysql/movie_db.sql`
- π Scalable API on 2 Azure VMs behind a Load Balancer
- πΎ Managed Azure MySQL integration
- π Web frontend deployed using Azure Web App
- π Service Principal authentication using Client Secret
- βοΈ Fully automated deployment workflow with CI/CD integration
- ποΈ End-to-end Terraform deployment from scratch included in workflow
- π§Ή Automated environment teardown using `terraform-destroy.yml`
- πΈ Uses Azure Web App **F1 Free Tier** for cost-effective deployment
Load Balancer API (Backend)
Azure Secrets
App Service
GH Actions Workflow
---
- [Frontend Web App](https://softdefault-movies-app.azurewebsites.net/)
- [API Endpoint (behind Load Balancer)](http://my-movie-analyst-lb.westus2.cloudapp.azure.com:8080/health)
Movie Analyst main page
Our Movies Critics
Latest Movie Reviews
Our Publication Partners
---
To get a local copy up and running, follow these instructions.
### Prerequisites
Most dependencies are installed automatically in the GitHub Actions workflow. However, for local development or debugging, ensure you have the following:
- π₯οΈ Azure CLI (`az`)
- π¦ Terraform β₯ 1.5
- βοΈ Ansible β₯ 2.15
- π SSH key pair for accessing virtual machines
- π¦ Node.js β₯ 14 and npm (required for both frontend and backend)
- π `zip` utility (used to package the frontend app)
- βοΈ Azure Service Principal credentials (used by the workflow):
- `ARM_CLIENT_ID`
- `ARM_CLIENT_SECRET`
- `ARM_TENANT_ID`
- `ARM_SUBSCRIPTION_ID`
- π‘ *(Optional)* GitHub CLI (`gh`) β useful for managing secrets or manually triggering workflows
### π§ Setup
```bash
# Clone this repository
git clone https://github.com/NeckerFree/azure-fullstack-automation.git
cd azure-fullstack-automation
```
create a file
## π¦ Provision Infrastructure (Terraform)
Infrastructure provisioning is fully automated and triggered via **GitHub Actions** on every push or pull request to the `master` branch.
- Terraform is initialized and executed within the workflow using predefined variables.
- The deployment includes:
- A MySQL database on Azure
- A Load Balancer with 2 backend VMs
- Network and security resources
- The entire infrastructure is provisioned from scratch via `terraform.yml`.
## βοΈ Configure Services (Ansible)
Ansible Jumpbox Configuration
Once the infrastructure is up, **Ansible playbooks** are automatically triggered within the same CI/CD workflow to:
- Configure the VMs with the required packages
- Deploy the Node.js API to both backend nodes
- Apply application settings
- Validate MySQL schema creation and data population
This configuration is handled through the `deploy-api.yml` GitHub Actions workflow.
- π― **Trigger**: Every push or pull request to `master` kicks off a full deployment pipeline.
- π **API** is publicly reachable via the Load Balancerβs IP address.
- π» **Frontend** is deployed to Azure Web App using the **F1 Free Tier**.
- π **Secure integration** between services via environment variables and Azure-managed credentials.
- 𧨠A separate `terraform-destroy.yml` workflow is available to automatically destroy all infrastructure when needed.
---
## π§ Customizing Variables
You can modify the following variables to adapt the deployment to your needs. These are defined in the Terraform configuration files:
### infra/terraform.tfvars:
```hcl
allowed_ssh_ip = "xxx.xxx.xxx.xxx/32" # IP allowed to access VMs via SSH
mysql_user = "mysqladmin" # MySQL admin user
mysql_admin_password = "Sec#reP@ssword123!" # MySQL admin password
```
### infra\variables.tf:
```hcl
variable "location" {
default = "westus2" # Azure region to deploy resources
}
variable "admin_username" {
default = "myadminuser" # Admin username for virtual machines
}
variable "lb_api_port" {
default = 8080 # API port exposed by Load Balancer
}
```
---
## βοΈ Remote Terraform State in Azure
Terraform uses remote state storage to persist infrastructure state across executions and team members.
This project stores the Terraform state file (`terraform.tfstate`) securely in an **Azure Storage Account** using a backend configuration like the following:
```hcl
terraform {
backend "azurerm" {
resource_group_name = "my-resource-group"
storage_account_name = "myterraformstate"
container_name = "tfstate"
key = "infrastructure.tfstate"
}
}
```
---
π€ **Elio CortΓ©s**
- GitHub: [@NeckerFree](https://github.com/NeckerFree)
- Twitter: [@ElioCortesM](https://twitter.com/ElioCortesM)
- LinkedIn: [elionelsoncortes](https://www.linkedin.com/in/elionelsoncortes/)
---
## π Future Features
- [ ] Enable autoscaling for the API tier
- [ ] Implement managed identity-based DB auth
---
Contributions, issues, and feature requests are welcome!
Feel free to open an issue, or request features.
---
If you like this project, please βοΈ the repository and share it with others!
---
- [Microsoft Azure documentation](https://learn.microsoft.com/en-us/azure/)
- [Ansible Azure Collection](https://galaxy.ansible.com/azure/azcollection) contributors
- [HashiCorp Terraform Modules](https://registry.terraform.io/)
- [devops-rampup](https://github.com/aljoveza/devops-rampup) β Backend & frontend prototype used as base for this project
- [EPAM DevOps Campus](https://campus.epam.com/en/training) β Cloud and DevOps learning program
- [ChatGPT](https://chatgpt.com/) β Assistance in automation, CI/CD, and documentation
- [DeepSeek](https://chat.deepseek.com/) β Assistance in automation, CI/CD, and documentation
---
### π Where are secrets like passwords and keys stored?
Secrets are securely stored as GitHub Actions secrets and injected at runtime into the workflows.
### π§ͺ Can I test changes before deploying to Azure?
Yes! You can test locally using `terraform plan` and `ansible-playbook` in dry-run mode before committing changes.
### π Where is the infrastructure deployed?
By default, all resources are deployed to the `westus2` Azure region. You can change this in `infra/variables.tf`.
### π What if I want to destroy all resources?
You can run the `terraform-destroy.yml` GitHub Actions workflow to safely destroy the provisioned infrastructure.
### π How is the database created?
The Azure MySQL database is provisioned with Terraform and initialized using `movie_db.sql` from Ansible.
### π What is the default URL for the frontend?
The frontend is hosted on Azure Web App. The exact URL depends on the generated Azure App Service name. Check the Azure Portal or output logs.
---
This project is licensed under the [MIT License](./LICENSE).