2024-12-04 16:32:43 +01:00
|
|
|
resource "google-compute-network" "vpc" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "vpcsim"
|
2024-12-04 16:32:43 +01:00
|
|
|
auto-create-subnetworks = false
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
resource "google-compute-subnetwork" "frontend" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "frontend"
|
2024-12-04 16:32:43 +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:32:43 +01:00
|
|
|
resource "google-compute-subnetwork" "backend" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "backend"
|
2024-12-04 16:32:43 +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:32:43 +01:00
|
|
|
resource "google-compute-subnetwork" "database" {
|
2024-12-04 16:11:44 +01:00
|
|
|
name = "database"
|
2024-12-04 16:32:43 +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:32:43 +01:00
|
|
|
resource "google-compute-firewall" "allow-http-https" {
|
|
|
|
name = "allow-http-https"
|
|
|
|
network = google-compute-network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["80", "443"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
source-ranges = ["0.0.0.0/0"]
|
|
|
|
target-tags = ["web"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
resource "google-compute-firewall" "allow-ssh" {
|
|
|
|
name = "allow-ssh"
|
|
|
|
network = google-compute-network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
source-ranges = var.ssh-source-ranges
|
|
|
|
target-tags = ["ssh"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
resource "google-compute-firewall" "front-to-back" {
|
|
|
|
name = "front-to-back"
|
|
|
|
network = google-compute-network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
source-ranges = var.frontend-cidr
|
|
|
|
target-tags = ["backend"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
resource "google-compute-firewall" "back-to-db" {
|
|
|
|
name = "back-to-db"
|
|
|
|
network = google-compute-network.vpc.id
|
2024-12-04 16:11:44 +01:00
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["3306"]
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:32:43 +01:00
|
|
|
source-ranges = var.backend-cidr
|
|
|
|
target-tags = ["database"]
|
2024-12-04 16:11:44 +01:00
|
|
|
}
|