forked from pierront/but3-iac
on espere ca va marcher
This commit is contained in:
81
terraform/modules/network/main.tf
Normal file
81
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,81 @@
|
||||
provider "google" {
|
||||
project = var.project_name
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_network" "custom_vpc" {
|
||||
name = "${var.project_name}-vpc"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "frontend" {
|
||||
name = "${var.project_name}-frontend-subnet"
|
||||
ip_cidr_range = var.frontend_cidr
|
||||
network = google_compute_network.custom_vpc.id
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "backend" {
|
||||
name = "${var.project_name}-backend-subnet"
|
||||
ip_cidr_range = var.backend_cidr
|
||||
network = google_compute_network.custom_vpc.id
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "database" {
|
||||
name = "${var.project_name}-database-subnet"
|
||||
ip_cidr_range = var.database_cidr
|
||||
network = google_compute_network.custom_vpc.id
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "frontend_http_https" {
|
||||
name = "${var.project_name}-frontend-http-https"
|
||||
network = google_compute_network.custom_vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["80", "443"]
|
||||
}
|
||||
|
||||
source_ranges = ["0.0.0.0/0"]
|
||||
target_tags = ["frontend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "ssh" {
|
||||
name = "${var.project_name}-ssh"
|
||||
network = google_compute_network.custom_vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["22"]
|
||||
}
|
||||
|
||||
source_ranges = [var.ssh_source_ranges]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "frontend_to_backend" {
|
||||
name = "${var.project_name}-frontend-to-backend"
|
||||
network = google_compute_network.custom_vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_tags = ["frontend"]
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "backend_to_database" {
|
||||
name = "${var.project_name}-backend-to-database"
|
||||
network = google_compute_network.custom_vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["3306"]
|
||||
}
|
||||
|
||||
source_tags = ["backend"]
|
||||
target_tags = ["database"]
|
||||
}
|
||||
13
terraform/modules/network/outputs.tf
Normal file
13
terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,13 @@
|
||||
output "vpc_id" {
|
||||
description = "ID du VPC créé"
|
||||
value = google_compute_network.custom_vpc.id
|
||||
}
|
||||
|
||||
output "subnet_ids" {
|
||||
description = "IDs des sous-réseaux"
|
||||
value = {
|
||||
frontend = google_compute_subnetwork.frontend.id
|
||||
backend = google_compute_subnetwork.backend.id
|
||||
database = google_compute_subnetwork.database.id
|
||||
}
|
||||
}
|
||||
33
terraform/modules/network/variables.tf
Normal file
33
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,33 @@
|
||||
variable "project_name" {
|
||||
description = "Nom du projet GCP"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Région pour le VPC et les sous-réseaux"
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
variable "ssh_source_ranges" {
|
||||
description = "Plages IP autorisées pour SSH"
|
||||
type = string
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
Reference in New Issue
Block a user