Correction OpenTofu pour exercice déploiement application 2 tiers Guestbook
| provider.tf | ||
| README.md | ||
| variables.tf | ||
| vars.sh | ||
OpenTofu Infrastructure – 2‑Tier AWS Demo
This project deploys a simple 2‑tier architecture on AWS using OpenTofu (Terraform-compatible IaC tool).
Architecture
The infrastructure created includes:
- VPC (
10.0.0.0/16) - Public subnet (EC2 web server)
- Two private subnets (RDS database)
- Internet Gateway
- Public and private route tables
- Security Groups
- EC2 instance running a Flask web application
- RDS MariaDB database
- Automatically generated SSH key pair
Architecture overview:
Internet
│
▼
Internet Gateway
│
Public Subnet
│
EC2 (Flask App)
│
Private Subnets
│
RDS MariaDB
Prerequisites
You must have the following installed:
- OpenTofu
- AWS CLI
- AWS credentials configured
Example:
aws configure
Project Structure
.
├── main.tf
├── variables.tf
├── vars.sh
└── README.md
Initialization
Importing env variables:
source ./vars.sh
Initialize the project and download providers:
tofu init
Planning the infrastructure
Run a plan to preview changes:
tofu plan
Deploy the infrastructure
tofu apply
Confirm with yes when prompted.
Accessing the application
After deployment:
- Retrieve the EC2 public IP:
tofu output
- Open in a browser:
http://EC2_PUBLIC_IP
You should see the AWS Guestbook Flask application.
SSH Access
The SSH key is automatically generated and saved locally:
stdkey.pem
Connect with:
chmod 600 stdkey.pem
ssh -i stdkey.pem ubuntu@EC2_PUBLIC_IP
Destroy the infrastructure
To remove all resources:
tofu destroy
Notes
- The RDS instance is deployed in private subnets.
- The web application connects to the database through security group rules.
- The database password is passed through a Terraform variable.
License
This project is for educational/demo purposes.