Skip to content

Springboot Fullstack Application Deployment on AWS, Infrastructure Automation with Terraform + Ansible

Notifications You must be signed in to change notification settings

Coding4Deep/Terraform-ansi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Springboot Fullstack Application Deployment on AWS

Infrastructure Automation with Terraform + Ansible


Project Overview

This project demonstrates fully automated infrastructure provisioning and configuration for a full-stack Spring Boot web application using:

  • Terraform: to provision AWS infrastructure (VPC, Subnets, EC2 instances, Security Groups, SSH Key, etc.)
  • Ansible: to install and configure required software on provisioned instances (Tomcat, Memcached, RabbitMQ, MongoDB)
  • Shell Scripting: to automated the whole process just by single command .

Tech Stack Used

Layer Technology
Infrastructure Provisioning Terraform
Infrastructure Configuration Ansible
Cloud Provider AWS
Application Server Apache Tomcat
Database MongoDB
Caching Memcached
Messaging Queue RabbitMQ

Prerequisites

Make sure you have following tools installed in your machine:

  1. Terraform

  2. Ansible

  3. AWS CLI

  4. Python Boto3 Module (for Ansible AWS Plugin)

    pip install boto3 botocore
  5. AWS Account with Access Key and Secret Key configured:

    aws configure

AWS Resources Provisioned

  • VPC

  • Public Subnet

  • Private Subnet

  • Security Groups

  • EC2 Instances:

    • Public EC2 (Tomcat Server)
    • Private EC2 (Memcached)
    • Private EC2 (RabbitMQ)
    • Private EC2 (MongoDB)
  • SSH Key Pair


Complete Project Structure

project-root/
│
├── terraform/
│   ├── # All Terraform code here
|
├── ansible/
│   ├── # All Ansible code here
|
└── project.pem (auto-generated by Terraform)

End-to-End Usage Guide

Step 1: Clone the Project Repository

git clone https://github.com/Coding4Deep/Terraform-Ansible-Project.git
cd Terraform-Ansible-Project

Step 2: Update Terraform Configuration

* Update `provider.tf` with your AWS region.
* Replace `ami-xxxxxxxx` with valid Ubuntu AMI ID from your region.

Step 3: Apply Terraform to Create Infrastructure

terraform init
terraform plan
terraform apply

✅ Terraform will create the entire AWS infrastructure. ✅ After provisioning is done, Terraform automatically triggers Ansible via null_resource to configure all servers.

Note: You may be prompted for approval during terraform apply.

Step 5: Ansible Dynamic Inventory Setup

Ensure you have valid AWS credentials locally (~/.aws/credentials).

The file ansible/inventory/aws_ec2.yaml uses AWS EC2 dynamic inventory plugin to auto-discover EC2 instances using tags.

You can test Ansible inventory:

cd ../ansible/
ansible-inventory --graph

You should see:

@all:
  |--@aws_ec2:
    |--@role_tomcat:
    |  |--springboot-public
    |--@role_memcached:
    |  |--springboot-memcached
    |--@role_rabbitmq:
    |  |--springboot-rabbitmq
    |--@role_mongo:
    |  |--springboot-mongo

No IP addresses needed. Fully dynamic!

Step 5: Run Ansible Playbooks Manually (optional)

If you want to re-run Ansible manually anytime:

ansible-playbook playbooks/site.yml

This will execute all roles (tomcat, memcached, rabbitmq, mongo).


What Happens During Provisioning?

Component Action
Terraform Provisions VPC, Subnets, EC2 Instances, Security Groups, SSH Key
Ansible Dynamically discovers EC2 instances via AWS tags
Tomcat Playbook Installs Java, Downloads and Configures Apache Tomcat
Memcached Playbook Installs and Starts Memcached Service
RabbitMQ Playbook Installs and Starts RabbitMQ Server
MongoDB Playbook Adds official MongoDB repo, Installs MongoDB, Starts MongoDB

Future Enhancements (Optional Improvements)

  • Use Bastion Host for secure SSH into private instances
  • Jenkins CI/CD integration for full automation pipeline
  • Monitoring with CloudWatch
  • HTTPS with ACM and Load Balancer

Credits

Created by [Deepak Sagar]. Open-source project to help anyone learn cloud provisioning and automation.


📅 License

This project is open-source and available under MIT License.


About

Springboot Fullstack Application Deployment on AWS, Infrastructure Automation with Terraform + Ansible

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published