1
0
forked from pierront/but3-iac

debut compute

This commit is contained in:
2025-12-04 09:02:57 +01:00
parent 6dbffb5a10
commit 7d80805e60
3 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
resource "google_compute_instance" "frontend" {
name = "${var.project_name}-frontend-vm"
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 {}
}
tags = ["frontend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
startup-script = var.startup_script
}
}
resource "google_compute_instance" "backend" {
name = "${var.project_name}-backend-vm"
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"
startup-script = var.startup_script
}
}
resource "google_compute_instance" "database" {
name = "${var.project_name}-database-vm"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
subnetwork = var.database_subnet_id
}
tags = ["database", "ssh"]
metadata = {
enable-oslogin = "TRUE"
startup-script = var.startup_script
}
}

View File

@@ -0,0 +1,19 @@
output "ip_internes" {
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
}
}
output "ip_public_frontend" {
value = google_compute_instance.frontend.network_interface[0].access_config[0].nat_ip
}
output "nom_instances" {
value = {
frontend = google_compute_instance.frontend.name
backend = google_compute_instance.backend.name
database = google_compute_instance.database.name
}
}

View File

@@ -0,0 +1,27 @@
variable "project_name" {
type = string
}
variable "instance_type" {
type = string
}
variable "zone" {
type = string
}
variable "frontend_subnet_id" {
type = string
}
variable "backend_subnet_id" {
type = string
}
variable "database_subnet_id" {
type = string
}
variable "startup_script" {
type = string
}