forked from pierront/but3-iac
.
This commit is contained in:
@@ -1,104 +1,87 @@
|
||||
# # VPC
|
||||
# resource "google_compute_network" "vpc" {
|
||||
# name = "mon-vpc"
|
||||
# auto_create_subnetworks = false
|
||||
# }
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "mon-vpc"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# # Sous-réseau
|
||||
# resource "google_compute_subnetwork" "subnet" {
|
||||
# name = "mon-subnet"
|
||||
# network = google_compute_network.vpc.id
|
||||
# ip_cidr_range = "10.0.1.0/24"
|
||||
# region = "europe-west1"
|
||||
# }
|
||||
|
||||
resource "google_compute_subnetwork" "frontend" {
|
||||
# Sous-réseau
|
||||
resource "google_compute_subnetwork" "frontend_network" {
|
||||
name = "mon-frontend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.frontend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "backend" {
|
||||
resource "google_compute_subnetwork" "backend_network" {
|
||||
name = "mon-backend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.backend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "database" {
|
||||
name = "ma-database"
|
||||
resource "google_compute_subnetwork" "database_network" {
|
||||
name = "mon-database"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.database_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
# resource "google_compute_firewall" "allow_http" {
|
||||
# name = "allow-http"
|
||||
# network = google_compute_network.vpc.id
|
||||
resource "google_compute_firewall" "ssh_firewall" {
|
||||
name = "mon-ssh"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
# allow {
|
||||
# protocol = "tcp"
|
||||
# ports = ["80", "443"]
|
||||
# }
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["22"]
|
||||
}
|
||||
|
||||
source_ranges = ["0.0.0.0/0"]
|
||||
target_tags = ["ssh"]
|
||||
|
||||
}
|
||||
|
||||
# source_ranges = ["0.0.0.0/0"]
|
||||
# target_tags = ["web"]
|
||||
# }
|
||||
|
||||
resource "google_compute_firewall" "frontend_firewall" {
|
||||
name = "frontend"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["80", "443"]
|
||||
}
|
||||
|
||||
source_ranges = ["0.0.0.0/0"]
|
||||
target_tags = ["frontend"]
|
||||
target_tags = ["frontend"]
|
||||
|
||||
}
|
||||
|
||||
|
||||
resource "google_compute_firewall" "backend_firewall" {
|
||||
name = "backend"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_tags = ["frontend"]
|
||||
target_tags = ["backend"]
|
||||
target_tags = ["backend"]
|
||||
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "database_firewall" {
|
||||
name = "database"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["3306"]
|
||||
}
|
||||
|
||||
source_tags = ["backend"]
|
||||
target_tags = ["database"]
|
||||
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"]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
# output "instance_ip" {
|
||||
# value = google_compute_instance.main.network_interface[0].access_config[0].nat_ip
|
||||
# }
|
||||
|
||||
output "vpc_terraform" {
|
||||
description = "ID du VPC créé"
|
||||
value = google_compute_network.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
|
||||
frontend = google_compute_subnetwork.frontend_network.id
|
||||
backend = google_compute_subnetwork.backend_network.id
|
||||
database = google_compute_subnetwork.database_network.id
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
# variable "project_id" {
|
||||
# description = "ID du projet GCP"
|
||||
# type = string
|
||||
# default = "mon-projet"
|
||||
# }
|
||||
|
||||
variable "project_name" {
|
||||
description = "Nom du projet cidr"
|
||||
type = string
|
||||
description = "but3-iac"
|
||||
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "region du cidr"
|
||||
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" {
|
||||
description = "ssh_source_range du projet cidr"
|
||||
description = "Plages d’adresses autorisées à se connecter en SSH"
|
||||
type = string
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user