forked from pierront/but3-iac
premier push
This commit is contained in:
24
terraform/environments/dev/main.tf
Normal file
24
terraform/environments/dev/main.tf
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
google = {
|
||||||
|
source = "hashicorp/google"
|
||||||
|
version = "~> 6.12.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "google" {
|
||||||
|
project = var.project_id
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
module "network" {
|
||||||
|
source = "../../modules/network"
|
||||||
|
project_name = var.project_name
|
||||||
|
region = var.region
|
||||||
|
frontend_cidr = var.frontend_cidr
|
||||||
|
backend_cidr = var.backend_cidr
|
||||||
|
database_cidr = var.database_cidr
|
||||||
|
ssh_source_ranges = var.ssh_source_ranges
|
||||||
|
}
|
||||||
0
terraform/environments/dev/outputs.tf
Normal file
0
terraform/environments/dev/outputs.tf
Normal file
42
terraform/environments/dev/variables.tf
Normal file
42
terraform/environments/dev/variables.tf
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
variable "project_name" {
|
||||||
|
description = "Nom du projet cidr"
|
||||||
|
type = string
|
||||||
|
default = "mon-projet"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "region" {
|
||||||
|
description = "region du cidr"
|
||||||
|
type = string
|
||||||
|
default = "mon-projet"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "frontend_cidr" {
|
||||||
|
description = "CIDR for frontend subnet"
|
||||||
|
type = string
|
||||||
|
default = "10.0.1.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "backend_cidr" {
|
||||||
|
description = "CIDR for backend subnet"
|
||||||
|
type = string
|
||||||
|
default = "10.0.2.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_cidr" {
|
||||||
|
description = "CIDR for database subnet"
|
||||||
|
type = string
|
||||||
|
default = "10.0.3.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_source_ranges" {
|
||||||
|
description = "ssh_source_range du projet cidr"
|
||||||
|
type = string
|
||||||
|
default = "mon-projet"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
variable "project_id" {
|
||||||
|
description = "id du projet"
|
||||||
|
type = string
|
||||||
|
default = "model-cirrus-478713-u8"
|
||||||
|
}
|
||||||
0
terraform/modules/compute/main.tf
Normal file
0
terraform/modules/compute/main.tf
Normal file
0
terraform/modules/compute/outputs.tf
Normal file
0
terraform/modules/compute/outputs.tf
Normal file
0
terraform/modules/compute/variables.tf
Normal file
0
terraform/modules/compute/variables.tf
Normal file
0
terraform/modules/iam/main.tf
Normal file
0
terraform/modules/iam/main.tf
Normal file
0
terraform/modules/iam/outputs.tf
Normal file
0
terraform/modules/iam/outputs.tf
Normal file
5
terraform/modules/iam/variables.tf
Normal file
5
terraform/modules/iam/variables.tf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
variable "project_name" {
|
||||||
|
description = "Nom du projet cidr"
|
||||||
|
type = string
|
||||||
|
default = "mon-projet"
|
||||||
|
}
|
||||||
102
terraform/modules/network/main.tf
Normal file
102
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
# À vous de créer :
|
||||||
|
# 1. Un VPC personnalisé avec auto_create_subnetworks = false
|
||||||
|
# 2. Trois sous-réseaux (frontend, backend, database)
|
||||||
|
# 3. Règles de firewall :
|
||||||
|
# - HTTP/HTTPS vers frontend
|
||||||
|
# - SSH vers toutes les instances
|
||||||
|
# - Port 8000 de frontend vers backend
|
||||||
|
# - Port 3306 de backend vers database
|
||||||
|
|
||||||
|
|
||||||
|
# VPC
|
||||||
|
resource "google_compute_network" "vpc" {
|
||||||
|
name = "mon-vpc"
|
||||||
|
auto_create_subnetworks = false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sous-réseau
|
||||||
|
resource "google_compute_subnetwork" "frontend" {
|
||||||
|
name = "mon-frontend"
|
||||||
|
network = projet_cidr.vpc.id
|
||||||
|
ip_cidr_range = "10.0.1.0/24"
|
||||||
|
region = "europe-west1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sous-réseau
|
||||||
|
resource "google_compute_subnetwork" "backend" {
|
||||||
|
name = "mon-backend"
|
||||||
|
network = projet_cidr.vpc.id
|
||||||
|
ip_cidr_range = "10.0.2.0/24"
|
||||||
|
region = "europe-west1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sous-réseau
|
||||||
|
resource "google_compute_subnetwork" "database" {
|
||||||
|
name = "ma-database"
|
||||||
|
network = projet_cidr.vpc.id
|
||||||
|
ip_cidr_range = "10.0.3.0/24"
|
||||||
|
region = "europe-west1"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# firewall
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "frontend_firewall" {
|
||||||
|
name = "frontend"
|
||||||
|
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" "backend_firewall" {
|
||||||
|
name = "backend"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["8000"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_tags = ["frontend"]
|
||||||
|
target_tags = ["backend"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "database_firewall" {
|
||||||
|
name = "database"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["3306"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_tags = ["backend"]
|
||||||
|
target_tags = ["database"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "ssh_firewall" {
|
||||||
|
name = "ssh"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["22"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
target_tags = ["ssh"]
|
||||||
|
}
|
||||||
|
|
||||||
15
terraform/modules/network/outputs.tf
Normal file
15
terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
output "vpc_terraform" {
|
||||||
|
description = "ID du VPC créé"
|
||||||
|
value = google_compute_instance.vpc.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "subnet_ids" {
|
||||||
|
description = "Map des IDs des sous-réseaux"
|
||||||
|
value = {
|
||||||
|
|
||||||
|
frontend = google_compute_subnetwork.frontend.id
|
||||||
|
backend = google_compute_subnetwork.backend.id
|
||||||
|
database = google_compute_subnetwork.database.id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
terraform/modules/network/variables.tf
Normal file
31
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
variable "project_name" {
|
||||||
|
description = "Nom du projet cidr"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "region" {
|
||||||
|
description = "region du cidr"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "frontend_cidr" {
|
||||||
|
description = "CIDR for frontend subnet"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "backend_cidr" {
|
||||||
|
description = "CIDR for backend subnet"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_cidr" {
|
||||||
|
description = "CIDR for database subnet"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_source_ranges" {
|
||||||
|
description = "ssh_source_range du projet cidr"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user