TP_Cloud/terraform/modules/network/main.tf

77 lines
1.6 KiB
Terraform
Raw Normal View History

2024-12-04 16:11:44 +01:00
resource "google_compute_network" "vpc" {
name = "vpcsim"
auto_create_subnetworks = false
}
2024-12-04 16:16:32 +01:00
resource "google_compute_subnetwork" "frontend" {
2024-12-04 16:11:44 +01:00
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = var.region
}
2024-12-04 16:16:32 +01:00
resource "google_compute_subnetwork" "backend" {
2024-12-04 16:11:44 +01:00
name = "backend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = var.region
}
2024-12-04 16:16:32 +01:00
resource "google_compute_subnetwork" "database" {
2024-12-04 16:11:44 +01:00
name = "database"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = var.region
}
2024-12-04 16:30:26 +01:00
resource "google_compute_firewall" "allowHttpHttps" {
name = "allowHttpHttps"
2024-12-04 16:11:44 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
}
2024-12-04 16:30:26 +01:00
resource "google_compute_firewall" "allowSsh" {
name = "allowSsh"
2024-12-04 16:11:44 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = var.ssh_source_ranges
target_tags = ["ssh"]
}
2024-12-04 16:30:26 +01:00
resource "google_compute_firewall" "frontToBack" {
name = "frontToBack"
2024-12-04 16:11:44 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_ranges = var.frontend_cidr
target_tags = ["backend"]
}
2024-12-04 16:30:26 +01:00
resource "google_compute_firewall" "backToDb" {
name = "backToDb"
2024-12-04 16:11:44 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_ranges = var.backend_cidr
target_tags = ["database"]
}