IAM
This commit is contained in:
78
terraform/modules/network/main.tf
Normal file
78
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,78 @@
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "net1"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Sous-réseau
|
||||
resource "google_compute_subnetwork" "subnet1" {
|
||||
name = "frontend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.frontend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "subnet2" {
|
||||
name = "backend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.backend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "subnet3" {
|
||||
name = "database"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.database_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "allow_http" {
|
||||
name = "rule-http"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["80", "443"]
|
||||
}
|
||||
|
||||
source_ranges = ["0.0.0.0/0"]
|
||||
target_tags = ["web"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "allow_ssh" {
|
||||
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" "front_to_back" {
|
||||
name = "front-to-back"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_tags = ["web"]
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "back_to_bdd" {
|
||||
name = "back-to-bdd"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_tags = ["backend"]
|
||||
target_tags = ["database"]
|
||||
}
|
11
terraform/modules/network/outputs.tf
Normal file
11
terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,11 @@
|
||||
output "vpc"{
|
||||
value = google_compute_network.vpc.id
|
||||
}
|
||||
|
||||
output "subnet" {
|
||||
value = {
|
||||
frontend = google_compute_subnetwork.subnet1.id,
|
||||
backend = google_compute_subnetwork.subnet2.id,
|
||||
database = google_compute_subnetwork.subnet3.id
|
||||
}
|
||||
}
|
30
terraform/modules/network/variables.tf
Normal file
30
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,30 @@
|
||||
variable "project_name" {
|
||||
description = "nom_du_projet"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "emplacement"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "frontend_cidr" {
|
||||
description = "addr_front"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "backend_cidr" {
|
||||
description = "addr_back"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "database_cidr" {
|
||||
description = "addr_bdd"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_source_ranges" {
|
||||
description = "addr_ssh"
|
||||
type = string
|
||||
}
|
||||
|
Reference in New Issue
Block a user