70 lines
1.6 KiB
Terraform
70 lines
1.6 KiB
Terraform
|
resource "google_compute_network" "my_vpc" {
|
||
|
name = "my-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_vpc.id
|
||
|
}
|
||
|
|
||
|
resource "google_compute_subnetwork" "backend" {
|
||
|
name = "backend"
|
||
|
ip_cidr_range = var.backend_cidr
|
||
|
region = var.region
|
||
|
network = google_compute_network.my_vpc.id
|
||
|
}
|
||
|
|
||
|
resource "google_compute_subnetwork" "database" {
|
||
|
name = "database"
|
||
|
ip_cidr_range = var.database_cidr
|
||
|
region = var.region
|
||
|
network = google_compute_network.my_vpc.id
|
||
|
}
|
||
|
|
||
|
resource "google_compute_firewall" "web" {
|
||
|
name = "web"
|
||
|
network = google_compute_network.my_vpc.id
|
||
|
allow {
|
||
|
protocol = "tcp"
|
||
|
ports = ["80", "443"]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
resource "google_compute_firewall" "ssh" {
|
||
|
name = "ssh"
|
||
|
network = google_compute_network.my_vpc.id
|
||
|
allow {
|
||
|
protocol = "tcp"
|
||
|
ports = ["22"]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
resource "google_compute_firewall" "frontend_to_backend" {
|
||
|
name = "frontend-to-backend"
|
||
|
network = google_compute_network.my_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_vpc.id
|
||
|
allow {
|
||
|
protocol = "tcp"
|
||
|
ports = ["3306"]
|
||
|
}
|
||
|
source_ranges = [
|
||
|
google_compute_subnetwork.backend.ip_cidr_range
|
||
|
]
|
||
|
target_tags = ["db"]
|
||
|
}
|