TP_Terraform/terraform/modules/network/main.tf

78 lines
1.7 KiB
Terraform
Raw Permalink Normal View History

2024-12-06 14:44:53 +01:00
resource "google_compute_network" "vpc" {
name = "vpc2"
auto_create_subnetworks = false
}
# Sous-réseau
resource "google_compute_subnetwork" "subnet_front" {
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = var.region
}
resource "google_compute_subnetwork" "subnet_back" {
name = "backend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = var.region
}
resource "google_compute_subnetwork" "subnet_db" {
name = "database"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = var.region
}
resource "google_compute_firewall" "allow_http" {
2024-12-06 15:25:37 +01:00
name = "allow-http"
2024-12-06 14:44:53 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
}
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]
target_tags = ["ssh"]
}
resource "google_compute_firewall" "allow_frontend_to_backend" {
2024-12-06 15:25:37 +01:00
name = "allow-frontend-to-backend"
2024-12-06 14:44:53 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_tags = ["web"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "allow_backend_to_database" {
2024-12-06 15:25:37 +01:00
name = "allow-backend-to-database"
2024-12-06 14:44:53 +01:00
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_tags = ["backend"]
target_tags = ["database"]
}