forked from pierront/but3-iac
ajout computes
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# définissez toutes les variables nécessaires avec des valeurs par défaut appropriées.
|
||||
|
||||
# variable "project_id" {
|
||||
# description = "ID du projet GCP"
|
||||
# type = string
|
||||
# default = "mon-projet"
|
||||
# }
|
||||
|
||||
variable "project_name" {
|
||||
description = "Nom du projet"
|
||||
type = string
|
||||
|
||||
@@ -1,22 +1,100 @@
|
||||
# À vous de créer :
|
||||
# resource "google_compute_instance" "vm" {
|
||||
# name = "ma-vm"
|
||||
# machine_type = "e2-medium"
|
||||
# zone = "europe-west1-b"
|
||||
|
||||
# 1. Instance frontend :
|
||||
# - Image : debian-11
|
||||
# - Disque : 10GB
|
||||
# - IP publique
|
||||
# - Tags : frontend, ssh
|
||||
# - OS Login enabled
|
||||
# boot_disk {
|
||||
# initialize_params {
|
||||
# image = "debian-cloud/debian-11"
|
||||
# size = 10
|
||||
# }
|
||||
# }
|
||||
|
||||
# 2. Instance backend :
|
||||
# - Image : debian-11
|
||||
# - Disque : 10GB
|
||||
# - Pas d'IP publique (interne seulement)
|
||||
# - Tags : backend, ssh
|
||||
# - OS Login enabled
|
||||
# network_interface {
|
||||
# access_config {} # IP publique
|
||||
# subnetwork = google_compute_subnetwork.subnet.id
|
||||
# }
|
||||
|
||||
# 3. Instance database :
|
||||
# - Image : debian-11
|
||||
# - Disque : 20GB
|
||||
# - Pas d'IP publique
|
||||
# - Tags : database, ssh
|
||||
# - OS Login enabled
|
||||
# tags = ["web", "app"]
|
||||
|
||||
# metadata = {
|
||||
# enable-oslogin = "TRUE"
|
||||
# }
|
||||
# }
|
||||
|
||||
resource "google_compute_instance" "vm_frontend" {
|
||||
name = "frontend-instance"
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "vm_backend" {
|
||||
name = "backend-instance"
|
||||
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" "vm_database" {
|
||||
name = "database-instance"
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,24 @@
|
||||
# À vous d'exposer :
|
||||
# 1. Les IPs internes de toutes les instances
|
||||
# 2. L'IP publique du frontend
|
||||
# 3. Les noms des instances
|
||||
# output "instance_ip" {
|
||||
# value = google_compute_instance.main.network_interface[0].access_config[0].nat_ip
|
||||
# }
|
||||
|
||||
|
||||
output "ip_internes" {
|
||||
value = {
|
||||
frontend = google_compute_instance.vm_frontend.network_interface[0].network_ip
|
||||
backend = google_compute_instance.vm_backend.network_interface[0].network_ip
|
||||
database = google_compute_instance.vm_database.network_interface[0].network_ip
|
||||
}
|
||||
}
|
||||
|
||||
output "ip_public_frontend" {
|
||||
value = google_compute_instance.vm_frontend.network_interface[0].access_config[0].nat_ip
|
||||
}
|
||||
|
||||
output "nom_instances" {
|
||||
value = {
|
||||
frontend = google_compute_instance.vm_frontend.name
|
||||
backend = google_compute_instance.vm_backend.name
|
||||
database = google_compute_instance.vm_database.name
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,33 @@
|
||||
# À vous de définir les variables pour :
|
||||
# - instance_type
|
||||
# - zone
|
||||
# - frontend_subnet_id
|
||||
# - backend_subnet_id
|
||||
# - database_subnet_id
|
||||
# variable "project_id" {
|
||||
# description = "ID du projet GCP"
|
||||
# type = string
|
||||
# default = "mon-projet"
|
||||
# }
|
||||
|
||||
variable "instance_type" {
|
||||
description = "Type de machine à utiliser pour les instances"
|
||||
type = string
|
||||
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "Zone où déployer les 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
# À vous de créer :
|
||||
# 1. Un VPC personnalisé avec auto_create_subnetworks = false
|
||||
# 2. Trois sous-réseaux (frontend, backend, database)
|
||||
# 3. Règles de firewall :
|
||||
# - HTTP/HTTPS vers frontend
|
||||
# - SSH vers toutes les instances
|
||||
# - Port 8000 de frontend vers backend
|
||||
# - Port 3306 de backend vers database
|
||||
|
||||
# VPC
|
||||
# # VPC
|
||||
# resource "google_compute_network" "vpc" {
|
||||
# name = "mon-vpc"
|
||||
# auto_create_subnetworks = false
|
||||
# }
|
||||
resource "google_compute_network" "vpc_terraform" {
|
||||
name = "vpc-terraform"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Sous-réseau
|
||||
# # Sous-réseau
|
||||
# resource "google_compute_subnetwork" "subnet" {
|
||||
# name = "mon-subnet"
|
||||
# network = google_compute_network.vpc.id
|
||||
# ip_cidr_range = "10.0.1.0/24"
|
||||
# region = "europe-west1"
|
||||
# }
|
||||
resource "google_compute_subnetwork" "subnet_frontend" {
|
||||
name = "frontend"
|
||||
network = google_compute_network.vpc_terraform.id
|
||||
@@ -35,6 +36,19 @@ resource "google_compute_subnetwork" "subnet_database" {
|
||||
region = var.region
|
||||
}
|
||||
|
||||
# resource "google_compute_firewall" "allow_http" {
|
||||
# name = "allow-http"
|
||||
# network = google_compute_network.vpc.id
|
||||
|
||||
# allow {
|
||||
# protocol = "tcp"
|
||||
# ports = ["80", "443"]
|
||||
# }
|
||||
|
||||
# source_ranges = ["0.0.0.0/0"]
|
||||
# target_tags = ["web"]
|
||||
# }
|
||||
|
||||
resource "google_compute_firewall" "allow_user_frontend" {
|
||||
name = "allow-user-frontend"
|
||||
network = google_compute_network.vpc_terraform.id
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
# À vous d'exposer :
|
||||
# 1. L'ID du VPC
|
||||
# 2. Les IDs des sous-réseaux sous forme de map
|
||||
# output "instance_ip" {
|
||||
# value = google_compute_instance.main.network_interface[0].access_config[0].nat_ip
|
||||
# }
|
||||
|
||||
output "vpc_terraform_output" {
|
||||
description = "ID du VPC crée "
|
||||
value = google_compute_network.vpc_terraform.id
|
||||
}
|
||||
|
||||
output "list_id" {
|
||||
description = "Map des IDS des osus réseaux "
|
||||
value = {
|
||||
frontend = google_compute_subnetwork.subnet_frontend.id
|
||||
backend = google_compute_subnetwork.subnet_backend.id
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
# À vous de définir les variables pour :
|
||||
# - project_name (string)
|
||||
# - region (string)
|
||||
# - frontend_cidr (string)
|
||||
# - backend_cidr (string)
|
||||
# - database_cidr (string)
|
||||
# - ssh_source_ranges (string)
|
||||
# variable "project_id" {
|
||||
# description = "ID du projet GCP"
|
||||
# type = string
|
||||
# default = "mon-projet"
|
||||
# }
|
||||
|
||||
variable "project_name" {
|
||||
description = "Nom du projet"
|
||||
|
||||
Reference in New Issue
Block a user