Première tentative de mise en place

This commit is contained in:
2024-12-04 16:28:21 +00:00
parent 60747fc516
commit 6dc7ad109d
17 changed files with 531 additions and 0 deletions

View File

View File

View File

View File

View File

View File

View File

@@ -0,0 +1,68 @@
#réation du réseau VPC
resource "google_compute_network" "my_vpc" {
name = "mon-vpc"
auto_create_subnetworks = false
}
# Création des sous-réseaux
resource "google_compute_subnetwork" "frontend" {
name = "frontend"
ip_cidr_range = "10.0.1.0/24"
region = google_compute_network.my_vpc.region
network = google_compute_network.my_vpc.id
}
resource "google_compute_subnetwork" "backend" {
name = "backend"
ip_cidr_range = "10.0.2.0/24"
region = google_compute_network.my_vpc.region
network = google_compute_network.my_vpc.id
}
resource "google_compute_subnetwork" "database" {
name = "database"
ip_cidr_range = "10.0.3.0/24"
region = google_compute_network.my_vpc.region
network = google_compute_network.my_vpc.id
}
# Création des règles de firewall
resource "google_compute_firewall" "allow_http_https" {
name = "allow-http-https"
network = google_compute_network.my_vpc.id
allowed = [
{ IPProtocol = "tcp", ports = ["80", "443"] },
]
}
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh"
network = google_compute_network.my_vpc.id
allowed = [
{ IPProtocol = "tcp", ports = ["22"] },
]
}
resource "google_compute_firewall" "frontend_to_backend" {
name = "frontend-to-backend"
network = google_compute_network.my_vpc.id
allowed = [
{ IPProtocol = "tcp", ports = ["8000"] },
]
source_ranges = [
google_compute_subnetwork.frontend.ip_cidr_range
]
target_tags = ["backend"]
}
resource "google_compute_firewall" "backend_to_database" {
name = "backend-to-database"
network = google_compute_network.my_vpc.id
allowed = [
{ IPProtocol = "tcp", ports = ["3306"] },
]
source_ranges = [
google_compute_subnetwork.backend.ip_cidr_range
]
target_tags = ["database"]
}

View File

@@ -0,0 +1,13 @@
output "vpc_id" {
value = google_compute_network.my_vpc.id
description = "ID du VPC créé"
}
output "subnet_ids" {
value = {
frontend = google_compute_subnetwork.frontend.id
backend = google_compute_subnetwork.backend.id
database = google_compute_subnetwork.database.id
}
description = "Map contenant les IDs des sous-réseaux"
}

View File

@@ -0,0 +1,30 @@
# modules/network/variables.tf
variable "project_name" {
description = "Nom du projet Google Cloud"
type = string
default = "automatisation-tp"
}
variable "region" {
description = "Région Google Cloud"
type = string
}
variable "frontend_cidr" {
description = "Bloc CIDR pour le sous-réseau frontend"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "Bloc CIDR pour le sous-réseau backend"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "Bloc CIDR pour le sous-réseau database"
type = string
default = "10.0.3.0/24"
}