This commit is contained in:
Jean-Luc NELET 2024-12-04 16:11:44 +01:00
parent 00946add4d
commit 9e9fe81630
3 changed files with 146 additions and 0 deletions

View File

@ -0,0 +1,28 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.0"
}
}
}
provider "google" {
project = var.project_id
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
cidr_range = var.cidr_range
frontend_cidr = var.frontend_cidr
backend_cidr = var.backend_cidr
database_cidr = var.database
ssh_source_ranges = var.ssh_source_ranges
}

View File

@ -0,0 +1,41 @@
variable "project_name" {
description = "ID du projet"
type = string
default = "tp-1-docker"
}
variable "region" {
description = "region du projet"
type = string
default = "europe-west4-a"
}
variable "frontend_cidr" {
description = "frontend"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "backend"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "database"
type = string
default = "10.0.3.0/24"
}
variable "ssh_source_ranges" {
description = "acces internet"
type = string
default = "0.0.0.0/24"
}
variable "cidr_range" {
description = "cidr de network"
type = string
default = "10.0.0.0/16"
}

View File

@ -0,0 +1,77 @@
resource "google_compute_network" "vpc" {
name = "monvpc"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "frontend" {
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = var.region
}
resource "google_compute_subnetwork" "backend" {
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = var.region
}
resource "google_compute_subnetwork" "database" {
name = "datababse"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = var.region
}
resource "google_compute_firewall" "allow_http-https" {
name = "allow-http-https"
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_ssh" {
name = "allow-ssh"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = var.ssh_source_ranges
target_tags = ["web"]
}
resource "google_compute_firewall" "front-to-back" {
name = "front-to-back"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_ranges = var.frontend_cidr
target_tags = ["backend"]
}
resource "google_compute_firewall" "back-to-db" {
name = "back-to-db"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_ranges = var.backend_cidr
target_tags = ["database"]
}