GKE w/ Terraform - set autoscaling_profile

Viewed 1026

I have scale down issue on my GKE cluster and found out with the right configuration I can solve this.

As the terraform documentation I can use the arguement autoscaling_profile and set it to OPTIMIZE_UTILIZATION

Like so :

resource "google_container_cluster" "k8s_cluster" {
  
[...]
  
  cluster_autoscaling {
    enabled = true
    autoscaling_profile = "OPTIMIZE_UTILIZATION"
    resource_limits {
      resource_type = "cpu"
      minimum = 1
      maximum = 4
    }
    resource_limits {
      resource_type = "memory"
      minimum = 4
      maximum = 16
    }
  }
}

But I got this error :

Error: Unsupported argument on modules/gke/main.tf line 70, in resource "google_container_cluster" "k8s_cluster": 70: autoscaling_profile = "OPTIMIZE_UTILIZATION"

An argument named "autoscaling_profile" is not expected here.

I don't get it ?

1 Answers

TL;DR

Add below parameter to the definition of your resource (at the top):

  • provider = google-beta

More explanation:

autoscaling_profile as shown in the documentation is a beta feature. This means that it will need to use different provider: google-beta.

You can read more about it by following official documentation:

Focusing on most important parts from above docs:

How to use it:

To use the google-beta provider, simply set the provider field on each resource where you want to use google-beta.

resource "google_compute_instance" "beta-instance" {
 provider = google-beta
 # ...
}

Disclaimer about usage of google and google-beta:

If the provider field is omitted, Terraform will implicitly use the google provider by default even if you have only defined a google-beta provider block.


Adding to the whole explanation your GKE cluster definition should look like this:

resource "google_container_cluster" "k8s_cluster" {
  
[...]

  provider = google-beta # <- HERE IT IS
  
  cluster_autoscaling {
    enabled = true
    autoscaling_profile = "OPTIMIZE_UTILIZATION"
    resource_limits {
      resource_type = "cpu"
      minimum = 1
      maximum = 4
    }
    resource_limits {
      resource_type = "memory"
      minimum = 4
      maximum = 16
    }
  }
}

You will also need to run:

  • $ terraform init
Related