From 5f4193870f455a85284354546b570755f7cbec78 Mon Sep 17 00:00:00 2001 From: SimonSayeBabu Date: Wed, 4 Dec 2024 16:11:44 +0100 Subject: [PATCH] test network --- terraform/environments/dev/main.tf | 28 +++++++++ terraform/environments/dev/outputs.tf | 0 terraform/environments/dev/variables.tf | 47 +++++++++++++++ terraform/modules/compute/main.tf | 0 terraform/modules/compute/outputs.tf | 0 terraform/modules/compute/variables.tf | 0 terraform/modules/iam/main.tf | 0 terraform/modules/iam/outputs.tf | 0 terraform/modules/iam/variables.tf | 0 terraform/modules/network/main.tf | 77 +++++++++++++++++++++++++ terraform/modules/network/outputs.tf | 0 terraform/modules/network/variables.tf | 0 12 files changed, 152 insertions(+) create mode 100644 terraform/environments/dev/main.tf create mode 100644 terraform/environments/dev/outputs.tf create mode 100644 terraform/environments/dev/variables.tf create mode 100644 terraform/modules/compute/main.tf create mode 100644 terraform/modules/compute/outputs.tf create mode 100644 terraform/modules/compute/variables.tf create mode 100644 terraform/modules/iam/main.tf create mode 100644 terraform/modules/iam/outputs.tf create mode 100644 terraform/modules/iam/variables.tf create mode 100644 terraform/modules/network/main.tf create mode 100644 terraform/modules/network/outputs.tf create mode 100644 terraform/modules/network/variables.tf diff --git a/terraform/environments/dev/main.tf b/terraform/environments/dev/main.tf new file mode 100644 index 0000000..5387a8a --- /dev/null +++ b/terraform/environments/dev/main.tf @@ -0,0 +1,28 @@ +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 + + # Autres variables spécifiques au module + cidr_range = var.cidr_range + frontend_cidr = var.frontend_cidr + backend_cidr = var.backend_cidr + database_cidr = var.database_cidr + ssh_source_ranges = var.ssh_source_ranges +} \ No newline at end of file diff --git a/terraform/environments/dev/outputs.tf b/terraform/environments/dev/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/environments/dev/variables.tf b/terraform/environments/dev/variables.tf new file mode 100644 index 0000000..bc97a1d --- /dev/null +++ b/terraform/environments/dev/variables.tf @@ -0,0 +1,47 @@ +# - project_name (string) +variable "project_name" { + description = "nom du projet" + type = string + default = "TP_IUT" +} + +# - region (string) +variable "region" { + description = "region du projet" + type = string + default = "europe-west1-d" +} + +# - 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 de la database" + type = string + default = "10.0.3.0/24" +} + +# - ssh_source_ranges (string) +variable "ssh_source_ranges" { + description = "acces internet" + type = string + default = "0.0.0.0/0" +} + +variable "cidr_range" { + description = "cidr de network" + type = string + default = "10.0.0.0/16" +} \ No newline at end of file diff --git a/terraform/modules/compute/main.tf b/terraform/modules/compute/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/compute/outputs.tf b/terraform/modules/compute/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/compute/variables.tf b/terraform/modules/compute/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/iam/main.tf b/terraform/modules/iam/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/iam/outputs.tf b/terraform/modules/iam/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/iam/variables.tf b/terraform/modules/iam/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/network/main.tf b/terraform/modules/network/main.tf new file mode 100644 index 0000000..090c421 --- /dev/null +++ b/terraform/modules/network/main.tf @@ -0,0 +1,77 @@ +resource "google_compute_network" "vpc" { + name = "vpcsim" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "subnet" { + name = "frontend" + network = google_compute_network.vpc.id + ip_cidr_range = var.frontend_cidr + region = var.region +} + +resource "google_compute_subnetwork" "subnet" { + name = "backend" + network = google_compute_network.vpc.id + ip_cidr_range = var.backend_cidr + region = var.region +} + +resource "google_compute_subnetwork" "subnet" { + name = "database" + network = google_compute_network.vpc.id + ip_cidr_range = var.database_cidr + region = var.region +} + +resource "google_compute_firewall" "allow_http-https" { + name = "allow_http-https" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["80", "443"] + } + + source_ranges = ["0.0.0.0/0"] + target_tags = ["web"] +} + +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 + target_tags = ["ssh"] +} + +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-db" { + name = "back-to-db" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["3306"] + } + + source_ranges = var.backend_cidr + target_tags = ["database"] +} \ No newline at end of file diff --git a/terraform/modules/network/outputs.tf b/terraform/modules/network/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/network/variables.tf b/terraform/modules/network/variables.tf new file mode 100644 index 0000000..e69de29