Skip to content

Commit

Permalink
feat: Added support for specifying autoscaling_profile in var.cluster…
Browse files Browse the repository at this point in the history
…_autoscaling (terraform-google-modules#456)

* add autoscaling_profile

* default to balanced if autoscaling_profile is null

* default to balanced if autoscaling_profile is null
  • Loading branch information
bharathkkb committed Mar 27, 2020
1 parent c039e67 commit b1cb123
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 70 deletions.
3 changes: 2 additions & 1 deletion autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ resource "google_container_cluster" "primary" {

{% if beta_cluster %}
cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
Expand Down
22 changes: 12 additions & 10 deletions autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,20 @@ variable "enable_kubernetes_alpha" {

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
enabled = bool
autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
enabled = false
autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.3.0"
version = "~> 3.12.0"
region = var.region
}

Expand Down
22 changes: 12 additions & 10 deletions examples/node_pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ variable "compute_engine_service_account" {

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
enabled = bool
autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
enabled = false
autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
2 changes: 1 addition & 1 deletion examples/node_pool_update_variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google" {
version = "~> 3.3.0"
version = "~> 3.12.0"
region = var.region
}

Expand Down
2 changes: 1 addition & 1 deletion examples/node_pool_update_variant_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.3.0"
version = "~> 3.12.0"
credentials = file(var.credentials_path)
region = var.region
}
Expand Down
4 changes: 2 additions & 2 deletions examples/safer_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ locals {
}

provider "google" {
version = "~> 3.3.0"
version = "~> 3.12.0"
}

provider "google-beta" {
version = "~> 3.3.0"
version = "~> 3.12.0"
}

module "gke" {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_regional_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.3.0"
version = "~> 3.12.0"
region = var.region
}

Expand Down
4 changes: 2 additions & 2 deletions examples/simple_regional_private_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ locals {
}

provider "google" {
version = "~> 3.3.0"
version = "~> 3.12.0"
region = var.region
}

provider "google-beta" {
version = "~> 3.3.0"
version = "~> 3.12.0"
region = var.region
}

Expand Down
2 changes: 1 addition & 1 deletion examples/workload_identity/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google" {
version = "~> 2.20.1"
version = "~> 3.12.0"
region = var.region
}

Expand Down
2 changes: 1 addition & 1 deletion examples/workload_metadata_config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

provider "google-beta" {
version = "~> 3.3.0"
version = "~> 3.12.0"
region = var.region
}

Expand Down
3 changes: 2 additions & 1 deletion modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ resource "google_container_cluster" "primary" {
monitoring_service = var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
Expand Down
22 changes: 12 additions & 10 deletions modules/beta-private-cluster-update-variant/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,20 @@ variable "enable_kubernetes_alpha" {

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
enabled = bool
autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
enabled = false
autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ resource "google_container_cluster" "primary" {
monitoring_service = var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
Expand Down
22 changes: 12 additions & 10 deletions modules/beta-private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,20 @@ variable "enable_kubernetes_alpha" {

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
enabled = bool
autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
enabled = false
autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ resource "google_container_cluster" "primary" {
monitoring_service = var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
Expand Down
22 changes: 12 additions & 10 deletions modules/beta-public-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,20 @@ variable "enable_kubernetes_alpha" {

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
enabled = bool
autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
enabled = false
autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
Expand Down
11 changes: 6 additions & 5 deletions test/fixtures/node_pool/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ module "example" {
compute_engine_service_account = var.compute_engine_service_accounts[0]

cluster_autoscaling = {
enabled = true
max_cpu_cores = 20
min_cpu_cores = 5
max_memory_gb = 30
min_memory_gb = 10
enabled = true
autoscaling_profile = "OPTIMIZE_UTILIZATION"
max_cpu_cores = 20
min_cpu_cores = 5
max_memory_gb = 30
min_memory_gb = 10
}
}

3 changes: 2 additions & 1 deletion test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

control "gcloud" do
title "Google Compute Engine GKE configuration"
describe command("gcloud --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do
describe command("gcloud beta --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do
its(:exit_status) { should eq 0 }
its(:stderr) { should eq '' }

Expand All @@ -40,6 +40,7 @@
"oauthScopes" => %w(https://www.googleapis.com/auth/logging.write https://www.googleapis.com/auth/monitoring),
"serviceAccount" => "default"
},
"autoscalingProfile" => "OPTIMIZE_UTILIZATION",
"enableNodeAutoprovisioning" => true,
"resourceLimits" => [
{
Expand Down

0 comments on commit b1cb123

Please sign in to comment.