This commit is contained in:
2025-12-03 16:29:13 +01:00
parent e67b5bf03c
commit 35d6692ead
12 changed files with 179 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.12.0"
}
}
}
provider "google" {
project = var.project_id
region = var.region
}
module "network" {
source = "../../modules/network"
project_name = var.project_name
region = var.region
frontend_cidr = var.frontend_cidr
backend_cidr = var.backend_cidr
database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges
}

View File

View File

@@ -0,0 +1,39 @@
variable "project_name" {
description = "project name"
type = string
default = "nom de projet"
}
variable "project_id" {
description = "project id"
type = string
default = "dazzling-alpha-477917-q9"
}
variable "region" {
description = "region "
type = string
default = "europe-west9-b"
}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"
type = string
default = "0.0.0.0/0"
}

View File

View File

View File

View File

View File

View File

View File

@@ -0,0 +1,85 @@
# VPC
resource "google_compute_network" "vpc" {
name = "mon-vpc"
auto_create_subnetworks = false
}
# Sous-réseau
resource "google_compute_subnetwork" "frontend" {
name = "mon-frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = var.region
}
resource "google_compute_subnetwork" "backend" {
name = "mon-backend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = var.region
}
resource "google_compute_subnetwork" "database" {
name = "mon-database"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = var.region
}
# Pare-Feu
resource "google_compute_firewall" "frontend_http" {
name = "frontend-http"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "ssh" {
name = "ssh"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = [var.ssh_source_ranges]
target_tags = ["ssh"]
}
resource "google_compute_firewall" "front_back" {
name = "front_back"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_ranges = ["frontend"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "back_data" {
name = "back_data"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_ranges = ["backend"]
target_tags = ["database"]
}

View File

View File

@@ -0,0 +1,32 @@
variable "project_name" {
description = "project name"
type = string
}
variable "project_id" {
description = "project id"
type = string
}
variable "region" {
description = "region "
type = string
}variable "frontend_cidr" {
description = "CIDR for frontend subnet"
type = string
}
variable "backend_cidr" {
description = "CIDR for backend subnet"
type = string
}
variable "database_cidr" {
description = "CIDR for database subnet"
type = string
}
variable "ssh_source_ranges" {
description = "ssh"
type = string
}