forked from pierront/but3-iac
presque fini (je pense)
This commit is contained in:
@@ -4,6 +4,10 @@ terraform {
|
|||||||
source = "hashicorp/google"
|
source = "hashicorp/google"
|
||||||
version = "~> 6.12.0"
|
version = "~> 6.12.0"
|
||||||
}
|
}
|
||||||
|
local = {
|
||||||
|
source = "hashicorp/local"
|
||||||
|
version = "~> 2.5.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,21 +19,19 @@ provider "google" {
|
|||||||
module "network" {
|
module "network" {
|
||||||
source = "../../modules/network"
|
source = "../../modules/network"
|
||||||
project_name = var.project_name
|
project_name = var.project_name
|
||||||
region = var.region
|
region = var.region
|
||||||
frontend_cidr = var.frontend_cidr
|
frontend_cidr = var.frontend_cidr
|
||||||
backend_cidr = var.backend_cidr
|
backend_cidr = var.backend_cidr
|
||||||
database_cidr = var.database_cidr
|
database_cidr = var.database_cidr
|
||||||
ssh_source_ranges = var.ssh_source_ranges
|
ssh_source_ranges = var.ssh_source_ranges
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module "compute" {
|
module "compute" {
|
||||||
source = "../../modules/compute"
|
source = "../../modules/compute"
|
||||||
|
|
||||||
project_name = var.project_name
|
project_name = var.project_name
|
||||||
zone = var.zone
|
zone = var.zone
|
||||||
instance_type = var.instance_type
|
instance_type = var.instance_type
|
||||||
|
|
||||||
frontend_subnet_id = module.network.subnet_ids["frontend"]
|
frontend_subnet_id = module.network.subnet_ids["frontend"]
|
||||||
backend_subnet_id = module.network.subnet_ids["backend"]
|
backend_subnet_id = module.network.subnet_ids["backend"]
|
||||||
database_subnet_id = module.network.subnet_ids["database"]
|
database_subnet_id = module.network.subnet_ids["database"]
|
||||||
@@ -41,3 +43,15 @@ module "iam" {
|
|||||||
ssh_public_key_path = "/home/adriendick18/.ssh/id_ed25519.pub"
|
ssh_public_key_path = "/home/adriendick18/.ssh/id_ed25519.pub"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "google_client_openid_userinfo" "me" {}
|
||||||
|
|
||||||
|
resource "local_file" "ansible_cfg" {
|
||||||
|
filename = "${path.module}/ansible.cfg"
|
||||||
|
|
||||||
|
content = templatefile(
|
||||||
|
"${path.module}/../../templates/ansile.cfg.tpl",
|
||||||
|
{
|
||||||
|
remote_user = data.google_client_openid_userinfo.me.email
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# Commentaire
|
|
||||||
variable "project_name" {
|
variable "project_name" {
|
||||||
type = string
|
type = string
|
||||||
description = "but3-iac"
|
description = "Nom logique du projet"
|
||||||
default = "projet-virtualisation"
|
default = "projet-virtualisation"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,14 +37,13 @@ variable "database_cidr" {
|
|||||||
variable "ssh_source_ranges" {
|
variable "ssh_source_ranges" {
|
||||||
type = string
|
type = string
|
||||||
description = "Plages d’adresses autorisées à se connecter en SSH"
|
description = "Plages d’adresses autorisées à se connecter en SSH"
|
||||||
default = "0.0.0.0/0"
|
default = "0.0.0.0/0"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "project_id"{
|
variable "project_id" {
|
||||||
description = "id du projet"
|
description = "ID du projet GCP"
|
||||||
type = string
|
type = string
|
||||||
default = "projet-virtualisation-478713"
|
default = "projet-virtualisation-478713"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instance_type" {
|
variable "instance_type" {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ resource "google_compute_instance" "database" {
|
|||||||
boot_disk {
|
boot_disk {
|
||||||
initialize_params {
|
initialize_params {
|
||||||
image = "debian-cloud/debian-11"
|
image = "debian-cloud/debian-11"
|
||||||
size = 10
|
size = 20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,29 @@
|
|||||||
variable "project_name" {
|
variable "project_name" {
|
||||||
type = string
|
description = "Nom du projet / préfixe pour les VMs"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instance_type" {
|
variable "instance_type" {
|
||||||
type = string
|
description = "Type de machine à utiliser pour les instances"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "zone" {
|
variable "zone" {
|
||||||
type = string
|
description = "Zone où déployer les instances"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "frontend_subnet_id" {
|
variable "frontend_subnet_id" {
|
||||||
type = string
|
description = "ID du sous-réseau frontend"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "backend_subnet_id" {
|
variable "backend_subnet_id" {
|
||||||
type = string
|
description = "ID du sous-réseau backend"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "database_subnet_id" {
|
variable "database_subnet_id" {
|
||||||
type = string
|
description = "ID du sous-réseau database"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
variable "project_id" {
|
variable "project_id" {
|
||||||
type = string
|
description = "ID du projet GCP"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ssh_public_key_path" {
|
variable "ssh_public_key_path" {
|
||||||
type = string
|
|
||||||
description = "Chemin vers la clé publique SSH"
|
description = "Chemin vers la clé publique SSH"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ resource "google_compute_subnetwork" "database_network" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_firewall" "ssh_firewall" {
|
resource "google_compute_firewall" "ssh_firewall" {
|
||||||
name = "${var.project_name}-ssh"
|
name = "${var.project_name}-ssh"
|
||||||
network = google_compute_network.vpc.name
|
network = google_compute_network.vpc.name
|
||||||
direction = "INGRESS"
|
direction = "INGRESS"
|
||||||
priority = 1000
|
priority = 1000
|
||||||
target_tags = ["ssh"]
|
target_tags = ["ssh"]
|
||||||
source_ranges = [var.ssh_source_ranges]
|
source_ranges = [var.ssh_source_ranges]
|
||||||
|
|
||||||
allow {
|
allow {
|
||||||
@@ -39,11 +39,11 @@ resource "google_compute_firewall" "ssh_firewall" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_firewall" "frontend_firewall" {
|
resource "google_compute_firewall" "frontend_firewall" {
|
||||||
name = "${var.project_name}-frontend-http-https"
|
name = "${var.project_name}-frontend-http-https"
|
||||||
network = google_compute_network.vpc.name
|
network = google_compute_network.vpc.name
|
||||||
direction = "INGRESS"
|
direction = "INGRESS"
|
||||||
priority = 1000
|
priority = 1000
|
||||||
target_tags = ["frontend"]
|
target_tags = ["frontend"]
|
||||||
source_ranges = ["0.0.0.0/0"]
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
|
||||||
allow {
|
allow {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
output "vpc_id" {
|
output "vpc_id" {
|
||||||
value = google_compute_network.vpc.id
|
description = "ID du VPC créé"
|
||||||
|
value = google_compute_network.vpc.id
|
||||||
}
|
}
|
||||||
|
|
||||||
output "subnet_ids" {
|
output "subnet_ids" {
|
||||||
|
description = "Map des IDs des sous-réseaux"
|
||||||
value = {
|
value = {
|
||||||
frontend = google_compute_subnetwork.frontend_network.id
|
frontend = google_compute_subnetwork.frontend_network.id
|
||||||
backend = google_compute_subnetwork.backend_network.id
|
backend = google_compute_subnetwork.backend_network.id
|
||||||
|
|||||||
@@ -1,36 +1,29 @@
|
|||||||
variable "project_name" {
|
variable "project_name" {
|
||||||
|
description = "Nom du projet / préfixe des ressources réseau"
|
||||||
type = string
|
type = string
|
||||||
description = "but3-iac-dick"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "region" {
|
variable "region" {
|
||||||
|
description = "Région GCP"
|
||||||
type = string
|
type = string
|
||||||
description = "Région dans laquelle déployer les ressources"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "frontend_cidr" {
|
variable "frontend_cidr" {
|
||||||
description = "CIDR for frontend subnet"
|
description = "CIDR pour le subnet frontend"
|
||||||
type = string
|
type = string
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "backend_cidr" {
|
variable "backend_cidr" {
|
||||||
description = "CIDR for backend subnet"
|
description = "CIDR pour le subnet backend"
|
||||||
type = string
|
type = string
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "database_cidr" {
|
variable "database_cidr" {
|
||||||
description = "CIDR for database subnet"
|
description = "CIDR pour le subnet database"
|
||||||
type = string
|
type = string
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ssh_source_ranges" {
|
variable "ssh_source_ranges" {
|
||||||
|
description = "Plage IP autorisée pour le SSH"
|
||||||
type = string
|
type = string
|
||||||
description = "Plages d’adresses autorisées à se connecter en SSH"
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user