2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_network" "vpc" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "vpcsim"
|
2024-12-04 16:35:15 +01:00
|
|
|
auto_create_subnetworks = false
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_subnetwork" "frontend" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "frontend"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.frontend_cidr
|
2024-12-04 16:11:44 +01:00
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_subnetwork" "backend" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "backend"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.backend_cidr
|
2024-12-04 16:11:44 +01:00
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_subnetwork" "database" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "database"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.database_cidr
|
2024-12-04 16:11:44 +01:00
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_firewall" "allow-http-https" {
|
2024-12-04 16:32:43 +01:00
|
|
|
name = "allow-http-https"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["80", "443"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
source_ranges = ["0.0.0.0/0"]
|
|
|
|
target_tags = ["web"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_firewall" "allow-ssh" {
|
2024-12-04 16:32:43 +01:00
|
|
|
name = "allow-ssh"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
source_ranges = [var.ssh_source_ranges]
|
|
|
|
target_tags = ["ssh"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
resource "google_compute_firewall" "front-to-back" {
|
2024-12-04 16:36:24 +01:00
|
|
|
name = "front-to-back"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
source_ranges = [var.frontend_cidr]
|
|
|
|
target_tags = ["backend"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:36:24 +01:00
|
|
|
resource "google_compute_firewall" "back-to-db" {
|
|
|
|
name = "back-to-db"
|
2024-12-04 16:35:15 +01:00
|
|
|
network = google_compute_network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["3306"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:35:15 +01:00
|
|
|
source_ranges = [var.backend_cidr]
|
|
|
|
target_tags = ["database"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|