forked from pierront/but3-iac
arborenscence + fichier modifier
This commit is contained in:
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
0
terraform/modules/iam/variables.tf
Normal file
0
terraform/modules/iam/variables.tf
Normal file
86
terraform/modules/network/main.tf
Normal file
86
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,86 @@
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "${var.project_name}-vpc"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Sous-réseau
|
||||
resource "google_compute_subnetwork" "frontend" {
|
||||
name = "mon-frontend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = "10.0.1.0/24"
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "backend" {
|
||||
name = "mon-backend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = "10.0.2.0/24"
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "database" {
|
||||
name = "mon-database"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = "10.0.3.0/24"
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "ssh_firewall" {
|
||||
name = "mon_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" "frontend_firewall" {
|
||||
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" "backend_firewall" {
|
||||
name = "allow-http"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_ranges = ["frontend"]
|
||||
target_tags = ["backend"]
|
||||
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "database_firewall" {
|
||||
name = "allow-http"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["3306"]
|
||||
}
|
||||
|
||||
source_ranges = ["backend"]
|
||||
target_tags = ["database"]
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
16
terraform/modules/network/outputs.tf
Normal file
16
terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,16 @@
|
||||
output "vpc_terraform" {
|
||||
description = "ID du VPC créé"
|
||||
value = google_compute_instance.vpc.id
|
||||
|
||||
}
|
||||
|
||||
output "subnet_ids" {
|
||||
description = "IDs des sous-réseaux"
|
||||
value = {
|
||||
|
||||
frontend = google_compute_subnetwork.frontend.id
|
||||
backend = google_compute_subnetwork.backend.id
|
||||
database = google_compute_subnetwork.database.id
|
||||
}
|
||||
|
||||
}
|
||||
36
terraform/modules/network/variables.tf
Normal file
36
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,36 @@
|
||||
variable "project_name" {
|
||||
type = string
|
||||
description = "but3-iac"
|
||||
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "Région dans laquelle déployer les ressources"
|
||||
|
||||
}
|
||||
|
||||
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" {
|
||||
type = string
|
||||
description = "Plages d’adresses autorisées à se connecter en SSH"
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user