From 1e52dc49d9d56173a90f715d1fee8bf972dd7a79 Mon Sep 17 00:00:00 2001 From: sjh Date: Thu, 28 Dec 2023 04:04:46 +0000 Subject: [PATCH 01/19] Added remote backend --- .terraform.lock.hcl | 59 ++++++++++++++++++++++++++++++++++++++++ remote_backend.tf | 9 ++++++ terraform.tfvars.example | 5 ---- 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 .terraform.lock.hcl create mode 100644 remote_backend.tf delete mode 100644 terraform.tfvars.example diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 00000000..25c3ad0b --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,59 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/google" { + version = "3.68.0" + constraints = "3.68.0" + hashes = [ + "h1:bkeUlWc289dNsjFID2c1MyyuzPJVl9DY4Q5OET5m5EY=", + "zh:1cc538c8aebbf90bf25a667ddce50f9b06ffd8aaa0910e593e9bda7ad4554a6e", + "zh:2db9ac90c377b3bf131cffe93b15b2376a919cfd96464bdf22f67e42534103c8", + "zh:2fd7ada3adeec07aea071a859a34d02a15ecac872ebaadfa320cf308559e6f5f", + "zh:61dd1dcad202508936da07a8810a99c0baafd052e630aff975036e86e3078537", + "zh:84cc28abfabc76d830f187ed3e66957950fd330e3de6f3b8a85bb099d743d7d2", + "zh:9aa9eb2544cd1b763a3e4cf143c1b630f5126fdd9193e9c10eee79d328a0d574", + "zh:abba9c4cad0d02eb434970f37d0eab6722cb81c84de14f2682366cf20125ba5d", + "zh:b94a148a7da8432e75af53c19f61f169859d9d8c5204497779930e825ba76ba8", + "zh:cba5276db512f16aaa90925d60010c434027083067ab0dd9a477f03442b65d66", + "zh:cc5a7109b12d065082c0bf19053afa33d03919c3fd701d77e809522fb4df9291", + "zh:ed3b127c255cf3f819c8892ea283bf866c91f6806db0eda9b67b38c092c2b5ce", + ] +} + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.2" + hashes = [ + "h1:zT1ZbegaAYHwQa+QwIFugArWikRJI9dqohj8xb0GY88=", + "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", + "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", + "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", + "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", + "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", + "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", + "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", + "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", + "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", + "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", + ] +} + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.0.5" + hashes = [ + "h1:e4LBdJoZJNOQXPWgOAG0UuPBVhCStu98PieNlqJTmeU=", + "zh:01cfb11cb74654c003f6d4e32bbef8f5969ee2856394a96d127da4949c65153e", + "zh:0472ea1574026aa1e8ca82bb6df2c40cd0478e9336b7a8a64e652119a2fa4f32", + "zh:1a8ddba2b1550c5d02003ea5d6cdda2eef6870ece86c5619f33edd699c9dc14b", + "zh:1e3bb505c000adb12cdf60af5b08f0ed68bc3955b0d4d4a126db5ca4d429eb4a", + "zh:6636401b2463c25e03e68a6b786acf91a311c78444b1dc4f97c539f9f78de22a", + "zh:76858f9d8b460e7b2a338c477671d07286b0d287fd2d2e3214030ae8f61dd56e", + "zh:a13b69fb43cb8746793b3069c4d897bb18f454290b496f19d03c3387d1c9a2dc", + "zh:a90ca81bb9bb509063b736842250ecff0f886a91baae8de65c8430168001dad9", + "zh:c4de401395936e41234f1956ebadbd2ed9f414e6908f27d578614aaa529870d4", + "zh:c657e121af8fde19964482997f0de2d5173217274f6997e16389e7707ed8ece8", + "zh:d68b07a67fbd604c38ec9733069fbf23441436fecf554de6c75c032f82e1ef19", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} diff --git a/remote_backend.tf b/remote_backend.tf new file mode 100644 index 00000000..3730d11e --- /dev/null +++ b/remote_backend.tf @@ -0,0 +1,9 @@ +terraform { + backend "remote" { + hostname = "app.terraform.io" + organization = "sjh" + workspaces { + name = "hashicat-gcp" + } + } +} diff --git a/terraform.tfvars.example b/terraform.tfvars.example deleted file mode 100644 index fb073c66..00000000 --- a/terraform.tfvars.example +++ /dev/null @@ -1,5 +0,0 @@ -# Rename or copy this file to terraform.tfvars -# Prefix must be all lowercase letters, digits, and hyphens. -# Make sure it is at least 5 characters long. - -# prefix = "yourname" From ec623caebcc12e38465dca29ecc0f23dbfcd9cda Mon Sep 17 00:00:00 2001 From: sjh Date: Thu, 28 Dec 2023 04:12:54 +0000 Subject: [PATCH 02/19] test --- files/deploy_app.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/deploy_app.sh b/files/deploy_app.sh index 9115b73f..9b09415d 100644 --- a/files/deploy_app.sh +++ b/files/deploy_app.sh @@ -14,7 +14,7 @@ cat << EOM > /var/www/html/index.html

