forked from pierront/but3-iac
feat: compute module
This commit is contained in:
67
terraform/modules/compute/main.tf
Normal file
67
terraform/modules/compute/main.tf
Normal file
@@ -0,0 +1,67 @@
|
||||
resource "google_compute_instance" "frontend-vm" {
|
||||
name = "frontend-vm"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = "debian-cloud/debian-11"
|
||||
size = 10
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
access_config {}
|
||||
subnetwork = var.frontend_subnet_id
|
||||
}
|
||||
|
||||
tags = ["frontend", "ssh"]
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "backend-vm" {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "database-vm" {
|
||||
name = "database-vm"
|
||||
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"
|
||||
}
|
||||
}
|
||||
22
terraform/modules/compute/outputs.tf
Normal file
22
terraform/modules/compute/outputs.tf
Normal file
@@ -0,0 +1,22 @@
|
||||
output "internal_ips" {
|
||||
description = "IPs internes de toutes les instances"
|
||||
value = {
|
||||
frontend = google_compute_instance.frontend-vm.network_interface[0].network_ip
|
||||
backend = google_compute_instance.backend-vm.network_interface[0].network_ip
|
||||
database = google_compute_instance.database-vm.network_interface[0].network_ip
|
||||
}
|
||||
}
|
||||
|
||||
output "frontend_public_ip" {
|
||||
description = "IP publique du frontend"
|
||||
value = google_compute_instance.frontend-vm.network_interface[0].access_config[0].nat_ip
|
||||
}
|
||||
|
||||
output "instance_names" {
|
||||
description = "Noms des instances"
|
||||
value = {
|
||||
frontend = google_compute_instance.frontend-vm.name
|
||||
backend = google_compute_instance.backend-vm.name
|
||||
database = google_compute_instance.database-vm.name
|
||||
}
|
||||
}
|
||||
24
terraform/modules/compute/variables.tf
Normal file
24
terraform/modules/compute/variables.tf
Normal file
@@ -0,0 +1,24 @@
|
||||
variable "instance_type" {
|
||||
description = "Type d'instance"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "Zone GCP des instances"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "frontend_subnet_id" {
|
||||
description = "ID du sous-réseau frontend"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "backend_subnet_id" {
|
||||
description = "ID du sous-réseau backend"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "database_subnet_id" {
|
||||
description = "ID du sous-réseau database"
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user