From 246db63fbca023eebe44f06424f7b8c0cfad5d1d Mon Sep 17 00:00:00 2001 From: Saahil Bhavsar Date: Wed, 22 Nov 2023 06:00:33 +0530 Subject: [PATCH] Inits go module and terraform for kubernetes nodes on GCP --- .gitignore | 37 +++++++++ go.mod | 3 + infra/.terraform.lock.hcl | 21 +++++ infra/main.tf | 167 ++++++++++++++++++++++++++++++++++++++ infra/provider.tf | 7 ++ infra/variables.tf | 9 ++ main.go | 1 + 7 files changed, 245 insertions(+) create mode 100644 go.mod create mode 100644 infra/.terraform.lock.hcl create mode 100644 infra/main.tf create mode 100644 infra/provider.tf create mode 100644 infra/variables.tf create mode 100644 main.go diff --git a/.gitignore b/.gitignore index 3b735ec..da72542 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,40 @@ # Go workspace file go.work + +ssh/ + +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c0e73e9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/XanderWatson/CSL7510-VCC-Project + +go 1.21.0 diff --git a/infra/.terraform.lock.hcl b/infra/.terraform.lock.hcl new file mode 100644 index 0000000..8390b30 --- /dev/null +++ b/infra/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/google" { + version = "5.7.0" + hashes = [ + "h1:27EAcEv0G2mV1ohhDWsz/nx6l15+uOYkPBzJgASXRQo=", + "zh:0c0cf15cc034d5f92cc1cd5ee4615012553a674b69ee1802e46c4b87f1c339aa", + "zh:28e64a798320866c4dc84c323b66eef94ec98043dba016cf01d6adbe2dc85de4", + "zh:3b6e6443a9000354f93682d847737d6e9f702a77c53a492a39b200134b3e8dfd", + "zh:3ed6af130702d9da8fc14f94b3b2c9a93917cda31d50d934dd6de0ca48044572", + "zh:784a0feae2a48aa9a63fe6feb86ad29e8d35647fa29eb42303b799f09ee92060", + "zh:828e0198d99b7f9e53994470d6b51012566660a560da9c8266d1eaf2b140635c", + "zh:8dcb7537d95ec14e75ca71cfce62323682ce0fb453902dc9f890b7c524a915d3", + "zh:a7e760dc5707603091a0c3de0d47d6f8e51d8cce523b5c90587b05f113c5e09c", + "zh:b5c79a5e5b9bcaf0158f5f704d31cf90fb93826085151f06dfc3ef48276ed17a", + "zh:c44a2726dcfbf7d538aa0d5abd2473108f625d1d82485a340e62dfc04043288f", + "zh:f4da66ba04847138949a6a178b8836182f7960e9d069bfe76f1203d9af99cd22", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} diff --git a/infra/main.tf b/infra/main.tf new file mode 100644 index 0000000..7a989dd --- /dev/null +++ b/infra/main.tf @@ -0,0 +1,167 @@ +resource "google_compute_instance" "kubenode1" { + boot_disk { + auto_delete = true + device_name = "instance-1" + + initialize_params { + image = "projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20231030" + size = 50 + type = "pd-balanced" + } + + mode = "READ_WRITE" + } + + can_ip_forward = true + deletion_protection = false + enable_display = false + hostname = "kubenode1.vcc" + + labels = { + goog-ec-src = "vm_add-tf" + } + + machine_type = "e2-medium" + name = "kubenode1" + + network_interface { + access_config { + network_tier = "PREMIUM" + } + + subnetwork = "projects/vcc-course/regions/asia-south2/subnetworks/default" + } + + scheduling { + automatic_restart = true + on_host_maintenance = "MIGRATE" + preemptible = false + provisioning_model = "STANDARD" + } + + service_account { + email = var.gcp_svc_email + scopes = var.gcp_svc_scopes + } + + shielded_instance_config { + enable_integrity_monitoring = true + enable_secure_boot = false + enable_vtpm = true + } + + tags = ["http-server", "https-server", "lb-health-check"] + zone = "asia-south2-a" +} + +resource "google_compute_instance" "kubenode2" { + boot_disk { + auto_delete = true + device_name = "instance-2" + + initialize_params { + image = "projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20231030" + size = 50 + type = "pd-balanced" + } + + mode = "READ_WRITE" + } + + can_ip_forward = true + deletion_protection = false + enable_display = false + hostname = "kubenode2.vcc" + + labels = { + goog-ec-src = "vm_add-tf" + } + + machine_type = "e2-medium" + name = "kubenode2" + + network_interface { + access_config { + network_tier = "PREMIUM" + } + + subnetwork = "projects/vcc-course/regions/us-west1/subnetworks/default" + } + + scheduling { + automatic_restart = true + on_host_maintenance = "MIGRATE" + preemptible = false + provisioning_model = "STANDARD" + } + + service_account { + email = var.gcp_svc_email + scopes = var.gcp_svc_scopes + } + + shielded_instance_config { + enable_integrity_monitoring = true + enable_secure_boot = false + enable_vtpm = true + } + + tags = ["http-server", "https-server", "lb-health-check"] + zone = "us-west1-b" +} + +resource "google_compute_instance" "kubenode3" { + boot_disk { + auto_delete = true + device_name = "instance-3" + + initialize_params { + image = "projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20231030" + size = 50 + type = "pd-balanced" + } + + mode = "READ_WRITE" + } + + can_ip_forward = true + deletion_protection = false + enable_display = false + hostname = "kubenode3.vcc" + + labels = { + goog-ec-src = "vm_add-tf" + } + + machine_type = "e2-medium" + name = "kubenode3" + + network_interface { + access_config { + network_tier = "PREMIUM" + } + + subnetwork = "projects/vcc-course/regions/europe-west9/subnetworks/default" + } + + scheduling { + automatic_restart = true + on_host_maintenance = "MIGRATE" + preemptible = false + provisioning_model = "STANDARD" + } + + service_account { + email = var.gcp_svc_email + scopes = var.gcp_svc_scopes + } + + shielded_instance_config { + enable_integrity_monitoring = true + enable_secure_boot = false + enable_vtpm = true + } + + tags = ["http-server", "https-server", "lb-health-check"] + zone = "europe-west9-a" +} diff --git a/infra/provider.tf b/infra/provider.tf new file mode 100644 index 0000000..43a396d --- /dev/null +++ b/infra/provider.tf @@ -0,0 +1,7 @@ +# GCP Provider + +provider "google" { + credentials = file(var.gcp_svc_key) + project = var.gcp_project + region = var.gcp_region +} diff --git a/infra/variables.tf b/infra/variables.tf new file mode 100644 index 0000000..6b6e823 --- /dev/null +++ b/infra/variables.tf @@ -0,0 +1,9 @@ +variable "gcp_svc_key" {} + +variable "gcp_project" {} + +variable "gcp_region" {} + +variable "gcp_svc_email" {} + +variable "gcp_svc_scopes" {} diff --git a/main.go b/main.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/main.go @@ -0,0 +1 @@ +package main