tofu fmt, fixes in the readme

This commit is contained in:
Aleksei Krugliak 2024-05-05 14:06:11 +04:00
parent 524c8d217f
commit b19f7f7cbc
3 changed files with 30 additions and 21 deletions

View File

@ -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" project = "gcp-project"
region = "europe-west1" region = "europe-west1"
environment_name = "demo" environment_name = "demo"
``` ```
2. Create cluster 2. Create cluster
``` All commands will be applied via Terraform 1.7.0 and via OpenTofu, the same version.
terraform init
terraform apply 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 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
```
<!-- BEGIN_TF_DOCS --> <!-- BEGIN_TF_DOCS -->
## Requirements ## Requirements

8
gke.tf
View File

@ -9,8 +9,10 @@ resource "google_container_cluster" "primary" {
remove_default_node_pool = true remove_default_node_pool = true
initial_node_count = 1 initial_node_count = 1
network = google_compute_network.vpc.name network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.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" # min_master_version = "1.26.5-gke.1200"
} }
@ -38,4 +40,6 @@ resource "google_container_node_pool" "primary_nodes" {
disable-legacy-endpoints = "true" disable-legacy-endpoints = "true"
} }
} }
depends_on = [google_container_cluster.primary]
} }

View File

@ -20,15 +20,15 @@ output "kubernetes_cluster_host" {
output "gcloud_gke_get_creds" { output "gcloud_gke_get_creds" {
description = "Command to get GKE credentials" 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" { output "gcloud_vpc_link" {
description = "VPC web ui 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" { output "gcloud_gke_link" {
description = "GKE web ui 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}"
} }