This commit is contained in:
Florian GENIQUE 2024-12-06 16:35:48 +01:00
parent 39851e8a42
commit 1a96b7692d
5 changed files with 78 additions and 7 deletions

View File

@ -26,14 +26,27 @@ module "network" {
ssh_source_ranges = var.ssh_source_ranges
}
/*module "iam" {
source = "../../modules/iam"
module "iam" {
source = "../../modules/iam"
project_id = var.project_id
}
# Variables d'entrée
data "google_client_openid_userinfo" "me" {
}
resource "local_file" "ansible_config" {
content = templatefile("${path.module}/../../templates/ansible.cfg.tpl",
{
remote_user = data.google_client_openid_userinfo.me.email
}
)
filename = "../../../ansible/ansible.cfg"
}
# Autres variables spécifiques au module
}*/
resource "local_file" "service_account" {
content = base64decode(module.iam.service_account_key)
filename = "../../../ansible/service_account.json"
}
module "compute" {
source = "../../modules/compute"

View File

@ -0,0 +1,19 @@
output "instance_name" {
value = {
frontend = google_compute_instance.vm-front.name
backend = google_compute_instance.vm-back.name
database = google_compute_instance.vm-database.name
}
}
output "ip_instance" {
value = {
frontend = google_compute_instance.vm_front.network_interface.0.network_ip
backend = google_compute_instance.vm_back.network_interface.0.network_ip
database = google_compute_instance.vm_db.network_interface.0.network_ip
}
}
output "frontend_public_ip" {
value = google_compute_instance.vm_front.network_interface.0.access_config.0.nat_ip
}

View File

@ -0,0 +1,24 @@
resource "google_service_account" "service_account" {
account_id = "terraform"
display_name = "terraform"
}
resource "google_service_account_key" "service_account" {
service_account_id = google_service_account.service_account.name
public_key_type = "TYPE_X509_PEM_FILE"
}
resource "google_project_iam_binding" "service_account_roles" {
project = var.project_id
role = "roles/viewer"
members = ["serviceAccount:${google_service_account.service_account.email}"]
}
data "google_client_openid_userinfo" "me" {
}
resource "google_os_login_ssh_public_key" "add_my_key" {
project = var.project_id
user = data.google_client_openid_userinfo.me.email
key = file("~/.ssh/id_ed25519.pub")
}

View File

@ -0,0 +1,10 @@
output "service_account_email" {
description = "Email du compte de service"
value = google_service_account.service_account.email
}
output "service_account_key" {
description = "Clé du compte de service"
value = google_service_account_key.service_account.private_key
sensitive = true
}

View File

@ -0,0 +1,5 @@
# modules/iam/variables.tf
variable "project_id" {
description = "ID du projet GCP"
type = string
}