This commit is contained in:
Jean-Luc NELET 2024-12-06 02:43:07 +01:00
parent 770fb2bb35
commit ebd9b043a5
3 changed files with 63 additions and 44 deletions

View File

@ -1,43 +1,44 @@
#- project_name (string)
variable "project_name" { variable "project_name" {
description = "nom du projet" description = "Nom du projet"
type = string type = string
default = "tp-1-docker" default = "but3-automatisation"
} }
#- project_id (string)
variable "project_id" { variable "project_id" {
description = "ID du projet" description = "ID du projet"
type = string type = string
default = "tp-1-docker" default = "but3-automatisation"
} }
# - region (string)
variable "region" { variable "region" {
description = "region du projet" description = "gion du projet"
type = string type = string
default = "europe-west4" default = "europe-west4"
} }
# - frontend_cidr (string)
variable "frontend_cidr" { variable "frontend_cidr" {
description = "frontend" description = "cidr du frontend"
type = string type = string
default = "10.0.1.0/24" default = "10.0.1.0/24"
} }
# - backend_cidr (string)
variable "backend_cidr" { variable "backend_cidr" {
description = "backend" description = "cidr du backend"
type = string type = string
default = "10.0.2.0/24" default = "10.0.2.0/24"
} }
# - database_cidr (string)
variable "database_cidr" { variable "database_cidr" {
description = "database" description = "cidr du database"
type = string type = string
default = "10.0.3.0/24" default = "10.0.3.0/24"
} }
# - ssh_source_ranges (string)
variable "ssh_source_ranges" { variable "ssh_source_ranges" {
description = "acces internet" description = "Accès à internet"
type = string type = string
default = "0.0.0.0/24" default = "0.0.0.0/0"
} }
variable "cidr_range" { variable "cidr_range" {

View File

@ -1,43 +1,60 @@
# VPC
resource "google_compute_network" "vpc" { resource "google_compute_network" "vpc" {
name = "monvpc" name = "myvpc"
auto_create_subnetworks = false auto_create_subnetworks = false
} }
resource "google_compute_subnetwork" "frontend" { # Sous-réseau
name = "frontend" resource "google_compute_subnetwork" "frontend_subnet" {
name = "frontend-subnet"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr ip_cidr_range = var.frontend_cidr
region = var.region region = var.region
} }
resource "google_compute_subnetwork" "backend" { # Sous-réseau
name = "frontend" resource "google_compute_subnetwork" "backend_subnet" {
name = "backend-subnet"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr ip_cidr_range = var.backend_cidr
region = var.region region = var.region
} }
resource "google_compute_subnetwork" "database" { # Sous-réseau
name = "database" resource "google_compute_subnetwork" "database_subnet" {
name = "database-subnet"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr ip_cidr_range = var.database_cidr
region = var.region region = var.region
} }
resource "google_compute_firewall" "allow-http-https" { resource "google_compute_firewall" "allow_http" {
name = "allow-http-https" name = "allow-http"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
allow { allow {
protocol = "tcp" protocol = "tcp"
ports = ["80", "443"] ports = ["80"]
} }
source_ranges = ["0.0.0.0/0"] source_ranges = ["0.0.0.0/0"]
target_tags = ["web"] target_tags = ["web"]
} }
resource "google_compute_firewall" "allow-ssh" { resource "google_compute_firewall" "allow_https" {
name = "allow-https"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
}
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh" name = "allow-ssh"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
@ -47,11 +64,11 @@ resource "google_compute_firewall" "allow-ssh" {
} }
source_ranges = [var.ssh_source_ranges] source_ranges = [var.ssh_source_ranges]
target_tags = ["web"] target_tags = ["ssh"]
} }
resource "google_compute_firewall" "front-to-back" { resource "google_compute_firewall" "allow_frontend_to_backend" {
name = "front-to-back" name = "allow-frontend-to-backend"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
allow { allow {
@ -60,11 +77,11 @@ resource "google_compute_firewall" "front-to-back" {
} }
source_ranges = [var.frontend_cidr] source_ranges = [var.frontend_cidr]
target_tags = ["backend"] target_tags = ["web"]
} }
resource "google_compute_firewall" "back-to-db" { resource "google_compute_firewall" "allow-sql" {
name = "back-to-db" name = "allow-sql"
network = google_compute_network.vpc.id network = google_compute_network.vpc.id
allow { allow {
@ -73,5 +90,5 @@ resource "google_compute_firewall" "back-to-db" {
} }
source_ranges = [var.backend_cidr] source_ranges = [var.backend_cidr]
target_tags = ["database"] target_tags = ["web"]
} }

View File

@ -1,30 +1,31 @@
#- project_name (string)
variable "project_name" { variable "project_name" {
description = "ID du projet" description = "Nom du projet"
type = string type = string
} }
# - region (string)
variable "region" { variable "region" {
description = "region du projet" description = "gion du projet"
type = string type = string
} }
# - frontend_cidr (string)
variable "frontend_cidr" { variable "frontend_cidr" {
description = "frontend" description = "cidr du frontend"
type = string type = string
} }
# - backend_cidr (string)
variable "backend_cidr" { variable "backend_cidr" {
description = "backend" description = "cidr du backend"
type = string type = string
} }
# - database_cidr (string)
variable "database_cidr" { variable "database_cidr" {
description = "database" description = "cidr du database"
type = string type = string
} }
# - ssh_source_ranges (string)
variable "ssh_source_ranges" { variable "ssh_source_ranges" {
description = "acces internet" description = "Accès à internet"
type = string type = string
} }