Search⌘ K

Exploring Terraform Variables

Explore how Terraform variables define and manage critical parameters like region, Kubernetes version, and node counts for AWS EKS clusters. Understand the role of default and runtime variable values in creating scalable, customizable infrastructure as code setups.

Viewing variables in Terraform

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

  • 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. For now, we’ll focus on variables and leave the rest for later.

Note: All the configuration files we’ll need are in the file subdirectory. We’ll pull them out one by one and explore what they’re used for.

Let’s look at the definition of variables.tf.

Shell
variable "region" {
type = string
default = "us-east-1"
}
variable "cluster_name" {
type = string
default = "devops-catalog"
}
variable "k8s_version" {
type = string
}
variable "release_version" {
type = string
}
variable "min_node_count" {
type = number
default = 3
}
variable "max_node_count" {
type = number
default = 9
}
variable "machine_type" {
type = string
default = "t2.small"
}
variable "state_bucket" {
type = string
default = "devops-catalog"
}

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

...