From fc411afe95741cd699c1815647bf124fdb19a3e2 Mon Sep 17 00:00:00 2001 From: rocherl Date: Wed, 4 Dec 2024 16:23:22 +0000 Subject: [PATCH] ajout de quelques fichiers de config --- environments/dev/main.tf | 37 +++++++++++++++++ environments/dev/outputs.tf | 0 environments/dev/variables.tf | 12 ++++++ modules/compute/main.tf | 0 modules/compute/outputs.tf | 0 modules/compute/variables.tf | 0 modules/iam/main.tf | 0 modules/iam/outputs.tf | 0 modules/iam/variables.tf | 0 modules/network/main.tf | 75 +++++++++++++++++++++++++++++++++++ modules/network/outputs.tf | 0 modules/network/variables.tf | 36 +++++++++++++++++ templates/ansible.cfg.tpl | 0 13 files changed, 160 insertions(+) create mode 100644 environments/dev/main.tf create mode 100644 environments/dev/outputs.tf create mode 100644 environments/dev/variables.tf create mode 100644 modules/compute/main.tf create mode 100644 modules/compute/outputs.tf create mode 100644 modules/compute/variables.tf create mode 100644 modules/iam/main.tf create mode 100644 modules/iam/outputs.tf create mode 100644 modules/iam/variables.tf create mode 100644 modules/network/main.tf create mode 100644 modules/network/outputs.tf create mode 100644 modules/network/variables.tf create mode 100644 templates/ansible.cfg.tpl diff --git a/environments/dev/main.tf b/environments/dev/main.tf new file mode 100644 index 0000000..8f2f67f --- /dev/null +++ b/environments/dev/main.tf @@ -0,0 +1,37 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.0" + } + } +} + +provider "google" { + project = var.project_id + region = var.region +} + +module "network" { + source = "./modules/network" + + # Variables d'entrée + project_name = var.project_name + region = var.region +} + +module "iam" { + source = "./modules/iam" + + # Variables d'entrée + project_name = var.project_name + region = var.region +} + +module "compute" { + source = "./modules/compute" + + # Variables d'entrée + project_name = var.project_name + region = var.region +} diff --git a/environments/dev/outputs.tf b/environments/dev/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/environments/dev/variables.tf b/environments/dev/variables.tf new file mode 100644 index 0000000..572a8a1 --- /dev/null +++ b/environments/dev/variables.tf @@ -0,0 +1,12 @@ +variable "projet_id" { + description = "ID du projet GCP" + type = string + default = "automatisation-tp1" +} + +variable "region" { + description = "region des vms" + type = string + default = "europe-west1-b" +} + diff --git a/modules/compute/main.tf b/modules/compute/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/compute/outputs.tf b/modules/compute/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/compute/variables.tf b/modules/compute/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/iam/main.tf b/modules/iam/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/iam/outputs.tf b/modules/iam/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/iam/variables.tf b/modules/iam/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/network/main.tf b/modules/network/main.tf new file mode 100644 index 0000000..46d1063 --- /dev/null +++ b/modules/network/main.tf @@ -0,0 +1,75 @@ +resource "google_compute_network" "vpc" { + name = "vpc-terra" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "front" { + name = "frontend" + network = google_compute_network.vpc.id + ip_cidr_range = "10.0.1.0/24" + region = "europe-west1-b" +} + +resource "google_compute_subnetwork" "backend" { + name = "backend" + network = google_compute_network.vpc.id + ip_cidr_range = "10.0.2.0/24" + region = "europe-west1-b" +} + +resource "google_compute_subnetwork" "database" { + name = "database" + network = google_compute_network.vpc.id + ip_cidr_range = "10.0.3.0/24" + region = "europe-west1" +} + +resource "google_compute_firewall" "allow_http" { + name = "allow-http" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["80", "443"] + } + target_tags = ["frontend"] +} + +resource "google_compute_firewall" "allow_ssh" { + name = "allow-ssh" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["22"] + } +source_ranges = [var.ssh_source_ranges] + +} + + +resource "google_compute_firewall" "front-to-back" { + name = "front-to-back" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["8000"] + } + source_ranges = [ var.frontend_cidr ] + target_tags = ["backend"] +} + +resource "google_compute_firewall" "back-to-data" { + name = "back-to-data" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["3306"] + } + source_ranges = [ var.backend_cidr ] + target_tags = ["database"] +} + + diff --git a/modules/network/outputs.tf b/modules/network/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/modules/network/variables.tf b/modules/network/variables.tf new file mode 100644 index 0000000..308a0e4 --- /dev/null +++ b/modules/network/variables.tf @@ -0,0 +1,36 @@ +# modules/network/variables.tf + +variable "project_name" { + description = "Nom du projet Google Cloud" + type = string + default = "automatisation-tp1" +} + +variable "region" { + description = "Région Google Cloud" + type = string +} + +variable "frontend_cidr" { + description = "Bloc CIDR pour le sous-réseau frontend" + type = string + default = "10.0.1.0/24" +} + +variable "backend_cidr" { + description = "Bloc CIDR pour le sous-réseau backend" + type = string + default = "10.0.2.0/24" +} + +variable "database_cidr" { + description = "Bloc CIDR pour le sous-réseau database" + type = string + default = "10.0.3.0/24" +} + +variable "ssh_source_ranges" { + description = "source ranges" + type = string + default = "0.0.0.0/0" +} diff --git a/templates/ansible.cfg.tpl b/templates/ansible.cfg.tpl new file mode 100644 index 0000000..e69de29