This commit is contained in:
2025-12-03 15:51:27 +01:00
parent e67b5bf03c
commit f2eef8ed81
12 changed files with 136 additions and 0 deletions

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

@@ -0,0 +1,83 @@
# À vous de créer :
# 1. Un VPC personnalisé avec auto_create_subnetworks = false
resource "google_compute_network" "VPC" {
name = "vpc"
auto_create_subnetworks = false
}
# 2. Trois sous-réseaux (frontend, backend, database)
resource "google_compute_subnetwork" "frontend" {
name = "${var.project_name}-frontend"
ip_cidr_range = var.frontend_cidr
region = var.region
network = google_compute_network.vpc.id
}
resource "google_compute_subnetwork" "backend" {
name = "${var.project_name}-backend"
ip_cidr_range = var.backend_cidr
region = var.region
network = google_compute_network.vpc.id
}
resource "google_compute_subnetwork" "database" {
name = "${var.project_name}-database"
ip_cidr_range = var.database_cidr
region = var.region
network = google_compute_network.vpc.id
}
# 3. Règles de firewall :
# HTTP/HTTPS → frontend
resource "google_compute_firewall" "frontend_http" {
name = "${var.project_name}-frontend-http"
network = google_compute_network.vpc.name
allow {
protocol = "tcp"
ports = ["80", "443"]
}
target_tags = ["frontend"]
source_ranges = ["0.0.0.0/0"]
}
# SSH → all
resource "google_compute_firewall" "ssh" {
name = "${var.project_name}-ssh"
network = google_compute_network.vpc.name
allow {
protocol = "tcp"
ports = ["22"]
}
target_tags = ["ssh"]
source_ranges = ["0.0.0.0/0"]
}
# Port 8000 : frontend → backend
resource "google_compute_firewall" "frontend_backend" {
name = "${var.project_name}-frontend-to-backend"
network = google_compute_network.vpc.name
allow {
protocol = "tcp"
ports = ["8000"]
}
source_tags = ["frontend"]
target_tags = ["backend"]
}
# Port 3306 : backend → database
resource "google_compute_firewall" "backend_database" {
name = "${var.project_name}-backend-to-database"
network = google_compute_network.vpc.name
allow {
protocol = "tcp"
ports = ["3306"]
}
source_tags = ["backend"]
target_tags = ["database"]
}

View File

@@ -0,0 +1,11 @@
output "vpc_id" {
value = google_compute_network.vpc.id
}
output "subnet_ids" {
value = {
frontend = google_compute_subnetwork.frontend.id
backend = google_compute_subnetwork.backend.id
database = google_compute_subnetwork.database.id
}
}

View File

@@ -0,0 +1,42 @@
# À vous de définir les variables pour :
# - project_name (string)
# - region (string)
# - frontend_cidr (string)
# - backend_cidr (string)
# - database_cidr (string)
# - ssh_source_ranges (string)
variable "project_name" {
description = "Nom du projet"
type = string
default = "Test IAC"
}
variable "region" {
description = "Nom de la région"
type = string
default = "europe-west9"
}
variable "frontend_cidr" {
description = "CIDR for frontend subnet"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "CIDR for backend subnet"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "CIDR for database subnet"
type = string
default = "10.0.3.0/24"
}
variable "ssh_source_ranges" {
description = "ssh_source_ranges"
type = string
}