tp_cloud/terraform/modules/network/main.tf

69 lines
1.9 KiB
Terraform
Raw Normal View History

2024-12-04 17:28:21 +01:00
#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"]
}