Compare commits
2 Commits
main
...
fce17b31d2
| Author | SHA1 | Date | |
|---|---|---|---|
| fce17b31d2 | |||
| 4d39543590 |
25
terraform/environments/dev/main.tf
Normal file
25
terraform/environments/dev/main.tf
Normal file
@@ -0,0 +1,25 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = "~> 6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "google" {
|
||||
project = var.project_id
|
||||
region = var.region
|
||||
}
|
||||
|
||||
# Module Network
|
||||
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
|
||||
}
|
||||
10
terraform/environments/dev/outputs.tf
Normal file
10
terraform/environments/dev/outputs.tf
Normal file
@@ -0,0 +1,10 @@
|
||||
# Outputs du module Network
|
||||
output "vpc_id" {
|
||||
description = "ID du VPC"
|
||||
value = module.network.vpc_id
|
||||
}
|
||||
|
||||
output "subnet_ids" {
|
||||
description = "IDs des sous-réseaux"
|
||||
value = module.network.subnet_ids
|
||||
}
|
||||
53
terraform/environments/dev/variables.tf
Normal file
53
terraform/environments/dev/variables.tf
Normal file
@@ -0,0 +1,53 @@
|
||||
variable "project_id" {
|
||||
description = "ID du projet GCP"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "project_name" {
|
||||
description = "Nom du projet"
|
||||
type = string
|
||||
default = "mon-projet"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Région GCP"
|
||||
type = string
|
||||
default = "europe-west9"
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "Zone GCP pour les instances"
|
||||
type = string
|
||||
default = "europe-west9-a"
|
||||
}
|
||||
|
||||
variable "instance_type" {
|
||||
description = "Type d'instance GCP"
|
||||
type = string
|
||||
default = "n1-standard-1"
|
||||
}
|
||||
|
||||
variable "frontend_cidr" {
|
||||
description = "CIDR pour le sous-réseau frontend"
|
||||
type = string
|
||||
default = "10.0.1.0/24"
|
||||
}
|
||||
|
||||
variable "backend_cidr" {
|
||||
description = "CIDR pour le sous-réseau backend"
|
||||
type = string
|
||||
default = "10.0.2.0/24"
|
||||
}
|
||||
|
||||
variable "database_cidr" {
|
||||
description = "CIDR pour le sous-réseau database"
|
||||
type = string
|
||||
default = "10.0.3.0/24"
|
||||
}
|
||||
|
||||
variable "ssh_source_ranges" {
|
||||
description = "Plages d'adresses IP source autorisées pour SSH"
|
||||
type = string
|
||||
default = "0.0.0.0/0"
|
||||
}
|
||||
|
||||
80
terraform/modules/network/main.tf
Normal file
80
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,80 @@
|
||||
# VPC
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "${var.project_name}-vpc"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Sous-réseaux
|
||||
resource "google_compute_subnetwork" "frontend" {
|
||||
name = "${var.project_name}-frontend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.frontend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "backend" {
|
||||
name = "${var.project_name}-backend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.backend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "database" {
|
||||
name = "${var.project_name}-database"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.database_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
# Firewall
|
||||
resource "google_compute_firewall" "allow_http" {
|
||||
name = "${var.project_name}-allow-http"
|
||||
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 = "${var.project_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" "allow_frontend_to_backend" {
|
||||
name = "${var.project_name}-allow-frontend-to-backend"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_ranges = [var.frontend_cidr]
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "allow_backend_to_database" {
|
||||
name = "${var.project_name}-allow-backend-to-database"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["3306"]
|
||||
}
|
||||
|
||||
source_ranges = [var.backend_cidr]
|
||||
target_tags = ["database"]
|
||||
}
|
||||
13
terraform/modules/network/outputs.tf
Normal file
13
terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,13 @@
|
||||
output "vpc_id" {
|
||||
description = "ID du VPC"
|
||||
value = google_compute_network.vpc.id
|
||||
}
|
||||
|
||||
output "subnet_ids" {
|
||||
description = "IDs des sous-réseaux frontend, backend, database"
|
||||
value = {
|
||||
frontend = google_compute_subnetwork.frontend.id
|
||||
backend = google_compute_subnetwork.backend.id
|
||||
database = google_compute_subnetwork.database.id
|
||||
}
|
||||
}
|
||||
34
terraform/modules/network/variables.tf
Normal file
34
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,34 @@
|
||||
variable "project_name" {
|
||||
description = "Nom du projet"
|
||||
type = string
|
||||
default = "mon-projet"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Région du projet"
|
||||
type = string
|
||||
default = "europe-west9"
|
||||
}
|
||||
|
||||
variable "frontend_cidr" {
|
||||
description = "CIDR pour frontend"
|
||||
type = string
|
||||
default = "10.0.1.0/24"
|
||||
}
|
||||
|
||||
variable "backend_cidr" {
|
||||
description = "CIDR pour backend"
|
||||
type = string
|
||||
default = "10.0.2.0/24"
|
||||
}
|
||||
|
||||
variable "database_cidr" {
|
||||
description = "CIDR pour database"
|
||||
type = string
|
||||
default = "10.0.3.0/24"
|
||||
}
|
||||
|
||||
variable "ssh_source_ranges" {
|
||||
description = "Plages d'adresses IP source autorisées pour SSH"
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user