2024-12-06 16:15:47 +01:00
|
|
|
# VPC
|
|
|
|
resource "google_compute_network" "vpc" {
|
|
|
|
name = "myvpc"
|
2024-12-04 17:28:21 +01:00
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
2024-12-06 16:15:47 +01:00
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "frontend_subnet" {
|
|
|
|
name = "frontend-subnet"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.frontend_cidr
|
|
|
|
region = var.region
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 16:15:47 +01:00
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "backend_subnet" {
|
|
|
|
name = "backend-subnet"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.backend_cidr
|
|
|
|
region = var.region
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 16:15:47 +01:00
|
|
|
# Sous-réseau
|
|
|
|
resource "google_compute_subnetwork" "database_subnet" {
|
|
|
|
name = "database-subnet"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.database_cidr
|
|
|
|
region = var.region
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 16:15:47 +01:00
|
|
|
resource "google_compute_firewall" "allow_http" {
|
|
|
|
name = "allow-http"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["80"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
target_tags = ["web"]
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = ["web"]
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "allow_ssh" {
|
2024-12-06 16:15:47 +01:00
|
|
|
name = "allow-ssh"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = [var.ssh_source_ranges]
|
|
|
|
target_tags = ["ssh"]
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 16:15:47 +01:00
|
|
|
resource "google_compute_firewall" "allow_frontend_to_backend" {
|
|
|
|
name = "allow-frontend-to-backend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = [var.frontend_cidr]
|
|
|
|
target_tags = ["web"]
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 16:15:47 +01:00
|
|
|
resource "google_compute_firewall" "allow-sql" {
|
|
|
|
name = "allow-sql"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["3306"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = [var.backend_cidr]
|
|
|
|
target_tags = ["web"]
|
2024-12-04 17:28:21 +01:00
|
|
|
}
|