DEV5.6_TP07/terraform/modules/network/main.tf

82 lines
1.7 KiB
Terraform
Raw Normal View History

2024-12-04 16:25:11 +01:00
#VPC
2024-12-04 16:28:08 +01:00
resource "google_compute_network" "tp07" {
2024-12-04 16:25:11 +01:00
name = "tp07"
auto_create_subnetworks = false
}
2024-12-04 16:28:08 +01:00
resource "google_compute_subnetwork" "tp07-frontend" {
2024-12-04 16:25:11 +01:00
name = "tp07-frontend"
2024-12-04 16:37:56 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
ip_cidr_range = var.frontend_cidr
region = "europe-west4"
}
2024-12-04 16:28:08 +01:00
resource "google_compute_subnetwork" "tp07-backend" {
2024-12-04 16:25:11 +01:00
name = "tp07-backend"
2024-12-04 16:37:56 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
ip_cidr_range = var.backend_cidr
region = "europe-west4"
}
2024-12-04 16:28:08 +01:00
resource "google_compute_subnetwork" "tp07-database" {
2024-12-04 16:25:11 +01:00
name = "tp07-database"
2024-12-04 16:37:56 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
ip_cidr_range = var.database_cidr
region = "europe-west4"
}
resource "google_compute_firewall" "allow_http_https" {
name = "allow-http-https"
2024-12-04 16:37:56 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh"
2024-12-04 16:37:56 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["ssh"]
}
2024-12-04 16:43:10 +01:00
resource "google_compute_firewall" "allow_front_back" {
2024-12-04 16:57:21 +01:00
name = "allow-front--back"
2024-12-04 16:38:58 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
allow {
protocol = "tcp"
ports = ["8000"]
}
source_tags = ["frontend"]
target_tags = ["backend"]
}
2024-12-04 16:43:10 +01:00
resource "google_compute_firewall" "allow_back_database" {
2024-12-04 16:57:21 +01:00
name = "allow-back--database"
2024-12-04 16:37:56 +01:00
network = google_compute_network.tp07.id
2024-12-04 16:25:11 +01:00
allow {
protocol = "tcp"
ports = ["3306"]
}
source_tags = ["backend"]
target_tags = ["database"]
}