fin du tp terraform

This commit is contained in:
rocherl
2024-12-06 16:24:57 +00:00
parent fc411afe95
commit fcf2b14ec1
20 changed files with 2021 additions and 31 deletions

View File

@@ -0,0 +1,69 @@
resource "google_compute_instance" "vm_frontend" {
name = "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" "vm_backend" {
name = "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" "vm_database" {
name = "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 "internal_ips" {
value = {
frontend = google_compute_instance.vm_frontend.network_interface.0.network_ip
backend = google_compute_instance.vm_backend.network_interface.0.network_ip
database = google_compute_instance.vm_database.network_interface.0.network_ip
}
description = "Internal ips of instances"
}
output "public_ip" {
value = google_compute_instance.vm_frontend.network_interface.0.access_config.0.nat_ip
}
output "instance_names" {
value = {
frontend = google_compute_instance.vm_frontend.name
backend = google_compute_instance.vm_backend.name
database = google_compute_instance.vm_database.name
}
description = "Name of instances"
}

View File

@@ -0,0 +1,30 @@
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"
}