tp_cloud/terraform/modules/network/main.tf

74 lines
1.8 KiB
HCL

resource "google_compute_network" "my_new_vpc" {
name = "my-new-vpc"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "frontend" {
name = "frontend"
ip_cidr_range = var.frontend_cidr
region = var.region
network = google_compute_network.my_new_vpc.id
}
resource "google_compute_subnetwork" "backend" {
name = "backend"
ip_cidr_range = var.backend_cidr
region = var.region
network = google_compute_network.my_new_vpc.id
}
resource "google_compute_subnetwork" "database" {
name = "database"
ip_cidr_range = var.database_cidr
region = var.region
network = google_compute_network.my_new_vpc.id
}
resource "google_compute_firewall" "web_rule" {
name = "web-rule"
network = google_compute_network.my_new_vpc.id
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = [var.web_source_ranges]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "ssh_rule" {
name = "ssh-rule"
network = google_compute_network.my_new_vpc.id
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = [var.ssh_source_ranges]
target_tags = ["ssh"]
}
resource "google_compute_firewall" "frontend_to_backend" {
name = "frontend-to-backend"
network = google_compute_network.my_new_vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_ranges = [
google_compute_subnetwork.frontend.ip_cidr_range
]
target_tags = ["backend"]
}
resource "google_compute_firewall" "backend_to_database" {
name = "backend-to-database"
network = google_compute_network.my_new_vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_ranges = [
google_compute_subnetwork.backend.ip_cidr_range
]
target_tags = ["db"]
}