init repo

This commit is contained in:
Gregory
2023-04-12 16:23:57 -07:00
commit 97e995b906
12 changed files with 176 additions and 0 deletions

48
modules/compute/main.tf Normal file
View File

@@ -0,0 +1,48 @@
# Create the first VM in the first zone
resource "google_compute_instance" "vm1" {
name = "vm1"
machine_type = var.instance_type
zone = var.zone[0]
tags = ["allow-ssh","allow-internal"]
boot_disk {
initialize_params {
image = var.image_name
}
}
network_interface {
network = var.network_name
subnetwork = "subnet-1"
access_config {
// Use ephemeral IP address
nat_ip = null
}
}
metadata_startup_script = "apt-get update && apt-get install -y rsync"
}
# Create the second VM in the second zone
resource "google_compute_instance" "vm2" {
name = "vm2"
machine_type = var.instance_type
zone = var.zone[1]
tags = ["allow-ssh","allow-internal"]
boot_disk {
initialize_params {
image = var.image_name
}
}
network_interface {
network = var.network_name
subnetwork = "subnet-2"
access_config {
// Use ephemeral IP address
nat_ip = null
}
}
metadata_startup_script = "apt-get update && apt-get install -y rsync"
}

View File

@@ -0,0 +1,7 @@
output "vm1_ip" {
value = google_compute_instance.vm1.network_interface[*].access_config[*].nat_ip
}
output "vm2_ip" {
value = google_compute_instance.vm2.network_interface[*].access_config[*].nat_ip
}

View File

@@ -0,0 +1,7 @@
variable "image_name" {}
variable "instance_type" {}
variable "zone" {}
variable "project_id" {}
variable "region" {}
variable "network_name" {}
variable "subnets_cidr_list" {}

31
modules/firewall/main.tf Normal file
View File

@@ -0,0 +1,31 @@
resource "google_compute_firewall" "allow_internal" {
name = "allow-internal"
network = var.network_name
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["0-65535"]
}
allow {
protocol = "udp"
ports = ["0-65535"]
}
target_tags = ["allow-internal"]
}
resource "google_compute_firewall" "allow-ssh" {
name = "allow-ssh"
network = var.network_name
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "tcp"
ports = ["22"]
}
target_tags = ["allow-ssh"]
}

View File

View File

@@ -0,0 +1 @@
variable "network_name" {}

7
modules/vpc/outputs.tf Normal file
View File

@@ -0,0 +1,7 @@
output "vpc_network_name" {
value = google_compute_network.vpc_network.name
}
output "vpc_subnets" {
value = google_compute_subnetwork.vpc_subnets.*.self_link
}

15
modules/vpc/variables.tf Normal file
View File

@@ -0,0 +1,15 @@
variable "network_name" {
type = string
description = "Name of the VPC network to create"
}
variable "subnets_cidr_list" {
type = list(string)
default = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24", "10.0.4.0/24"]
description = "List of CIDR blocks for the subnets to create within the VPC network"
}
variable "region" {
type = string
description = "Region where the VPC subnets will be created"
}