forked from pierront/but3-iac
Update
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
// 1. VPC personnalisé
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "${var.project_name}-vpc"
|
||||
project = var.project_name
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
// 2. Sous-réseaux
|
||||
|
||||
resource "google_compute_subnetwork" "frontend" {
|
||||
name = "${var.project_name}-frontend-subnet"
|
||||
project = var.project_name
|
||||
@@ -31,17 +28,12 @@ resource "google_compute_subnetwork" "database" {
|
||||
ip_cidr_range = var.database_cidr
|
||||
}
|
||||
|
||||
// 3. Règles de firewall
|
||||
|
||||
// 3.1 HTTP/HTTPS vers frontend (depuis Internet)
|
||||
resource "google_compute_firewall" "frontend_http_https" {
|
||||
name = "${var.project_name}-fw-frontend-http-https"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
|
||||
name = "${var.project_name}-fw-frontend-http-https"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
description = "Autorise HTTP/HTTPS vers les instances frontend"
|
||||
|
||||
direction = "INGRESS"
|
||||
direction = "INGRESS"
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
@@ -49,61 +41,46 @@ resource "google_compute_firewall" "frontend_http_https" {
|
||||
}
|
||||
|
||||
source_ranges = ["0.0.0.0/0"]
|
||||
|
||||
// Les instances frontend devront avoir ce tag
|
||||
target_tags = ["frontend"]
|
||||
target_tags = ["frontend"]
|
||||
}
|
||||
|
||||
// 3.2 SSH vers toutes les instances (depuis la plage fournie)
|
||||
resource "google_compute_firewall" "ssh_all" {
|
||||
name = "${var.project_name}-fw-ssh-all"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
|
||||
name = "${var.project_name}-fw-ssh-all"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
description = "Autorise SSH vers toutes les instances du VPC"
|
||||
|
||||
direction = "INGRESS"
|
||||
direction = "INGRESS"
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["22"]
|
||||
}
|
||||
|
||||
// Une seule CIDR passée en string, on l'enferme dans une liste
|
||||
source_ranges = [var.ssh_source_ranges]
|
||||
}
|
||||
|
||||
// 3.3 Port 8000 de frontend vers backend
|
||||
resource "google_compute_firewall" "frontend_to_backend_8000" {
|
||||
name = "${var.project_name}-fw-frontend-backend-8000"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
|
||||
name = "${var.project_name}-fw-frontend-backend-8000"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
description = "Autorise le trafic TCP 8000 des instances frontend vers backend"
|
||||
|
||||
direction = "INGRESS"
|
||||
direction = "INGRESS"
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
// Le trafic vient des instances taguées 'frontend'
|
||||
source_tags = ["frontend"]
|
||||
|
||||
// Et cible les instances taguées 'backend'
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
// 3.4 Port 3306 de backend vers database
|
||||
resource "google_compute_firewall" "backend_to_database_3306" {
|
||||
name = "${var.project_name}-fw-backend-database-3306"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
|
||||
name = "${var.project_name}-fw-backend-database-3306"
|
||||
project = var.project_name
|
||||
network = google_compute_network.vpc.name
|
||||
description = "Autorise le trafic TCP 3306 des instances backend vers database"
|
||||
|
||||
direction = "INGRESS"
|
||||
direction = "INGRESS"
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
|
||||
Reference in New Issue
Block a user