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"
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
# output.tf
|
||||
|
||||
# 1. ID du VPC
|
||||
output "vpc_id" {
|
||||
description = "ID du VPC personnalisé"
|
||||
value = google_compute_network.vpc.id
|
||||
}
|
||||
|
||||
# 2. IDs des sous-réseaux sous forme de map
|
||||
output "subnet_ids" {
|
||||
description = "Map des IDs des sous-réseaux (frontend, backend, database)"
|
||||
value = {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
variable "project_name" {
|
||||
description = "Name of the project"
|
||||
type = string
|
||||
default = "school-478713"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "The region of the VM"
|
||||
type = string
|
||||
default = "europe-west1"
|
||||
}
|
||||
|
||||
variable "frontend_cidr" {
|
||||
|
||||
Reference in New Issue
Block a user