commit new all

This commit is contained in:
gregory hendrickson
2023-03-15 11:40:32 -07:00
commit e9964c2141
14 changed files with 441 additions and 0 deletions

41
modules/network/main.tf Normal file
View 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"]
}

View 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
}

View 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"
}