diff --git a/terraform/environments/dev/main.tf b/terraform/environments/dev/main.tf index e69de29..d6b991b 100644 --- a/terraform/environments/dev/main.tf +++ b/terraform/environments/dev/main.tf @@ -0,0 +1,22 @@ +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 + + +} \ No newline at end of file diff --git a/terraform/environments/dev/variables.tf b/terraform/environments/dev/variables.tf index e69de29..78fdb18 100644 --- a/terraform/environments/dev/variables.tf +++ b/terraform/environments/dev/variables.tf @@ -0,0 +1,35 @@ +variable "project_name"{ + description = "nom du projet" + type = string + default = "cours-virtu" +} + +variable "region"{ + description = "region du projet" + type = string + default = "europe-west4" +} + +variable "frontend_cidr"{ + description = "sous réseau frontend" + type = string + default = "10.0.1.0/24" +} + +variable "backend_cidr"{ + description = "sous réseau backend" + type = string + default = "10.0.2.0/24" +} + +variable "database_cidr"{ + description = "sous réseau database" + type = string + default = "10.0.3.0/24" +} + +variable "ssh_source_ranges"{ + description = "source range ssh" + type = string + default = "0.0.0.0/0" +} \ No newline at end of file diff --git a/terraform/modules/network/main.tf b/terraform/modules/network/main.tf index e69de29..558a3fa 100644 --- a/terraform/modules/network/main.tf +++ b/terraform/modules/network/main.tf @@ -0,0 +1,82 @@ +#VPC +resource "google_compute_network" "vpc" { + name = "tp07" + auto_create_subnetworks = false +} + + + +resource "google_compute_subnetwork" "subnet" { + name = "tp07-frontend" + network = google_compute_network.vpc.id + ip_cidr_range = var.frontend_cidr + region = "europe-west4" +} + +resource "google_compute_subnetwork" "subnet" { + name = "tp07-backend" + network = google_compute_network.vpc.id + ip_cidr_range = var.backend_cidr + region = "europe-west4" +} + +resource "google_compute_subnetwork" "subnet" { + name = "tp07-database" + network = google_compute_network.vpc.id + ip_cidr_range = var.database_cidr + region = "europe-west4" +} + + + +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 = ["frontend"] +} + +resource "google_compute_firewall" "allow_ssh" { + name = "allow-ssh" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["22"] + } + + source_ranges = ["0.0.0.0/0"] + target_tags = ["ssh"] +} + +resource "google_compute_firewall" "allow_front-back" { + name = "allow-front-back" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["8000"] + } + + source_tags = ["frontend"] + target_tags = ["backend"] +} + +resource "google_compute_firewall" "allow_front-back" { + name = "allow-front-back" + network = google_compute_network.vpc.id + + allow { + protocol = "tcp" + ports = ["3306"] + } + + source_tags = ["backend"] + target_tags = ["database"] +} \ No newline at end of file diff --git a/terraform/modules/network/variables.tf b/terraform/modules/network/variables.tf index e69de29..5b9521e 100644 --- a/terraform/modules/network/variables.tf +++ b/terraform/modules/network/variables.tf @@ -0,0 +1,30 @@ +variable "project_name"{ + description = "nom du projet" + type = string + default = "cours-virtu" +} + +variable "region"{ + description = "region du projet" + type = string +} + +variable "frontend_cidr"{ + description = "sous réseau frontend" + type = string +} + +variable "backend_cidr"{ + description = "sous réseau backend" + type = string +} + +variable "database_cidr"{ + description = "sous réseau database" + type = string +} + +variable "ssh_source_ranges"{ + description = "source range ssh" + type = string +} \ No newline at end of file