From b19f7f7cbc4b25823e654366e6917febf0d1d0f7 Mon Sep 17 00:00:00 2001 From: Aleksei Krugliak Date: Sun, 5 May 2024 14:06:11 +0400 Subject: [PATCH] tofu fmt, fixes in the readme --- README.md | 37 +++++++++++++++++++++---------------- gke.tf | 8 ++++++-- outputs.tf | 6 +++--- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 7973aa4..b18794f 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,38 @@ -# How to use +# How to use repo -1. Create *.tfvars file with a few variables -``` +1. Create `terraform.tfvars` file with a few variables +```bash project = "gcp-project" region = "europe-west1" environment_name = "demo" ``` 2. Create cluster -``` -terraform init -terraform apply +All commands will be applied via Terraform 1.7.0 and via OpenTofu, the same version. + +Here are OpenTofu commands. +```bash +tofu init +tofu apply ``` -3. Configure kubeconfig for new cluster +3. Get the credentials for the new cluster (configure kubeconfig) + +You can see all useful commands and links in the output: +```bash +tofu output ``` -gcloud container clusters get-credentials $(terraform output -raw kubernetes_cluster_name) --region $(terraform output -raw region) --project $(terraform output -raw project) + +There is a manual command: +```bash +gcloud container clusters get-credentials $(tofu output -raw kubernetes_cluster_name) --region $(tofu output -raw region) --project $(tofu output -raw project) ``` 4. Destroy all resources -``` -terraform destroy -target 'kubernetes_namespace.flux-system' -terraform destroy -target 'google_container_node_pool.primary_nodes' -terraform destroy -target 'google_container_cluster.primary' -terraform destroy -target 'google_compute_subnetwork.subnet' -terraform destroy -target 'google_compute_network.vpc' -terraform destroy -target 'data.google_client_config.primary' -``` +```bash +tofu destroy +``` ## Requirements diff --git a/gke.tf b/gke.tf index 663cb13..5d5ec2e 100644 --- a/gke.tf +++ b/gke.tf @@ -9,8 +9,10 @@ resource "google_container_cluster" "primary" { remove_default_node_pool = true initial_node_count = 1 - network = google_compute_network.vpc.name - subnetwork = google_compute_subnetwork.subnet.name + network = google_compute_network.vpc.name + subnetwork = google_compute_subnetwork.subnet.name + deletion_protection = false # Use this only for study purposess + depends_on = [google_compute_network.vpc, google_compute_subnetwork.subnet] # min_master_version = "1.26.5-gke.1200" } @@ -38,4 +40,6 @@ resource "google_container_node_pool" "primary_nodes" { disable-legacy-endpoints = "true" } } + + depends_on = [google_container_cluster.primary] } diff --git a/outputs.tf b/outputs.tf index 62f6dd4..1b0f5a4 100644 --- a/outputs.tf +++ b/outputs.tf @@ -20,15 +20,15 @@ output "kubernetes_cluster_host" { output "gcloud_gke_get_creds" { description = "Command to get GKE credentials" - value = "gcloud container clusters get-credentials ${google_container_cluster.primary.name} --region ${var.region} --project ${var.project}" + value = "gcloud container clusters get-credentials ${google_container_cluster.primary.name} --region ${var.region} --project ${var.project}" } output "gcloud_vpc_link" { description = "VPC web ui link" - value = "https://console.cloud.google.com/networking/networks/list?project=${var.project}" + value = "https://console.cloud.google.com/networking/networks/list?project=${var.project}" } output "gcloud_gke_link" { description = "GKE web ui link" - value = "https://console.cloud.google.com/kubernetes/clusters/details/${var.region}/${var.project}-gke/details?project=${var.project}" + value = "https://console.cloud.google.com/kubernetes/clusters/details/${var.region}/${var.project}-gke/details?project=${var.project}" }