Added the end of TP

This commit is contained in:
2024-12-06 15:54:49 +00:00
parent a18e0b1225
commit c53cf12609
18 changed files with 845 additions and 18 deletions

View File

@@ -0,0 +1,69 @@
resource "google_compute_instance" "vm_front" {
name = "vm-front"
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" "vm_back" {
name = "vm-back"
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" "vm_db" {
name = "vm-db"
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 = ["db", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}

View File

@@ -0,0 +1,22 @@
output "internal_ips" {
value = {
frontend = google_compute_instance.vm_front.network_interface.0.network_ip
backend = google_compute_instance.vm_back.network_interface.0.network_ip
database = google_compute_instance.vm_db.network_interface.0.network_ip
}
description = "Internal ips of instances"
}
output "public_ip" {
value = google_compute_instance.vm_front.network_interface.0.access_config.0.nat_ip
}
output "instance_names" {
value = {
frontend = google_compute_instance.vm_front.name
backend = google_compute_instance.vm_back.name
database = google_compute_instance.vm_db.name
}
description = "Name of instances"
}

View File

@@ -0,0 +1,29 @@
variable "instance_type" {
description = "GCP Instance type"
type = string
default = "e2-small"
}
variable "zone" {
description = "GCP Zone"
type = string
default = "europe-west1-b"
}
variable "frontend_subnet_id" {
description = "Frontend subnet ID"
type = string
default = "frontend"
}
variable "backend_subnet_id" {
description = "Backend subnet ID"
type = string
default = "backend"
}
variable "database_subnet_id" {
description = "Database subnet ID"
type = string
default = "database"
}