2024-12-04 16:30:49 +01:00
|
|
|
# VPC
|
2024-12-04 16:37:45 +01:00
|
|
|
resource "google_compute_network" "vpc" {
|
2024-12-04 16:30:49 +01:00
|
|
|
name = "tp7"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sous-réseau frontend
|
|
|
|
resource "google_compute_subnetwork" "frontend" {
|
|
|
|
name = "frontend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.frontend_cidr
|
|
|
|
region = "europe-west4"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sous-réseau backend
|
|
|
|
resource "google_compute_subnetwork" "backend" {
|
|
|
|
name = "backend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.backend_cidr
|
|
|
|
region = "europe-west4"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sous-réseau database
|
|
|
|
resource "google_compute_subnetwork" "database" {
|
|
|
|
name = "database"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.database_cidr
|
|
|
|
region = "europe-west4"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Règle de pare-feu
|
|
|
|
resource "google_compute_firewall" "allow_ssh" {
|
2024-12-04 16:48:45 +01:00
|
|
|
name = "allow-ssh-22"
|
2024-12-04 16:30:49 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
target_tags = ["ssh"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "allow_http" {
|
|
|
|
name = "allow-http"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
2024-12-04 16:48:45 +01:00
|
|
|
ports = ["80", "443"]
|
2024-12-04 16:30:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
2024-12-04 16:48:45 +01:00
|
|
|
target_tags = ["frontend"]
|
2024-12-04 16:30:49 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:48:45 +01:00
|
|
|
resource "google_compute_firewall" "allow_frontend_backend" {
|
2024-12-04 16:30:49 +01:00
|
|
|
name = "allow-front-to-back"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
2024-12-04 16:48:45 +01:00
|
|
|
ports = ["8000"]
|
2024-12-04 16:30:49 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:48:45 +01:00
|
|
|
source_tags = ["frontend"]
|
2024-12-04 16:30:49 +01:00
|
|
|
target_tags = ["backend"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:48:45 +01:00
|
|
|
resource "google_compute_firewall" "allow_backend_db" {
|
2024-12-04 16:30:49 +01:00
|
|
|
name = "allow-back-to-db"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["3306"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:48:45 +01:00
|
|
|
source_tags = ["backend"]
|
2024-12-04 16:30:49 +01:00
|
|
|
target_tags = ["database"]
|
|
|
|
}
|