inshBouddah

This commit is contained in:
Jean-Luc NELET 2024-12-06 14:42:39 +01:00
parent 0811717b23
commit 6ee0abf341
6 changed files with 126 additions and 4 deletions

View File

@ -26,3 +26,13 @@ module "network" {
database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges
}
module "compute" {
source = "../../modules/compute"
instance_type = "e2-micro"
zone ="europe-west4"
frontend_subnet_id = module.network.id_subnetwork["frontend"]
backend_subnet_id = module.network.id_subnetwork["backend"]
database_subnet_id = module.network.id_subnetwork["database"]
}

View File

@ -4,36 +4,42 @@ variable "project_name" {
type = string
default = "tp-1-docker"
}
#- project_id (string)
variable "project_id" {
description = "ID du projet"
type = string
default = "tp-1-docker"
}
# - region (string)
variable "region" {
description = "Région du projet"
type = string
default = "europe-west4"
}
# - frontend_cidr (string)
variable "frontend_cidr" {
description = "cidr du frontend"
type = string
default = "10.0.1.0/24"
}
# - backend_cidr (string)
variable "backend_cidr" {
description = "cidr du backend"
type = string
default = "10.0.2.0/24"
}
# - database_cidr (string)
variable "database_cidr" {
description = "cidr du database"
type = string
default = "10.0.3.0/24"
}
# - ssh_source_ranges (string)
variable "ssh_source_ranges" {
description = "Accès à internet"

View File

@ -0,0 +1,69 @@
resource "google_compute_instance" "frontend" {
name = "ma-vm frontend"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
subnetwork = var.frontend_subnet_id
access_config {} # IP publique
}
tags = ["frontend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "backend" {
name = "ma-vm backend"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
subnetwork = var.backend_subnet_id
}
tags = ["backend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "database" {
name = "ma-vm database"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 20
}
}
network_interface {
subnetwork = var.database_subnet_id
}
tags = ["database", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}

View File

@ -0,0 +1,26 @@
variable "instance_type" {
description = "les types d'instances"
type = string
default = "e2-micro"
}
variable "zone" {
description = "zone des instances"
type = string
default = "europe-west4"
}
variable "frontend_subnet_id" {
description = "L'identifiant du subnet utilisé pour le frontend"
type = string
}
variable "backend_subnet_id" {
description = "L'identifiant du subnet utilisé pour le backend"
type = string
}
variable "database_subnet_id" {
description = "L'identifiant du subnet utilisé pour la database"
type = string
}

View File

@ -38,7 +38,7 @@ resource "google_compute_firewall" "allow_http" {
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "allow_https" {
@ -51,7 +51,7 @@ resource "google_compute_firewall" "allow_https" {
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "allow_ssh" {
@ -77,7 +77,7 @@ resource "google_compute_firewall" "allow_frontend_to_backend" {
}
source_ranges = [var.frontend_cidr]
target_tags = ["web"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "allow-sql" {
@ -90,5 +90,5 @@ resource "google_compute_firewall" "allow-sql" {
}
source_ranges = [var.backend_cidr]
target_tags = ["web"]
target_tags = ["database"]
}

View File

@ -0,0 +1,11 @@
output "id_vpc" {
value = google_compute_network.vpc.id
}
output "id_subnetwork" {
value = {
frontend=google_compute_network.frontend.id,
backend=google_compute_network.backend.id,
database=google_compute_network.database.id
}
}