2024-12-04 16:11:44 +01:00
|
|
|
resource "google_compute_network" "vpc" {
|
|
|
|
name = "monvpc"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "frontend" {
|
|
|
|
name = "frontend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.frontend_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "backend" {
|
|
|
|
name = "frontend"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.backend_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "database" {
|
2024-12-04 16:17:39 +01:00
|
|
|
name = "database"
|
2024-12-04 16:11:44 +01:00
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
ip_cidr_range = var.database_cidr
|
|
|
|
region = var.region
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "allow_http-https" {
|
|
|
|
name = "allow-http-https"
|
|
|
|
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 = ["web"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "front-to-back" {
|
|
|
|
name = "front-to-back"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["8000"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = var.frontend_cidr
|
|
|
|
target_tags = ["backend"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "back-to-db" {
|
|
|
|
name = "back-to-db"
|
|
|
|
network = google_compute_network.vpc.id
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["3306"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = var.backend_cidr
|
|
|
|
target_tags = ["database"]
|
|
|
|
}
|