Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 4 #12

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
variable "vpc_count" {}
provider "google" {
project = var.project_name
region = var.region
Expand All @@ -11,34 +10,65 @@ resource "random_string" "vpc_suffix" {
special = false
}

resource "google_compute_network" "private_vpc_assn3" {
count = var.vpc_count
name = var.vpc_name[count.index]
resource "google_compute_network" "private_vpc" {
name = var.vpc_name
auto_create_subnetworks = var.auto_create_subnets
routing_mode = var.routing_mode_RGL
delete_default_routes_on_create = var.delete_default_route
}

resource "google_compute_subnetwork" "webapp_subnet" {
count = var.vpc_count
name = "webapp-${count.index + 1}"
name = var.webapp_subnet
ip_cidr_range = var.ip_cidr_range_webapp
network = google_compute_network.private_vpc_assn3[count.index].id
network = google_compute_network.private_vpc.id
region = var.region
}

resource "google_compute_subnetwork" "db_subnet" {
count = var.vpc_count
name = "db-${count.index + 1}"
name = var.db_subnet
ip_cidr_range = var.ip_cidr_range_db
network = google_compute_network.private_vpc_assn3[count.index].id
network = google_compute_network.private_vpc.id
region = var.region
}

resource "google_compute_route" "webapp_subnet_route" {
count = var.vpc_count
name = "webapp-route-${count.index + 1}"
network = google_compute_network.private_vpc_assn3[count.index].id
name = var.webapp_subnet_route
network = google_compute_network.private_vpc.id
dest_range = var.webapp_destination
next_hop_gateway = var.next_hop_gateway
}
}

resource "google_compute_firewall" "private_vpc_firewall" {
name = var.webapp_firewall_name
network = google_compute_network.private_vpc.name

allow {
protocol = var.webapp_firewall_protocol
ports = var.webapp_firewall_protocol_ports
}
source_tags = var.webapp_firewall_source_tags
target_tags = var.webapp_firewall_target_tags
}

resource "google_compute_instance" "webapp_instance" {
name = var.webapp_instance_name
machine_type = var.webapp_instance_type
zone = var.zone

tags = var.webapp_instance_tags
boot_disk {
initialize_params {
image = var.webapp_instance_image
size = var.webapp_instance_size
type = var.webapp_instance_bootdisk_type
}
}

network_interface {
network = google_compute_network.private_vpc.name
subnetwork = google_compute_subnetwork.webapp_subnet.name
access_config {
network_tier = var.webapp_instance_networktier
}
}
}
53 changes: 53 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ variable "region" {
description = "Google cloud region"
}

variable "zone" {
type = string
}

variable "routing_mode_RGL" {
type = string
description = "routing_mode_RGL"
Expand Down Expand Up @@ -62,5 +66,54 @@ variable "next_hop_gateway" {
}

variable "vpc_name" {
type = string
}

variable "webapp_instance_name" {
type = string
}

variable "webapp_instance_type" {
type = string
}

variable "webapp_instance_tags" {
type = list(string)
}

variable "webapp_instance_image" {
type = string
}

variable "webapp_instance_size" {
type = number
}

variable "webapp_instance_bootdisk_type" {
type = string
}

variable "webapp_instance_networktier" {
type = string
}

variable "webapp_firewall_name" {
type = string
}

variable "webapp_firewall_protocol" {
type = string
}

variable "webapp_firewall_protocol_ports" {
type = list(string)
}

variable "webapp_firewall_target_tags" {
type = list(string)
}

variable "webapp_firewall_source_tags" {
type = list(string)

}
Loading