76 lines
1.6 KiB
Terraform
76 lines
1.6 KiB
Terraform
|
resource "google_compute_network" "vpc" {
|
||
|
name = "vpc-terra"
|
||
|
auto_create_subnetworks = false
|
||
|
}
|
||
|
|
||
|
resource "google_compute_subnetwork" "front" {
|
||
|
name = "frontend"
|
||
|
network = google_compute_network.vpc.id
|
||
|
ip_cidr_range = "10.0.1.0/24"
|
||
|
region = "europe-west1-b"
|
||
|
}
|
||
|
|
||
|
resource "google_compute_subnetwork" "backend" {
|
||
|
name = "backend"
|
||
|
network = google_compute_network.vpc.id
|
||
|
ip_cidr_range = "10.0.2.0/24"
|
||
|
region = "europe-west1-b"
|
||
|
}
|
||
|
|
||
|
resource "google_compute_subnetwork" "database" {
|
||
|
name = "database"
|
||
|
network = google_compute_network.vpc.id
|
||
|
ip_cidr_range = "10.0.3.0/24"
|
||
|
region = "europe-west1"
|
||
|
}
|
||
|
|
||
|
resource "google_compute_firewall" "allow_http" {
|
||
|
name = "allow-http"
|
||
|
network = google_compute_network.vpc.id
|
||
|
|
||
|
allow {
|
||
|
protocol = "tcp"
|
||
|
ports = ["80", "443"]
|
||
|
}
|
||
|
target_tags = ["frontend"]
|
||
|
}
|
||
|
|
||
|
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]
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
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-data" {
|
||
|
name = "back-to-data"
|
||
|
network = google_compute_network.vpc.id
|
||
|
|
||
|
allow {
|
||
|
protocol = "tcp"
|
||
|
ports = ["3306"]
|
||
|
}
|
||
|
source_ranges = [ var.backend_cidr ]
|
||
|
target_tags = ["database"]
|
||
|
}
|
||
|
|
||
|
|