forked from pierront/but3-iac
initial
This commit is contained in:
0
terraform/environments/dev/main.tf
Normal file
0
terraform/environments/dev/main.tf
Normal file
0
terraform/environments/dev/outputs.tf
Normal file
0
terraform/environments/dev/outputs.tf
Normal file
0
terraform/environments/dev/variables.tf
Normal file
0
terraform/environments/dev/variables.tf
Normal file
0
terraform/modules/compute/main.tf
Normal file
0
terraform/modules/compute/main.tf
Normal file
0
terraform/modules/compute/outputs.tf
Normal file
0
terraform/modules/compute/outputs.tf
Normal file
0
terraform/modules/compute/variables.tf
Normal file
0
terraform/modules/compute/variables.tf
Normal file
0
terraform/modules/iam/main.tf
Normal file
0
terraform/modules/iam/main.tf
Normal file
0
terraform/modules/iam/outputs.tf
Normal file
0
terraform/modules/iam/outputs.tf
Normal file
0
terraform/modules/iam/variables.tf
Normal file
0
terraform/modules/iam/variables.tf
Normal file
83
terraform/modules/network/main.tf
Normal file
83
terraform/modules/network/main.tf
Normal 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"]
|
||||
}
|
||||
11
terraform/modules/network/outputs.tf
Normal file
11
terraform/modules/network/outputs.tf
Normal 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
|
||||
}
|
||||
}
|
||||
42
terraform/modules/network/variables.tf
Normal file
42
terraform/modules/network/variables.tf
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user