2024-12-04 16:53:13 +01:00
|
|
|
resource "google_compute_network" "vpc" {
|
2024-12-06 15:35:23 +01:00
|
|
|
name = "myvpc"
|
2024-12-04 16:11:43 +01:00
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
2024-12-06 15:02:06 +01:00
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "frontend_subnet" {
|
|
|
|
name = "frontend-subnet"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.frontend_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
2024-12-06 15:02:06 +01:00
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "backend_subnet" {
|
|
|
|
name = "backend-subnet"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2024-12-06 15:02:06 +01:00
|
|
|
ip_cidr_range = var.backend_cidr
|
2024-12-04 16:11:43 +01:00
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
2024-12-06 15:02:06 +01:00
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "database_subnet" {
|
|
|
|
name = "database-subnet"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.database_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
2024-12-06 15:02:06 +01:00
|
|
|
resource "google_compute_firewall" "allow_http" {
|
|
|
|
name = "allow-http"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
2024-12-06 15:02:06 +01:00
|
|
|
ports = ["80"]
|
2024-12-04 16:11:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
2024-12-06 15:02:06 +01:00
|
|
|
target_tags = ["frontend"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "allow_https" {
|
|
|
|
name = "allow-https"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["443"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
target_tags = ["frontend"]
|
2024-12-04 16:11:43 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:38 +01:00
|
|
|
resource "google_compute_firewall" "allow_ssh" {
|
2024-12-04 16:30:22 +01:00
|
|
|
name = "allow-ssh"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:38 +01:00
|
|
|
source_ranges = [var.ssh_source_ranges]
|
2024-12-06 15:02:06 +01:00
|
|
|
target_tags = ["ssh"]
|
2024-12-04 16:11:43 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 15:02:06 +01:00
|
|
|
resource "google_compute_firewall" "allow_frontend_to_backend" {
|
|
|
|
name = "allow-frontend-to-backend"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:38 +01:00
|
|
|
source_ranges = [var.frontend_cidr]
|
2024-12-04 16:11:43 +01:00
|
|
|
target_tags = ["backend"]
|
|
|
|
}
|
|
|
|
|
2024-12-06 15:02:06 +01:00
|
|
|
resource "google_compute_firewall" "allow-sql" {
|
|
|
|
name = "allow-sql"
|
2024-12-04 16:11:43 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
2024-12-06 15:02:06 +01:00
|
|
|
ports = ["3306"]
|
2024-12-04 16:11:43 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:38 +01:00
|
|
|
source_ranges = [var.backend_cidr]
|
2024-12-04 16:11:43 +01:00
|
|
|
target_tags = ["database"]
|
|
|
|
}
|