inshBouddah

This commit is contained in:
2024-12-06 14:42:39 +01:00
parent 0811717b23
commit 6ee0abf341
6 changed files with 126 additions and 4 deletions

View File

@@ -0,0 +1,69 @@
resource "google_compute_instance" "frontend" {
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" "backend" {
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" "database" {
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,26 @@
variable "instance_type" {
description = "les types d'instances"
type = string
default = "e2-micro"
}
variable "zone" {
description = "zone des instances"
type = string
default = "europe-west4"
}
variable "frontend_subnet_id" {
description = "L'identifiant du subnet utilisé pour le frontend"
type = string
}
variable "backend_subnet_id" {
description = "L'identifiant du subnet utilisé pour le backend"
type = string
}
variable "database_subnet_id" {
description = "L'identifiant du subnet utilisé pour la database"
type = string
}

View File

@@ -38,7 +38,7 @@ resource "google_compute_firewall" "allow_http" {
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "allow_https" {
@@ -51,7 +51,7 @@ resource "google_compute_firewall" "allow_https" {
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
target_tags = ["frontend"]
}
resource "google_compute_firewall" "allow_ssh" {
@@ -77,7 +77,7 @@ resource "google_compute_firewall" "allow_frontend_to_backend" {
}
source_ranges = [var.frontend_cidr]
target_tags = ["web"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "allow-sql" {
@@ -90,5 +90,5 @@ resource "google_compute_firewall" "allow-sql" {
}
source_ranges = [var.backend_cidr]
target_tags = ["web"]
target_tags = ["database"]
}

View File

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