From 43491ed096a1021dbd3def2657bc8411224cf46c Mon Sep 17 00:00:00 2001 From: Darius Date: Fri, 6 Dec 2024 16:12:47 +0100 Subject: [PATCH] fix --- tp-cloud/terraform/environments/dev/main.tf | 20 +++++++++++++++++-- .../terraform/environments/dev/variables.tf | 11 ++++++++-- tp-cloud/terraform/modules/compute/main.tf | 4 ++-- .../terraform/modules/compute/variables.tf | 2 +- tp-cloud/terraform/modules/iam/main.tf | 2 +- tp-cloud/terraform/modules/iam/variables.tf | 3 ++- tp-cloud/terraform/modules/network/main.tf | 1 + .../terraform/modules/network/variables.tf | 12 +++++------ tp-cloud/terraform/templates/ansible.cfg.tpl | 8 ++++++++ 9 files changed, 48 insertions(+), 15 deletions(-) diff --git a/tp-cloud/terraform/environments/dev/main.tf b/tp-cloud/terraform/environments/dev/main.tf index 547fa85..d5841a7 100644 --- a/tp-cloud/terraform/environments/dev/main.tf +++ b/tp-cloud/terraform/environments/dev/main.tf @@ -38,7 +38,23 @@ module "compute" { } module "iam" { - source = "../../modules/iam" - + source = "../../modules/iam" project_id = var.project_id +} + +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" +} + +resource "local_file" "service_account" { + content = base64decode(module.iam.service_account_key) + filename = "../../ansible/service_account.json" } \ No newline at end of file diff --git a/tp-cloud/terraform/environments/dev/variables.tf b/tp-cloud/terraform/environments/dev/variables.tf index c8b4d9e..9278c7e 100644 --- a/tp-cloud/terraform/environments/dev/variables.tf +++ b/tp-cloud/terraform/environments/dev/variables.tf @@ -1,39 +1,46 @@ +#- project_name (string) variable "project_name" { description = "Nom du projet" type = string - default = "newtp-443913" + default = "tp-1-docker" } +#- project_id (string) variable "project_id" { description = "ID du projet" type = string - default = "newtp-443913" + default = "tp-1-docker" } +# - region (string) variable "region" { description = "Région du projet" type = string default = "europe-west4" } +# - frontend_cidr (string) variable "frontend_cidr" { description = "cidr du frontend" type = string default = "10.0.1.0/24" } +# - backend_cidr (string) variable "backend_cidr" { description = "cidr du backend" type = string default = "10.0.2.0/24" } +# - database_cidr (string) variable "database_cidr" { description = "cidr du database" type = string default = "10.0.3.0/24" } +# - ssh_source_ranges (string) variable "ssh_source_ranges" { description = "Accès à internet" type = string diff --git a/tp-cloud/terraform/modules/compute/main.tf b/tp-cloud/terraform/modules/compute/main.tf index 2c16e80..dd38f46 100644 --- a/tp-cloud/terraform/modules/compute/main.tf +++ b/tp-cloud/terraform/modules/compute/main.tf @@ -36,6 +36,7 @@ resource "google_compute_instance" "backend" { network_interface { subnetwork = var.backend_subnet_id + access_config {} # IP publique } tags = ["backend", "ssh"] @@ -59,8 +60,7 @@ resource "google_compute_instance" "database" { network_interface { subnetwork = var.database_subnet_id - access_config {} - + access_config {} # IP publique } tags = ["database", "ssh"] diff --git a/tp-cloud/terraform/modules/compute/variables.tf b/tp-cloud/terraform/modules/compute/variables.tf index 5205614..6840a39 100644 --- a/tp-cloud/terraform/modules/compute/variables.tf +++ b/tp-cloud/terraform/modules/compute/variables.tf @@ -7,7 +7,7 @@ variable "instance_type" { variable "zone" { description = "zone des instances" type = string - default = "europe-west4-a" + default = "europe-west4" } variable "frontend_subnet_id" { diff --git a/tp-cloud/terraform/modules/iam/main.tf b/tp-cloud/terraform/modules/iam/main.tf index 1eefe7a..993825e 100644 --- a/tp-cloud/terraform/modules/iam/main.tf +++ b/tp-cloud/terraform/modules/iam/main.tf @@ -21,4 +21,4 @@ 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") -} \ No newline at end of file +} diff --git a/tp-cloud/terraform/modules/iam/variables.tf b/tp-cloud/terraform/modules/iam/variables.tf index 850ca8f..c76c7b1 100644 --- a/tp-cloud/terraform/modules/iam/variables.tf +++ b/tp-cloud/terraform/modules/iam/variables.tf @@ -1,4 +1,5 @@ +# modules/iam/variables.tf variable "project_id" { description = "ID du projet GCP" type = string -} \ No newline at end of file +} \ No newline at end of file diff --git a/tp-cloud/terraform/modules/network/main.tf b/tp-cloud/terraform/modules/network/main.tf index 2a1a23f..9b1ee92 100644 --- a/tp-cloud/terraform/modules/network/main.tf +++ b/tp-cloud/terraform/modules/network/main.tf @@ -1,3 +1,4 @@ +# VPC resource "google_compute_network" "vpc" { name = "myvpc" auto_create_subnetworks = false diff --git a/tp-cloud/terraform/modules/network/variables.tf b/tp-cloud/terraform/modules/network/variables.tf index 7d5fe2c..e56ec80 100644 --- a/tp-cloud/terraform/modules/network/variables.tf +++ b/tp-cloud/terraform/modules/network/variables.tf @@ -1,29 +1,29 @@ - +#- project_name (string) variable "project_name" { description = "Nom du projet" type = string } - +# - region (string) variable "region" { description = "Région du projet" type = string } - +# - frontend_cidr (string) variable "frontend_cidr" { description = "cidr du frontend" type = string } - +# - backend_cidr (string) variable "backend_cidr" { description = "cidr du backend" type = string } - +# - database_cidr (string) variable "database_cidr" { description = "cidr du database" type = string } - +# - ssh_source_ranges (string) variable "ssh_source_ranges" { description = "Accès à internet" type = string diff --git a/tp-cloud/terraform/templates/ansible.cfg.tpl b/tp-cloud/terraform/templates/ansible.cfg.tpl index e69de29..f0a8d1f 100644 --- a/tp-cloud/terraform/templates/ansible.cfg.tpl +++ b/tp-cloud/terraform/templates/ansible.cfg.tpl @@ -0,0 +1,8 @@ +[defaults] +host_key_checking = False +inventory = gcp_compute.yml +interpreter_python = auto_silent +remote_user = ${replace(replace(remote_user, ".", "_"), "@", "_")} + +[inventory] +enable_plugins = gcp_compute, auto, host_list, yaml, ini, toml, script \ No newline at end of file