Unexpected attribute: An attribute named "max_node_count" is not expected here

Hi there,

Even though it’s possible to define maximum node count through variables, I get the error outlined above and when I remove them, it works perfectly.

main.tf file

# Define variables for cluster configuration (unchanged)

# Define the main GKE cluster (unchanged)
resource "google_container_cluster" "gke_cluster" {
  name  = var.cluster_name
  location = var.location
  initial_node_count = var.initial_node_count
}

# Define a separate node pool with desired machine type and maximum count
resource "google_container_node_pool" "high_mem_pool" {
  name      = "high-mem-pool"
  cluster   = google_container_cluster.gke_cluster.name
  node_count = var.initial_node_count  # Initial node count (can be adjusted)
  max_node_count = var.maximum_node_count  # Use the defined variable

  # Set machine type with more memory for memory-intensive workloads
  node_config {
    machine_type = "e2-standard-8"
  }
}

variables.tf

# Define variables for cluster configuration (variable block)
variable "cluster_name" {
 default = "gke-terraform"
}

variable "location" {
 default = "us-central1"
}

variable "initial_node_count" {
 default = 1
}

variable "maximum_node_count" {
  default = 3
}

providers.tf

provider "google" {
  project     = "project-id" #change project id to suit your project
  region      = "us-central1"
}

I don’t know why I get the error and when I extensively looked at the problem, I looked at documentation and other resources extensively but couldn’t find an answer.

Hi @Killpit,

You may get some further answers from those familiar with the GCP provider if you post this to the Terraform Providers category.

However - The documentation google_container_node_pool | Resources | hashicorp/google | Terraform | Terraform Registry does confirm that there is not a max_node_count argument at the top level of a google_container_node_pool as you have it here. Which is why you are getting the error, as that attribute is not expected.

Perhaps what you need is the autoscaling block within the resource which does have a max_node_count

So your resource block would look more like this:

resource "google_container_node_pool" "high_mem_pool" {
  name      = "high-mem-pool"
  cluster   = google_container_cluster.gke_cluster.name
  node_count = var.initial_node_count  # Initial node count (can be adjusted)
  
  autoscaling {
     max_node_count = var.maximum_node_count  # Use the defined variable
  }
  # Set machine type with more memory for memory-intensive workloads
  node_config {
    machine_type = "e2-standard-8"
  }
}

I am not familiar with the GCP provider, so, while the above is based upon the documentation, you may need some further attributes in that block depending upon the combination that the provider is expecting.

Hope that helps

Happy Terraforming

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.