Search⌘ K
AI Features

Exploring Terraform Variables

Explore the role of Terraform variables in defining and managing Google Kubernetes Engine clusters. Understand how variables with and without default values control cluster parameters like region, Kubernetes version, and node scalability, helping you build adaptive infrastructure as code.

Viewing variables in Terraform

Generally speaking, entries in Terraform definitions are split into four groups. We have:

  • Provider
  • Resource
  • Output
  • Variable

That’s not to say that there aren’t other types (there are) but those four are the most important and the most commonly used ones. For now, we’ll focus on variables and leave the rest for later.

Let’s take a quick look at the file that defines the variables that we’ll use.

Output description

Shell
variable "region" {
type = string
default = "us-east1"
}
variable "project_id" {
type = string
default = "devops-catalog-gke"
}
variable "cluster_name" {
type = string
default = "devops-catalog"
}
variable "k8s_version" {
type = string
}
variable "min_node_count" {
type = number
default = 1
}
variable "max_node_count" {
type = number
default = 3
}
variable "machine_type" {
type = string
default = "e2-standard-2"
}
variable "preemptible" {
type = bool
default = true
}
variable "state_bucket" {
type = string
}

If we focus on the names of the variables, we’ll notice that they’re self-explanatory:

  • In line 1
...