Meow World!

- Welcome to ${PREFIX}'s app. Replace this text with your own. + Welcome to sjh's app. Replace this text with your own. From 55298f0c71bbbb672d8d190d0386a1b23f1ba989 Mon Sep 17 00:00:00 2001 From: sjh Date: Thu, 28 Dec 2023 04:20:02 +0000 Subject: [PATCH 03/19] Added the first label --- main.tf | 243 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 122 insertions(+), 121 deletions(-) diff --git a/main.tf b/main.tf index ac39299d..8d1347e5 100644 --- a/main.tf +++ b/main.tf @@ -1,121 +1,122 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: Apache-2.0 - -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "=3.68.0" - } - } -} - -provider "google" { - project = var.project - region = var.region -} - -resource "google_compute_network" "hashicat" { - name = "${var.prefix}-vpc-${var.region}" - auto_create_subnetworks = false -} - -resource "google_compute_subnetwork" "hashicat" { - name = "${var.prefix}-subnet" - region = var.region - network = google_compute_network.hashicat.self_link - ip_cidr_range = var.subnet_prefix -} - -resource "google_compute_firewall" "http-server" { - name = "${var.prefix}-default-allow-ssh-http" - network = google_compute_network.hashicat.self_link - - allow { - protocol = "tcp" - ports = ["22", "80"] - } - - // Allow traffic from everywhere to instances with an http-server tag - source_ranges = ["0.0.0.0/0"] - target_tags = ["http-server"] -} - -resource "tls_private_key" "ssh-key" { - algorithm = "ED25519" -} - -resource "google_compute_instance" "hashicat" { - name = "${var.prefix}-hashicat" - zone = "${var.region}-b" - machine_type = var.machine_type - - boot_disk { - initialize_params { - image = "ubuntu-os-cloud/ubuntu-2204-lts" - } - } - - network_interface { - subnetwork = google_compute_subnetwork.hashicat.self_link - access_config { - } - } - - metadata = { - ssh-keys = "ubuntu:${chomp(tls_private_key.ssh-key.public_key_openssh)} terraform" - } - - tags = ["http-server"] - - labels = { - name = "hashicat" - } - -} - -resource "null_resource" "configure-cat-app" { - depends_on = [ - google_compute_instance.hashicat, - ] - - triggers = { - build_number = timestamp() - } - - provisioner "file" { - source = "files/" - destination = "/home/ubuntu/" - - connection { - type = "ssh" - user = "ubuntu" - timeout = "300s" - private_key = tls_private_key.ssh-key.private_key_pem - host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip - } - } - - provisioner "remote-exec" { - inline = [ - "sudo apt -y update", - "sleep 15", - "sudo apt -y update", - "sudo apt -y install apache2", - "sudo systemctl start apache2", - "sudo chown -R ubuntu:ubuntu /var/www/html", - "chmod +x *.sh", - "PLACEHOLDER=${var.placeholder} WIDTH=${var.width} HEIGHT=${var.height} PREFIX=${var.prefix} ./deploy_app.sh", - "sudo apt -y install cowsay", - "cowsay Mooooooooooo!", - ] - - connection { - type = "ssh" - user = "ubuntu" - timeout = "300s" - private_key = tls_private_key.ssh-key.private_key_pem - host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip - } - } -} +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "=3.68.0" + } + } +} + +provider "google" { + project = var.project + region = var.region +} + +resource "google_compute_network" "hashicat" { + name = "${var.prefix}-vpc-${var.region}" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "hashicat" { + name = "${var.prefix}-subnet" + region = var.region + network = google_compute_network.hashicat.self_link + ip_cidr_range = var.subnet_prefix +} + +resource "google_compute_firewall" "http-server" { + name = "${var.prefix}-default-allow-ssh-http" + network = google_compute_network.hashicat.self_link + + allow { + protocol = "tcp" + ports = ["22", "80"] + } + + // Allow traffic from everywhere to instances with an http-server tag + source_ranges = ["0.0.0.0/0"] + target_tags = ["http-server"] +} + +resource "tls_private_key" "ssh-key" { + algorithm = "ED25519" +} + +resource "google_compute_instance" "hashicat" { + name = "${var.prefix}-hashicat" + zone = "${var.region}-b" + machine_type = var.machine_type + + boot_disk { + initialize_params { + image = "ubuntu-os-cloud/ubuntu-2204-lts" + } + } + + network_interface { + subnetwork = google_compute_subnetwork.hashicat.self_link + access_config { + } + } + + metadata = { + ssh-keys = "ubuntu:${chomp(tls_private_key.ssh-key.public_key_openssh)} terraform" + } + + tags = ["http-server"] + + labels = { + name = "hashicat" + department = "devops" + } + +} + +resource "null_resource" "configure-cat-app" { + depends_on = [ + google_compute_instance.hashicat, + ] + + triggers = { + build_number = timestamp() + } + + provisioner "file" { + source = "files/" + destination = "/home/ubuntu/" + + connection { + type = "ssh" + user = "ubuntu" + timeout = "300s" + private_key = tls_private_key.ssh-key.private_key_pem + host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip + } + } + + provisioner "remote-exec" { + inline = [ + "sudo apt -y update", + "sleep 15", + "sudo apt -y update", + "sudo apt -y install apache2", + "sudo systemctl start apache2", + "sudo chown -R ubuntu:ubuntu /var/www/html", + "chmod +x *.sh", + "PLACEHOLDER=${var.placeholder} WIDTH=${var.width} HEIGHT=${var.height} PREFIX=${var.prefix} ./deploy_app.sh", + "sudo apt -y install cowsay", + "cowsay Mooooooooooo!", + ] + + connection { + type = "ssh" + user = "ubuntu" + timeout = "300s" + private_key = tls_private_key.ssh-key.private_key_pem + host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip + } + } +} From 91a2905f5016a02e5bb7ddb472680320c7e9d771 Mon Sep 17 00:00:00 2001 From: sjh Date: Thu, 28 Dec 2023 04:53:42 +0000 Subject: [PATCH 04/19] Added vpc module --- vpc.tf | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 vpc.tf diff --git a/vpc.tf b/vpc.tf new file mode 100644 index 00000000..fff5a996 --- /dev/null +++ b/vpc.tf @@ -0,0 +1,15 @@ +module "network" { + source = "app.terraform.io/sjh/network/google" + version = "3.4.0" + # insert required variables here + + network_name = "sjh" + project_id = "p-ayvahmypy8yp-0" + subnets = [ + { + subnet_name = "gaurav-subnet" + subnet_ip = "10.100.10.0/24" + subnet_region = var.region + } +] +} \ No newline at end of file From 4aed1ea6883fb649a3092cc0153e8697b1c42252 Mon Sep 17 00:00:00 2001 From: sjh Date: Thu, 28 Dec 2023 05:05:14 +0000 Subject: [PATCH 05/19] Added vpc module --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 8d1347e5..21406a40 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ terraform { required_providers { google = { source = "hashicorp/google" - version = "=3.68.0" + # version = "=3.68.0" } } } From 8f04adf0777a7476e7f8bd2ec57867ae8b5ed868 Mon Sep 17 00:00:00 2001 From: sjh Date: Thu, 4 Jan 2024 06:24:50 +0000 Subject: [PATCH 06/19] 230323 --- .terraform.lock.hcl | 59 ++++++++++ main.tf | 242 +++++++++++++++++++-------------------- remote_backend.tf | 9 ++ terraform.tfvars.example | 5 - vpc.tf | 16 +++ 5 files changed, 205 insertions(+), 126 deletions(-) create mode 100644 .terraform.lock.hcl create mode 100644 remote_backend.tf delete mode 100644 terraform.tfvars.example create mode 100644 vpc.tf diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 00000000..25c3ad0b --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,59 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/google" { + version = "3.68.0" + constraints = "3.68.0" + hashes = [ + "h1:bkeUlWc289dNsjFID2c1MyyuzPJVl9DY4Q5OET5m5EY=", + "zh:1cc538c8aebbf90bf25a667ddce50f9b06ffd8aaa0910e593e9bda7ad4554a6e", + "zh:2db9ac90c377b3bf131cffe93b15b2376a919cfd96464bdf22f67e42534103c8", + "zh:2fd7ada3adeec07aea071a859a34d02a15ecac872ebaadfa320cf308559e6f5f", + "zh:61dd1dcad202508936da07a8810a99c0baafd052e630aff975036e86e3078537", + "zh:84cc28abfabc76d830f187ed3e66957950fd330e3de6f3b8a85bb099d743d7d2", + "zh:9aa9eb2544cd1b763a3e4cf143c1b630f5126fdd9193e9c10eee79d328a0d574", + "zh:abba9c4cad0d02eb434970f37d0eab6722cb81c84de14f2682366cf20125ba5d", + "zh:b94a148a7da8432e75af53c19f61f169859d9d8c5204497779930e825ba76ba8", + "zh:cba5276db512f16aaa90925d60010c434027083067ab0dd9a477f03442b65d66", + "zh:cc5a7109b12d065082c0bf19053afa33d03919c3fd701d77e809522fb4df9291", + "zh:ed3b127c255cf3f819c8892ea283bf866c91f6806db0eda9b67b38c092c2b5ce", + ] +} + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.2" + hashes = [ + "h1:zT1ZbegaAYHwQa+QwIFugArWikRJI9dqohj8xb0GY88=", + "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", + "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", + "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", + "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", + "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", + "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", + "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", + "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", + "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", + "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", + ] +} + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.0.5" + hashes = [ + "h1:e4LBdJoZJNOQXPWgOAG0UuPBVhCStu98PieNlqJTmeU=", + "zh:01cfb11cb74654c003f6d4e32bbef8f5969ee2856394a96d127da4949c65153e", + "zh:0472ea1574026aa1e8ca82bb6df2c40cd0478e9336b7a8a64e652119a2fa4f32", + "zh:1a8ddba2b1550c5d02003ea5d6cdda2eef6870ece86c5619f33edd699c9dc14b", + "zh:1e3bb505c000adb12cdf60af5b08f0ed68bc3955b0d4d4a126db5ca4d429eb4a", + "zh:6636401b2463c25e03e68a6b786acf91a311c78444b1dc4f97c539f9f78de22a", + "zh:76858f9d8b460e7b2a338c477671d07286b0d287fd2d2e3214030ae8f61dd56e", + "zh:a13b69fb43cb8746793b3069c4d897bb18f454290b496f19d03c3387d1c9a2dc", + "zh:a90ca81bb9bb509063b736842250ecff0f886a91baae8de65c8430168001dad9", + "zh:c4de401395936e41234f1956ebadbd2ed9f414e6908f27d578614aaa529870d4", + "zh:c657e121af8fde19964482997f0de2d5173217274f6997e16389e7707ed8ece8", + "zh:d68b07a67fbd604c38ec9733069fbf23441436fecf554de6c75c032f82e1ef19", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} diff --git a/main.tf b/main.tf index ac39299d..3673f13f 100644 --- a/main.tf +++ b/main.tf @@ -1,121 +1,121 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: Apache-2.0 - -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "=3.68.0" - } - } -} - -provider "google" { - project = var.project - region = var.region -} - -resource "google_compute_network" "hashicat" { - name = "${var.prefix}-vpc-${var.region}" - auto_create_subnetworks = false -} - -resource "google_compute_subnetwork" "hashicat" { - name = "${var.prefix}-subnet" - region = var.region - network = google_compute_network.hashicat.self_link - ip_cidr_range = var.subnet_prefix -} - -resource "google_compute_firewall" "http-server" { - name = "${var.prefix}-default-allow-ssh-http" - network = google_compute_network.hashicat.self_link - - allow { - protocol = "tcp" - ports = ["22", "80"] - } - - // Allow traffic from everywhere to instances with an http-server tag - source_ranges = ["0.0.0.0/0"] - target_tags = ["http-server"] -} - -resource "tls_private_key" "ssh-key" { - algorithm = "ED25519" -} - -resource "google_compute_instance" "hashicat" { - name = "${var.prefix}-hashicat" - zone = "${var.region}-b" - machine_type = var.machine_type - - boot_disk { - initialize_params { - image = "ubuntu-os-cloud/ubuntu-2204-lts" - } - } - - network_interface { - subnetwork = google_compute_subnetwork.hashicat.self_link - access_config { - } - } - - metadata = { - ssh-keys = "ubuntu:${chomp(tls_private_key.ssh-key.public_key_openssh)} terraform" - } - - tags = ["http-server"] - - labels = { - name = "hashicat" - } - -} - -resource "null_resource" "configure-cat-app" { - depends_on = [ - google_compute_instance.hashicat, - ] - - triggers = { - build_number = timestamp() - } - - provisioner "file" { - source = "files/" - destination = "/home/ubuntu/" - - connection { - type = "ssh" - user = "ubuntu" - timeout = "300s" - private_key = tls_private_key.ssh-key.private_key_pem - host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip - } - } - - provisioner "remote-exec" { - inline = [ - "sudo apt -y update", - "sleep 15", - "sudo apt -y update", - "sudo apt -y install apache2", - "sudo systemctl start apache2", - "sudo chown -R ubuntu:ubuntu /var/www/html", - "chmod +x *.sh", - "PLACEHOLDER=${var.placeholder} WIDTH=${var.width} HEIGHT=${var.height} PREFIX=${var.prefix} ./deploy_app.sh", - "sudo apt -y install cowsay", - "cowsay Mooooooooooo!", - ] - - connection { - type = "ssh" - user = "ubuntu" - timeout = "300s" - private_key = tls_private_key.ssh-key.private_key_pem - host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip - } - } -} +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "=3.68.0" + } + } +} + +provider "google" { + project = var.project + region = var.region +} + +resource "google_compute_network" "hashicat" { + name = "${var.prefix}-vpc-${var.region}" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "hashicat" { + name = "${var.prefix}-subnet" + region = var.region + network = google_compute_network.hashicat.self_link + ip_cidr_range = var.subnet_prefix +} + +resource "google_compute_firewall" "http-server" { + name = "${var.prefix}-default-allow-ssh-http" + network = google_compute_network.hashicat.self_link + + allow { + protocol = "tcp" + ports = ["22", "80"] + } + + // Allow traffic from everywhere to instances with an http-server tag + source_ranges = ["0.0.0.0/0"] + target_tags = ["http-server"] +} + +resource "tls_private_key" "ssh-key" { + algorithm = "ED25519" +} + +resource "google_compute_instance" "hashicat" { + name = "${var.prefix}-hashicat" + zone = "${var.region}-b" + machine_type = var.machine_type + + boot_disk { + initialize_params { + image = "ubuntu-os-cloud/ubuntu-2204-lts" + } + } + + network_interface { + subnetwork = google_compute_subnetwork.hashicat.self_link + access_config { + } + } + + metadata = { + ssh-keys = "ubuntu:${chomp(tls_private_key.ssh-key.public_key_openssh)} terraform" + } + + tags = ["http-server"] + + labels = { + name = "hashicat" + } + +} + +resource "null_resource" "configure-cat-app" { + depends_on = [ + google_compute_instance.hashicat, + ] + + triggers = { + build_number = timestamp() + } + + provisioner "file" { + source = "files/" + destination = "/home/ubuntu/" + + connection { + type = "ssh" + user = "ubuntu" + timeout = "300s" + private_key = tls_private_key.ssh-key.private_key_pem + host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip + } + } + + provisioner "remote-exec" { + inline = [ + "sudo apt -y update", + "sleep 15", + "sudo apt -y update", + "sudo apt -y install apache2", + "sudo systemctl start apache2", + "sudo chown -R ubuntu:ubuntu /var/www/html", + "chmod +x *.sh", + "PLACEHOLDER=${var.placeholder} WIDTH=${var.width} HEIGHT=${var.height} PREFIX=${var.prefix} ./deploy_app.sh", + "sudo apt -y install cowsay", + "cowsay Mooooooooooo!", + ] + + connection { + type = "ssh" + user = "ubuntu" + timeout = "300s" + private_key = tls_private_key.ssh-key.private_key_pem + host = google_compute_instance.hashicat.network_interface.0.access_config.0.nat_ip + } + } +} diff --git a/remote_backend.tf b/remote_backend.tf new file mode 100644 index 00000000..3730d11e --- /dev/null +++ b/remote_backend.tf @@ -0,0 +1,9 @@ +terraform { + backend "remote" { + hostname = "app.terraform.io" + organization = "sjh" + workspaces { + name = "hashicat-gcp" + } + } +} diff --git a/terraform.tfvars.example b/terraform.tfvars.example deleted file mode 100644 index fb073c66..00000000 --- a/terraform.tfvars.example +++ /dev/null @@ -1,5 +0,0 @@ -# Rename or copy this file to terraform.tfvars -# Prefix must be all lowercase letters, digits, and hyphens. -# Make sure it is at least 5 characters long. - -# prefix = "yourname" diff --git a/vpc.tf b/vpc.tf new file mode 100644 index 00000000..3be00246 --- /dev/null +++ b/vpc.tf @@ -0,0 +1,16 @@ +module "network" { + source = "app.terraform.io/sjh/network/google" + version = "3.4.0" + # insert required variables here + network_name = "sjh" + project_id = "p-gti8ayw9nnlr-0" + subnets = [ + { + subnet_name = "gaurav-subnet" + subnet_ip = "10.100.10.0/24" + subnet_region = var.region + } + ] + +} + From eb1285772d86d0e95e0c0f5a62880dd6f9d0d5b8 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:30:53 +0900 Subject: [PATCH 07/19] Update main.tf --- main.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.tf b/main.tf index d6733168..06ffdb1b 100644 --- a/main.tf +++ b/main.tf @@ -5,11 +5,7 @@ terraform { required_providers { google = { source = "hashicorp/google" -<<<<<<< HEAD version = "=3.68.0" -======= - # version = "=3.68.0" ->>>>>>> 4aed1ea6883fb649a3092cc0153e8697b1c42252 } } } From c9f5c9052448d121b5092699fc59e84663e36f67 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:31:41 +0900 Subject: [PATCH 08/19] Update vpc.tf --- vpc.tf | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/vpc.tf b/vpc.tf index 7446619d..cc364aac 100644 --- a/vpc.tf +++ b/vpc.tf @@ -2,26 +2,15 @@ module "network" { source = "app.terraform.io/sjh/network/google" version = "3.4.0" # insert required variables here -<<<<<<< HEAD - network_name = "sjh" - project_id = "p-gti8ayw9nnlr-0" -======= network_name = "sjh" - project_id = "p-ayvahmypy8yp-0" ->>>>>>> 4aed1ea6883fb649a3092cc0153e8697b1c42252 + project_id = "p-gti8ayw9nnlr-0" subnets = [ { subnet_name = "gaurav-subnet" subnet_ip = "10.100.10.0/24" subnet_region = var.region } -<<<<<<< HEAD ] } - -======= -] -} ->>>>>>> 4aed1ea6883fb649a3092cc0153e8697b1c42252 From d2bebdd8a9e0ba16a385f040e68751ae8176b8bb Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:39:19 +0900 Subject: [PATCH 09/19] Update main.tf --- main.tf | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.tf b/main.tf index 06ffdb1b..8d1347e5 100644 --- a/main.tf +++ b/main.tf @@ -70,10 +70,7 @@ resource "google_compute_instance" "hashicat" { labels = { name = "hashicat" -<<<<<<< HEAD -======= department = "devops" ->>>>>>> 4aed1ea6883fb649a3092cc0153e8697b1c42252 } } From 8a799bf5b0aa141f80fefb3f2d35fa9227da6e57 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:39:59 +0900 Subject: [PATCH 10/19] Update main.tf --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 8d1347e5..569f19e8 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ terraform { required_providers { google = { source = "hashicorp/google" - version = "=3.68.0" + #version = "=3.68.0" } } } From 3943c0596b677315315addeb1f81b54fa2892325 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:42:09 +0900 Subject: [PATCH 11/19] Update main.tf --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index 569f19e8..e540669c 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,6 @@ terraform { required_providers { google = { source = "hashicorp/google" - #version = "=3.68.0" } } } From 1a8cbd58c56334d8603eb0aad0ece9816d0ab225 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:50:16 +0900 Subject: [PATCH 12/19] Update vpc.tf --- vpc.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpc.tf b/vpc.tf index cc364aac..398f00e4 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ module "network" { source = "app.terraform.io/sjh/network/google" - version = "3.4.0" + # version = "3.4.0" # insert required variables here network_name = "sjh" From 0a7b626fa6f05bc28779ee0a32465c2748d8c26f Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:53:44 +0900 Subject: [PATCH 13/19] Update vpc.tf --- vpc.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpc.tf b/vpc.tf index 398f00e4..09c30ff6 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ module "network" { source = "app.terraform.io/sjh/network/google" - # version = "3.4.0" + # version = "3.4.1" # insert required variables here network_name = "sjh" From d30ea12fb8485a50a94fdb67e0b7a8fb3f09504f Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:58:13 +0900 Subject: [PATCH 14/19] Update vpc.tf --- vpc.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vpc.tf b/vpc.tf index 09c30ff6..dd6ab861 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ module "network" { - source = "app.terraform.io/sjh/network/google" - # version = "3.4.1" + source = "terraform-google-modules/network/google" + version = "6.0.0" # insert required variables here network_name = "sjh" From e3f319eaf9b7f50dcd3d4d922f052a430e2e8280 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:59:26 +0900 Subject: [PATCH 15/19] Update vpc.tf --- vpc.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpc.tf b/vpc.tf index dd6ab861..45cdfed0 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ module "network" { source = "terraform-google-modules/network/google" - version = "6.0.0" + version = "4.1.0" # insert required variables here network_name = "sjh" From 65fd8f6d8408c87ee53fb9ebb6545b983f89c276 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:00:57 +0900 Subject: [PATCH 16/19] Update vpc.tf --- vpc.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpc.tf b/vpc.tf index 45cdfed0..dd6ab861 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ module "network" { source = "terraform-google-modules/network/google" - version = "4.1.0" + version = "6.0.0" # insert required variables here network_name = "sjh" From c1c21e19b7e4053ae5b9213b65932a9d553fa491 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:04:14 +0900 Subject: [PATCH 17/19] Update vpc.tf --- vpc.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vpc.tf b/vpc.tf index dd6ab861..519f744f 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,4 +1,4 @@ -module "network" { +/* module "network" { source = "terraform-google-modules/network/google" version = "6.0.0" # insert required variables here @@ -14,3 +14,4 @@ module "network" { ] } +*/ From 0a5a7a48cb4c259454716c7ebae1dea112854115 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:04:59 +0900 Subject: [PATCH 18/19] Update vpc.tf --- vpc.tf | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vpc.tf b/vpc.tf index 519f744f..e600b4b7 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ -/* module "network" { + module "network" { source = "terraform-google-modules/network/google" - version = "6.0.0" + version = "8.1.0" # insert required variables here network_name = "sjh" @@ -14,4 +14,3 @@ ] } -*/ From f5dbf02049318322dad69a19c8446ff6fd37ee12 Mon Sep 17 00:00:00 2001 From: jhsong <68138881+caffeinelove@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:07:50 +0900 Subject: [PATCH 19/19] Update vpc.tf --- vpc.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpc.tf b/vpc.tf index e600b4b7..1d948e03 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,6 +1,6 @@ module "network" { source = "terraform-google-modules/network/google" - version = "8.1.0" + version = "3.4.0" # insert required variables here network_name = "sjh"