2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_network" "vpc_terraform" {
|
|
|
|
|
name = "vpc-terraform"
|
2025-12-03 15:21:08 +00:00
|
|
|
auto_create_subnetworks = false
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "subnet_frontend" {
|
|
|
|
|
name = "frontend"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
ip_cidr_range = var.frontend_cidr
|
|
|
|
|
region = var.region
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_subnetwork" "subnet_backend" {
|
|
|
|
|
name = "backend"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
ip_cidr_range = var.backend_cidr
|
|
|
|
|
region = var.region
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_subnetwork" "subnet_database" {
|
|
|
|
|
name = "database"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
ip_cidr_range = var.database_cidr
|
|
|
|
|
region = var.region
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_firewall" "allow_user_frontend" {
|
|
|
|
|
name = "allow-user-frontend"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
ports = ["80", "443"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
|
target_tags = ["frontend"]
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_firewall" "allow_frontend_backend" {
|
|
|
|
|
name = "allow-frontend-backend"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
2025-12-03 17:15:51 +01:00
|
|
|
ports = ["8000"]
|
2025-12-03 15:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
source_tags = ["frontend"]
|
|
|
|
|
target_tags = ["backend"]
|
2025-12-03 15:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_firewall" "allow_ssh_all" {
|
|
|
|
|
name = "allow-ssh-all"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
2025-12-03 17:15:51 +01:00
|
|
|
ports = ["22"]
|
2025-12-03 15:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
|
target_tags = ["ssh"]
|
2025-12-03 15:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-03 17:15:51 +01:00
|
|
|
resource "google_compute_firewall" "allow_backend_database" {
|
|
|
|
|
name = "allow-backend-database"
|
|
|
|
|
network = google_compute_network.vpc_terraform.id
|
2025-12-03 15:21:08 +00:00
|
|
|
|
|
|
|
|
allow {
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
ports = ["3306"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source_tags = ["backend"]
|
2025-12-03 17:15:51 +01:00
|
|
|
target_tags = ["database"]
|
|
|
|
|
}
|