forked from pierront/but3-iac
maj
This commit is contained in:
85
terraform/modules/network/main.tf
Normal file
85
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,85 @@
|
||||
# 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 = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.frontend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "backend" {
|
||||
name = "mon-backend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.backend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "database" {
|
||||
name = "mon-database"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.database_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
# Pare-Feu
|
||||
|
||||
|
||||
resource "google_compute_firewall" "frontend_http" {
|
||||
name = "frontend-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" "ssh" {
|
||||
name = "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" "front_back" {
|
||||
name = "front_back"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_ranges = ["frontend"]
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "back_data" {
|
||||
name = "back_data"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["3306"]
|
||||
}
|
||||
|
||||
source_ranges = ["backend"]
|
||||
target_tags = ["database"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user