Correction OpenTofu pour exercice déploiement application 2 tiers Guestbook
Find a file
2026-03-12 14:53:31 +01:00
provider.tf first commit 2026-03-12 14:53:31 +01:00
README.md first commit 2026-03-12 14:53:31 +01:00
variables.tf first commit 2026-03-12 14:53:31 +01:00
vars.sh first commit 2026-03-12 14:53:31 +01:00

OpenTofu Infrastructure 2Tier AWS Demo

This project deploys a simple 2tier 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:

  1. Retrieve the EC2 public IP:
tofu output
  1. 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.