From 419e7e6fd0ebe0e7ab49fa96892ee3ce6349a763 Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 4 Dec 2024 16:11:43 +0100 Subject: [PATCH] step 1 --- tp-cloud/terraform/environments/dev/main.tf | 27 +++++++ .../terraform/environments/dev/variables.tf | 42 ++++++++++ tp-cloud/terraform/modules/network/main.tf | 78 +++++++++++++++++++ 3 files changed, 147 insertions(+) diff --git a/tp-cloud/terraform/environments/dev/main.tf b/tp-cloud/terraform/environments/dev/main.tf index e69de29..7c6530c 100644 --- a/tp-cloud/terraform/environments/dev/main.tf +++ b/tp-cloud/terraform/environments/dev/main.tf @@ -0,0 +1,27 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "~> 6.0" + } + } +} + +provider "google" { + project = var.project_id + region = var.region +} + + +module "network" { + source = "../../modules/network" + + project_name = var.project_name + region = var.region + + cidr_range = var.cidr_range + backend_cidr = var.backend_cidr + frontend_cidr = var.frontend_cidr + database_cidr = var.database_cidr + ssh_source_ranges = var.ssh_source_ranges +} \ 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 e69de29..4cdf4d5 100644 --- a/tp-cloud/terraform/environments/dev/variables.tf +++ b/tp-cloud/terraform/environments/dev/variables.tf @@ -0,0 +1,42 @@ +variable "project_name" { + description = "ID du projet GCP" + type = string + default = "iut fbleau tp" +} + +variable "region" { + description = "region du projet" + type = string + default = "europe-west9-c" +} + + +variable "frontend_cidr" { + description = "frontend" + type = string + default = "10.0.1.0/24" +} + +variable "backend_cidr" { + description = "backend" + type = string + default = "10.0.2.0/24" +} + +variable "database_cidr" { + description = "database" + type = string + default = "10.0.3.0/24" +} + +variable "ssh_source_ranges" { + description = "acces par ssh" + type = string + default = "0.0.0.0/0" +} + +variable "cidr_range" { + description = "cidr-network" + type = string + default = "10.0.0.0/16" +} diff --git a/tp-cloud/terraform/modules/network/main.tf b/tp-cloud/terraform/modules/network/main.tf index e69de29..523af10 100644 --- a/tp-cloud/terraform/modules/network/main.tf +++ b/tp-cloud/terraform/modules/network/main.tf @@ -0,0 +1,78 @@ +resource "google_compute_network" "vpc" { + name = "nom" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "frontend" { + name = "frontend" + network = google_compute_network.vpc.id + ip_cidr_range = var.frontend_cidr + region = var.region +} + +resource "google_compute_subnetwork" "backend" { + name = "backend" + network = google_compute_network.vpc.id + ip_cidr_range = var.backend_cidr + region = var.region +} + +resource "google_compute_subnetwork" "db" { + name = "db" + 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 = ["web"] +} + + +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