0
votes

I am looking for terraform code to use sole tenant nodes in GKE cluster.

I found the below reference on Google Cloud Docs, but I am unable to find the code in terraform.

https://cloud.google.com/kubernetes-engine/docs/how-to/sole-tenancy

Here is the snippet of the code I want to convert :

gcloud container node-pools create NODE_POOL_NAME \    
--node-group GROUP_NAME --cluster CLUSTER_NAME \    
--zone COMPUTE_ZONE --machine-type=MACHINE_TYPE \    
--node-locations=COMPUTE_ZONE,COMPUTE_ZONE1
1

1 Answers

1
votes

For GCP sole tenant comes under the node template you can check this out

resource "google_compute_node_template" "template" {
  name      = "soletenant-tmpl"
  region    = "us-central1"
  node_type = "n1-node-96-624"
}

now adding the template to the node group

resource "google_compute_node_template" "soletenant-tmpl" {
  name      = "soletenant-tmpl"
  region    = "us-central1"
  node_type = "n1-node-96-624"
}

resource "google_compute_node_group" "nodes" {
  name        = "soletenant-group"
  zone        = "us-central1-a"
  description = "example google_compute_node_group for Terraform Google Provider"
  maintenance_policy = "RESTART_IN_PLACE"
  size          = 1
  node_template = google_compute_node_template.soletenant-tmpl.id
  autoscaling_policy {
    mode      = "ONLY_SCALE_OUT"
    min_nodes = 1
    max_nodes = 10
  }
}

you can check : https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_node_group