2025-12-03 16:12:14 +01:00
|
|
|
# À vous de créer :
|
|
|
|
|
# 1. Un VPC personnalisé avec auto_create_subnetworks = false
|
|
|
|
|
# 2. Trois sous-réseaux (frontend, backend, database)
|
|
|
|
|
# 3. Règles de firewall :
|
|
|
|
|
# - HTTP/HTTPS vers frontend
|
|
|
|
|
# - SSH vers toutes les instances
|
|
|
|
|
# - Port 8000 de frontend vers backend
|
|
|
|
|
# - Port 3306 de backend vers database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# VPC
|
|
|
|
|
resource "google_compute_network" "vpc" {
|
|
|
|
|
name = "mon-vpc"
|
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Sous-réseau
|
|
|
|
|
resource "google_compute_subnetwork" "frontend" {
|
|
|
|
|
name = "mon-frontend"
|
2025-12-03 16:50:35 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2025-12-03 16:12:14 +01:00
|
|
|
ip_cidr_range = "10.0.1.0/24"
|
|
|
|
|
region = "europe-west1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Sous-réseau
|
|
|
|
|
resource "google_compute_subnetwork" "backend" {
|
|
|
|
|
name = "mon-backend"
|
2025-12-03 16:50:35 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2025-12-03 16:12:14 +01:00
|
|
|
ip_cidr_range = "10.0.2.0/24"
|
|
|
|
|
region = "europe-west1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Sous-réseau
|
|
|
|
|
resource "google_compute_subnetwork" "database" {
|
|
|
|
|
name = "ma-database"
|
2025-12-03 16:50:35 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2025-12-03 16:12:14 +01:00
|
|
|
ip_cidr_range = "10.0.3.0/24"
|
|
|
|
|
region = "europe-west1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# firewall
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "frontend_firewall" {
|
|
|
|
|
name = "frontend"
|
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
ports = ["80", "443"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
|
target_tags = ["frontend"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "backend_firewall" {
|
|
|
|
|
name = "backend"
|
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
ports = ["8000"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source_tags = ["frontend"]
|
|
|
|
|
target_tags = ["backend"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "database_firewall" {
|
|
|
|
|
name = "database"
|
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
ports = ["3306"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source_tags = ["backend"]
|
|
|
|
|
target_tags = ["database"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "ssh_firewall" {
|
|
|
|
|
name = "ssh"
|
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
ports = ["22"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
|
target_tags = ["ssh"]
|
|
|
|
|
}
|
|
|
|
|
|