sauvegarde

This commit is contained in:
Tom MOGULJAK 2024-12-04 16:30:49 +01:00
parent f4716db2b4
commit bb87f0343a
4 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,27 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.0"
}
}
}
provider "google" {
project = var.project_name
region = var.region
}
module "network" {
source = "./modules/network"
#variables d'entrée
project_name = var.project_name
region = var.region
#autres variables spécifiques au module
frontend_cidr = var.frontend_cidr
backend_cidr = var.backend_cidr
database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges
}

View File

@ -0,0 +1,35 @@
variable "project_name" {
description = "nom du projet"
type = string
default = "projet-vertu"
}
variable "region" {
description = "region"
type = string
default = "europe-west4"
}
variable "frontend_cidr" {
description = "sous réseau frontend"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "sous réseau backend"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "sous réseau database"
type = string
default = "10.0.3.0/24"
}
variable "ssh_source_ranges" {
description = "ssh"
type = string
default = "0.0.0.0/0"
}

View File

@ -0,0 +1,82 @@
# VPC
resource "google_compute_network" "tp7" {
name = "tp7"
auto_create_subnetworks = false
}
# Sous-réseau frontend
resource "google_compute_subnetwork" "frontend" {
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = "europe-west4"
}
# Sous-réseau backend
resource "google_compute_subnetwork" "backend" {
name = "backend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = "europe-west4"
}
# Sous-réseau database
resource "google_compute_subnetwork" "database" {
name = "database"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = "europe-west4"
}
# Règle de pare-feu
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["ssh"]
}
resource "google_compute_firewall" "allow_http" {
name = "allow-http"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["80, 443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
}
resource "google_compute_firewall" "allow_front-to-back" {
name = "allow-front-to-back"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8080"]
}
source_ranges = ["frontend"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "allow_back-to-db" {
name = "allow-back-to-db"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_ranges = ["backend"]
target_tags = ["database"]
}

View File

@ -0,0 +1,29 @@
variable "project_name" {
description = "nom du projet"
type = string
}
variable "region" {
description = "region"
type = string
}
variable "frontend_cidr" {
description = "sous réseau frontend"
type = string
}
variable "backend_cidr" {
description = "sous réseau backend"
type = string
}
variable "database_cidr" {
description = "sous réseau database"
type = string
}
variable "ssh_source_ranges" {
description = "ssh"
type = string
}