This commit is contained in:
gregory hendrickson
2023-03-15 12:10:09 -07:00
parent 2a396b56a4
commit 7e49c86855
2 changed files with 16 additions and 42 deletions

View File

@@ -11,9 +11,13 @@ module "network" {
module "backend" { module "backend" {
source = "./modules/backend" source = "./modules/backend"
startup_script = module.network.startup_script sa_email = "example@project-id.iam.gserviceaccount.com"
image_name = "backend-image"
project_id = var.project_id
region = var.region
} }
module "nat_gateway" { module "nat_gateway" {
source = "./modules/network/nat_gateway" source = "./modules/network/nat_gateway"
network_name = module.network.network_name network_name = module.network.network_name

View File

@@ -1,56 +1,26 @@
terraform { # modules/backend/main.tf
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.5.0"
}
}
}
provider "google" { variable "project_id" {}
project = var.project_id variable "region" {}
region = var.region
module "network" {
source = "../network"
} }
resource "google_compute_instance" "backend" { resource "google_compute_instance" "backend" {
name = "backend" name = "backend"
machine_type = "n1-standard-1" machine_type = "f1-micro"
tags = ["backend"] zone = "${var.region}-b"
boot_disk { boot_disk {
initialize_params { initialize_params {
image = var.image_name image = "debian-cloud/debian-9"
} }
} }
metadata_startup_script = file("${path.module}/startup-script.sh")
network_interface { network_interface {
network = google_compute_network.backend_network.self_link network = module.network.network_name
access_config {
// Allocate a one-to-one NAT IP to allow SSH and HTTP access
}
} }
service_account { metadata_startup_script = module.network.startup_script
email = var.sa_email
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
resource "google_compute_firewall" "backend_firewall" {
name = "allow-backend-internal"
network = google_compute_network.backend_network.self_link
allow {
protocol = "tcp"
ports = ["8081-8082"]
}
source_tags = ["backend"]
target_tags = ["backend"]
}
output "backend_ip" {
value = google_compute_instance.backend.network_interface[0].access_config[0].nat_ip
} }