diff --git a/terraform/environments/dev/main.tf b/terraform/environments/dev/main.tf index 7291d17..7e1b289 100644 --- a/terraform/environments/dev/main.tf +++ b/terraform/environments/dev/main.tf @@ -24,4 +24,15 @@ module "network" { backend_cidr = var.backend_cidr database_cidr = var.database_cidr ssh_source_ranges = var.ssh_source_ranges +} + +module "compute" { + source = "../../modules/compute" + + #autres variables spécifiques au module + instance_type = var.instance_type + zone = var.zone + frontend_subnet = module.network.frontend_subnet + backend_subnet = module.network.backend_subnet + database_subnet = module.network.database_subnet } \ No newline at end of file diff --git a/terraform/environments/dev/variables.tf b/terraform/environments/dev/variables.tf index eee90eb..49c6404 100644 --- a/terraform/environments/dev/variables.tf +++ b/terraform/environments/dev/variables.tf @@ -32,4 +32,34 @@ variable "ssh_source_ranges" { description = "ssh" type = string default = "0.0.0.0/0" +} + +variable "instance_type" { + description = "Type de machine" + type = string + default = "e2-small" +} + +variable "zone" { + description = "zone" + type = string + default = "europe-west4-b" +} + +variable "frontend_subnet" { + description = "sous réseau frontend" + type = string + default = "frontend" +} + +variable "backend_subnet" { + description = "sous réseau backend" + type = string + default = "backend" +} + +variable "database_subnet" { + description = "sous réseau database" + type = string + default = "database" } \ No newline at end of file diff --git a/terraform/modules/compute/main.tf b/terraform/modules/compute/main.tf index e69de29..a847639 100644 --- a/terraform/modules/compute/main.tf +++ b/terraform/modules/compute/main.tf @@ -0,0 +1,71 @@ +resource "google_compute_instance" "vm_front" { + 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 + access_config {} # IP publique + } + + tags = ["frontend", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} + +resource "google_compute_instance" "vm_back" { + 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 + access_config {} # IP publique + } + + tags = ["backend", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} + +resource "google_compute_instance" "vm_db" { + 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 + access_config {} # IP publique + } + + tags = ["database", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} \ No newline at end of file diff --git a/terraform/modules/compute/variables.tf b/terraform/modules/compute/variables.tf index e69de29..d636543 100644 --- a/terraform/modules/compute/variables.tf +++ b/terraform/modules/compute/variables.tf @@ -0,0 +1,25 @@ +variable "instance_type" { + description = "Type de machine" + type = string + +} + +variable "zone" { + description = "zone" + type = string +} + +variable "frontend_subnet" { + description = "sous réseau frontend" + type = string +} + +variable "backend_subnet" { + description = "sous réseau backend" + type = string +} + +variable "database_subnet" { + description = "sous réseau database" + type = string +} \ No newline at end of file