2024-12-04 17:02:32 +01:00
|
|
|
resource "google_compute_network" "vpc" {
|
|
|
|
name = "net1"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "subnet1" {
|
|
|
|
name = "frontend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.frontend_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "subnet2" {
|
|
|
|
name = "backend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.backend_cidr
|
|
|
|
region = var.region
|
2024-12-04 17:04:24 +01:00
|
|
|
}
|
2024-12-04 17:02:32 +01:00
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "subnet3" {
|
|
|
|
name = "database"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.database_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "allow_http" {
|
|
|
|
name = "rule-http"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["80", "443"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
target_tags = ["web"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "allow_ssh" {
|
|
|
|
name = "allow-ssh"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = [var.ssh_source_ranges]
|
|
|
|
target_tags = ["ssh"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "front_to_back" {
|
2024-12-04 17:06:31 +01:00
|
|
|
name = "front-to-back"
|
2024-12-04 17:02:32 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_tags = ["web"]
|
|
|
|
target_tags = ["backend"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "back_to_bdd" {
|
2024-12-04 17:06:31 +01:00
|
|
|
name = "back-to-bdd"
|
2024-12-04 17:02:32 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_tags = ["backend"]
|
|
|
|
target_tags = ["database"]
|
|
|
|
}
|