forked from pierront/but3-iac
on espere ca va marcher
This commit is contained in:
42
terraform/environements/dev/main.tf
Normal file
42
terraform/environements/dev/main.tf
Normal file
@@ -0,0 +1,42 @@
|
||||
# Provider Google
|
||||
provider "google" {
|
||||
project = var.project_id
|
||||
region = var.region
|
||||
zone = var.zone
|
||||
}
|
||||
|
||||
# Module IAM
|
||||
module "iam" {
|
||||
source = "../../modules/iam"
|
||||
project_id = var.project_id
|
||||
}
|
||||
|
||||
# Module Compute
|
||||
module "compute" {
|
||||
source = "../../modules/compute"
|
||||
instance_type = var.instance_type
|
||||
zone = var.zone
|
||||
frontend_subnet_id = var.frontend_subnet_id
|
||||
backend_subnet_id = var.backend_subnet_id
|
||||
database_subnet_id = var.database_subnet_id
|
||||
}
|
||||
|
||||
# Exemple de création d'un template pour Ansible
|
||||
data "template_file" "ansible_inventory" {
|
||||
template = <<EOT
|
||||
[frontend]
|
||||
${module.compute.frontend_internal_ip} ansible_user=YOUR_SSH_USER
|
||||
|
||||
[backend]
|
||||
${module.compute.backend_internal_ip} ansible_user=YOUR_SSH_USER
|
||||
|
||||
[database]
|
||||
${module.compute.database_internal_ip} ansible_user=YOUR_SSH_USER
|
||||
EOT
|
||||
}
|
||||
|
||||
# Optionnel : écrire le fichier sur le disque
|
||||
resource "local_file" "ansible_inventory" {
|
||||
content = data.template_file.ansible_inventory.rendered
|
||||
filename = "${path.module}/inventory.ini"
|
||||
}
|
||||
35
terraform/environements/dev/outputs.tf
Normal file
35
terraform/environements/dev/outputs.tf
Normal file
@@ -0,0 +1,35 @@
|
||||
# Outputs du module Compute
|
||||
output "frontend_internal_ip" {
|
||||
value = module.compute.frontend_internal_ip
|
||||
}
|
||||
|
||||
output "backend_internal_ip" {
|
||||
value = module.compute.backend_internal_ip
|
||||
}
|
||||
|
||||
output "database_internal_ip" {
|
||||
value = module.compute.database_internal_ip
|
||||
}
|
||||
|
||||
output "frontend_public_ip" {
|
||||
value = module.compute.frontend_public_ip
|
||||
}
|
||||
|
||||
output "instance_names" {
|
||||
value = module.compute.instance_names
|
||||
}
|
||||
|
||||
# Outputs du module IAM
|
||||
output "service_account_email" {
|
||||
value = module.iam.service_account_email
|
||||
}
|
||||
|
||||
output "service_account_key" {
|
||||
value = module.iam.service_account_key
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
# Output du fichier Ansible généré
|
||||
output "ansible_inventory_file" {
|
||||
value = local_file.ansible_inventory.filename
|
||||
}
|
||||
41
terraform/environements/dev/variables.tf
Normal file
41
terraform/environements/dev/variables.tf
Normal file
@@ -0,0 +1,41 @@
|
||||
# Variables pour le projet GCP
|
||||
variable "project_id" {
|
||||
description = "ID du projet GCP"
|
||||
type = string
|
||||
default = "mon-projet-gcp-dev"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Région GCP"
|
||||
type = string
|
||||
default = "europe-west1"
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "Zone GCP"
|
||||
type = string
|
||||
default = "europe-west1-b"
|
||||
}
|
||||
|
||||
# Variables pour les subnets
|
||||
variable "frontend_subnet_id" {
|
||||
description = "ID du subnet frontend"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "backend_subnet_id" {
|
||||
description = "ID du subnet backend"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "database_subnet_id" {
|
||||
description = "ID du subnet database"
|
||||
type = string
|
||||
}
|
||||
|
||||
# Type d'instance par défaut
|
||||
variable "instance_type" {
|
||||
description = "Type d'instance pour Compute"
|
||||
type = string
|
||||
default = "e2-medium"
|
||||
}
|
||||
Reference in New Issue
Block a user