This commit is contained in:
Yanis DARIUS 2024-12-06 15:17:20 +01:00
parent d3be5f0031
commit abdd5136ec
4 changed files with 128 additions and 13 deletions

View File

@ -1,48 +1,47 @@
variable "project_name" { variable "project_name" {
description = "ID du projet GCP" description = "Nom du projet"
type = string type = string
default = "iut fbleau tp" default = "tp-1-docker"
} }
variable "project_id" { variable "project_id" {
description = "ID du projet GCP" description = "ID du projet"
type = string type = string
default = "iut fbleau tp" default = "tp-1-docker"
} }
variable "region" { variable "region" {
description = "region du projet" description = "gion du projet"
type = string type = string
default = "europe-west9" default = "europe-west4"
} }
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"
} }
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"
} }
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"
} }
variable "ssh_source_ranges" { variable "ssh_source_ranges" {
description = "acces par ssh" description = "Accès à internet"
type = string type = string
default = "0.0.0.0/0" default = "0.0.0.0/0"
} }
variable "cidr_range" { variable "cidr_range" {
description = "cidr-network" description = "cidr de network"
type = string type = string
default = "10.0.0.0/16" default = "10.0.0.0/16"
} }

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,21 @@
output "instance_names" {
description = "Noms des instances"
value = {
frontend = google_compute_instance.frontend.name
backend = google_compute_instance.backend.name
database = google_compute_instance.database.name
}
}
output "frontend_public_ip" {
value = google_compute_instance.frontend.network_interface[0].access_config[0].nat_ip
}
output "private_ip" {
description = "IPs internes de toutes les instances"
value = {
frontend = google_compute_instance.frontend.network_interface[0].network_ip
backend = google_compute_instance.backend.network_interface[0].network_ip
database = google_compute_instance.database.network_interface[0].network_ip
}
}

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
}