google ta mere

This commit is contained in:
SimonSayeBabu 2024-12-06 14:42:49 +01:00
parent 0ebc56b283
commit 93bb97f504
5 changed files with 118 additions and 1 deletions

View File

@ -25,4 +25,17 @@ module "network" {
backend_cidr = var.backend_cidr
database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges
}
module "compute" {
source = "../../modules/compute"
# Variables d'en"trée
instance_type = "e2-micro"
zone = "europe-west1-a"
# Autres variables spécifiques au module
frontend_subnet_id = module.network.id_subnetwork["frontend"]
backend_subnet_id = module.network.id_subnetwork["backend"]
database_subnet_id = module.network.id_subnetwork["database"]
}

View File

@ -0,0 +1,69 @@
resource "google_compute_instance" "vmfrontend" {
name = "ma-vm-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" "vmbackend" {
name = "ma-vm-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" "vmdatabase" {
name = "ma-vm-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,24 @@
variable "instance_type" {
description = "type d'instance"
type = string
}
variable "zone" {
description = "zone du projet"
type = string
}
variable "frontend_subnet_id" {
description = "id du subnet du frontend projet"
type = string
}
variable "backend_subnet_id" {
description = "id du subnet du backend projet"
type = string
}
variable "database_subnet_id" {
description = "id du subnet du database projet"
type = string
}

View File

@ -34,7 +34,7 @@ resource "google_compute_firewall" "allow-http-https" {
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "allow-ssh" {

View File

@ -0,0 +1,11 @@
output "id_vpc" {
value = google_compute_network.vpc.id
}
output "id_subnetwork" {
value = {
frontend = google_compute_subnetwork.frontend.id,
backend = google_compute_subnetwork.backend.id,
database = google_compute_subnetwork.database.id
}
}