mirror of
https://github.com/ghndrx/GSP662.git
synced 2026-02-10 15:04:57 +00:00
commit new all
This commit is contained in:
41
modules/network/main.tf
Normal file
41
modules/network/main.tf
Normal file
@@ -0,0 +1,41 @@
|
||||
# Define VPC
|
||||
resource "google_compute_network" "vpc_network" {
|
||||
name = var.vpc_name
|
||||
project = var.project_id
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Define subnetwork
|
||||
resource "google_compute_subnetwork" "vpc_subnet" {
|
||||
name = var.subnet_name
|
||||
ip_cidr_range = var.subnet_cidr_range
|
||||
region = var.region
|
||||
network = google_compute_network.vpc_network.self_link
|
||||
}
|
||||
|
||||
# Define firewall rule for frontend instances
|
||||
resource "google_compute_firewall" "frontend_firewall" {
|
||||
name = "allow-frontend"
|
||||
network = google_compute_network.vpc_network.self_link
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8080"]
|
||||
}
|
||||
|
||||
target_tags = ["frontend"]
|
||||
}
|
||||
|
||||
# Define firewall rule for backend instances
|
||||
resource "google_compute_firewall" "backend_firewall" {
|
||||
name = "allow-backend"
|
||||
network = google_compute_network.vpc_network.self_link
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8081-8082"]
|
||||
}
|
||||
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
19
modules/network/outputs.tf
Normal file
19
modules/network/outputs.tf
Normal file
@@ -0,0 +1,19 @@
|
||||
output "vpc_network_name" {
|
||||
value = google_compute_network.vpc_network.name
|
||||
}
|
||||
|
||||
output "subnet_name" {
|
||||
value = google_compute_subnetwork.vpc_subnet.name
|
||||
}
|
||||
|
||||
output "subnet_cidr_range" {
|
||||
value = google_compute_subnetwork.vpc_subnet.ip_cidr_range
|
||||
}
|
||||
|
||||
output "frontend_firewall_name" {
|
||||
value = google_compute_firewall.frontend_firewall.name
|
||||
}
|
||||
|
||||
output "backend_firewall_name" {
|
||||
value = google_compute_firewall.backend_firewall.name
|
||||
}
|
||||
23
modules/network/variables.tf
Normal file
23
modules/network/variables.tf
Normal file
@@ -0,0 +1,23 @@
|
||||
variable "project_id" {
|
||||
description = "The ID of the Google Cloud project to deploy resources to."
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "The region where the resources will be created."
|
||||
default = "us-central1"
|
||||
}
|
||||
|
||||
variable "vpc_name" {
|
||||
description = "The name of the VPC network to be created."
|
||||
default = "fancy-store-vpc"
|
||||
}
|
||||
|
||||
variable "subnet_name" {
|
||||
description = "The name of the subnet to be created."
|
||||
default = "fancy-store-subnet"
|
||||
}
|
||||
|
||||
variable "subnet_cidr_range" {
|
||||
description = "The CIDR range of the subnet to be created."
|
||||
default = "10.0.0.0/24"
|
||||
}
|
||||
Reference in New Issue
Block a user