Première tentative de mise en place
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
68
terraform/modules/network/main.tf
Normal file
68
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,68 @@
|
||||
#réation du réseau VPC
|
||||
resource "google_compute_network" "my_vpc" {
|
||||
name = "mon-vpc"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Création des sous-réseaux
|
||||
resource "google_compute_subnetwork" "frontend" {
|
||||
name = "frontend"
|
||||
ip_cidr_range = "10.0.1.0/24"
|
||||
region = google_compute_network.my_vpc.region
|
||||
network = google_compute_network.my_vpc.id
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "backend" {
|
||||
name = "backend"
|
||||
ip_cidr_range = "10.0.2.0/24"
|
||||
region = google_compute_network.my_vpc.region
|
||||
network = google_compute_network.my_vpc.id
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "database" {
|
||||
name = "database"
|
||||
ip_cidr_range = "10.0.3.0/24"
|
||||
region = google_compute_network.my_vpc.region
|
||||
network = google_compute_network.my_vpc.id
|
||||
}
|
||||
|
||||
# Création des règles de firewall
|
||||
resource "google_compute_firewall" "allow_http_https" {
|
||||
name = "allow-http-https"
|
||||
network = google_compute_network.my_vpc.id
|
||||
allowed = [
|
||||
{ IPProtocol = "tcp", ports = ["80", "443"] },
|
||||
]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "allow_ssh" {
|
||||
name = "allow-ssh"
|
||||
network = google_compute_network.my_vpc.id
|
||||
allowed = [
|
||||
{ IPProtocol = "tcp", ports = ["22"] },
|
||||
]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "frontend_to_backend" {
|
||||
name = "frontend-to-backend"
|
||||
network = google_compute_network.my_vpc.id
|
||||
allowed = [
|
||||
{ IPProtocol = "tcp", ports = ["8000"] },
|
||||
]
|
||||
source_ranges = [
|
||||
google_compute_subnetwork.frontend.ip_cidr_range
|
||||
]
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "backend_to_database" {
|
||||
name = "backend-to-database"
|
||||
network = google_compute_network.my_vpc.id
|
||||
allowed = [
|
||||
{ IPProtocol = "tcp", ports = ["3306"] },
|
||||
]
|
||||
source_ranges = [
|
||||
google_compute_subnetwork.backend.ip_cidr_range
|
||||
]
|
||||
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" {
|
||||
value = google_compute_network.my_vpc.id
|
||||
description = "ID du VPC créé"
|
||||
}
|
||||
|
||||
output "subnet_ids" {
|
||||
value = {
|
||||
frontend = google_compute_subnetwork.frontend.id
|
||||
backend = google_compute_subnetwork.backend.id
|
||||
database = google_compute_subnetwork.database.id
|
||||
}
|
||||
description = "Map contenant les IDs des sous-réseaux"
|
||||
}
|
30
terraform/modules/network/variables.tf
Normal file
30
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,30 @@
|
||||
# modules/network/variables.tf
|
||||
|
||||
variable "project_name" {
|
||||
description = "Nom du projet Google Cloud"
|
||||
type = string
|
||||
default = "automatisation-tp"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Région Google Cloud"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "frontend_cidr" {
|
||||
description = "Bloc CIDR pour le sous-réseau frontend"
|
||||
type = string
|
||||
default = "10.0.1.0/24"
|
||||
}
|
||||
|
||||
variable "backend_cidr" {
|
||||
description = "Bloc CIDR pour le sous-réseau backend"
|
||||
type = string
|
||||
default = "10.0.2.0/24"
|
||||
}
|
||||
|
||||
variable "database_cidr" {
|
||||
description = "Bloc CIDR pour le sous-réseau database"
|
||||
type = string
|
||||
default = "10.0.3.0/24"
|
||||
}
|
Reference in New Issue
Block a user