Skip to content

Commit

Permalink
feat: Set auto-provisioned node pools to use configured service accou…
Browse files Browse the repository at this point in the history
…nt (#639)
  • Loading branch information
dpetersen committed Dec 29, 2020
1 parent 2c4a2b1 commit 4a61f76
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 14 deletions.
10 changes: 9 additions & 1 deletion autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ resource "google_container_cluster" "primary" {
{% endif %}

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
{% if beta_cluster %}
dynamic "auto_provisioning_defaults" {
for_each = var.cluster_autoscaling.enabled ? [1] : []

content {
service_account = local.service_account
oauth_scopes = local.node_pools_oauth_scopes["all"]
}
}
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
{% endif %}
dynamic "resource_limits" {
Expand Down
2 changes: 1 addition & 1 deletion autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
10 changes: 9 additions & 1 deletion modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ resource "google_container_cluster" "primary" {
monitoring_service = local.cluster_telemetry_type_is_set ? null : var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
for_each = var.cluster_autoscaling.enabled ? [1] : []

content {
service_account = local.service_account
oauth_scopes = local.node_pools_oauth_scopes["all"]
}
}
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
10 changes: 9 additions & 1 deletion modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ resource "google_container_cluster" "primary" {
monitoring_service = local.cluster_telemetry_type_is_set ? null : var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
for_each = var.cluster_autoscaling.enabled ? [1] : []

content {
service_account = local.service_account
oauth_scopes = local.node_pools_oauth_scopes["all"]
}
}
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
10 changes: 9 additions & 1 deletion modules/beta-public-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ resource "google_container_cluster" "primary" {
monitoring_service = local.cluster_telemetry_type_is_set ? null : var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
for_each = var.cluster_autoscaling.enabled ? [1] : []

content {
service_account = local.service_account
oauth_scopes = local.node_pools_oauth_scopes["all"]
}
}
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-public-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
10 changes: 9 additions & 1 deletion modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ resource "google_container_cluster" "primary" {
monitoring_service = local.cluster_telemetry_type_is_set ? null : var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
for_each = var.cluster_autoscaling.enabled ? [1] : []

content {
service_account = local.service_account
oauth_scopes = local.node_pools_oauth_scopes["all"]
}
}
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
2 changes: 1 addition & 1 deletion modules/private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
2 changes: 1 addition & 1 deletion modules/private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
2 changes: 1 addition & 1 deletion sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ locals {
["dummy"],
),
)
// if user set var.service_accont it will be used even if var.create_service_account==true, so service account will be created but not used
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
it "has the expected cluster autoscaling settings" do
expect(data['autoscaling']).to eq({
"autoprovisioningNodePoolDefaults" => {
"oauthScopes" => %w(https://www.googleapis.com/auth/logging.write https://www.googleapis.com/auth/monitoring),
"oauthScopes" => %w(https://www.googleapis.com/auth/cloud-platform),
"serviceAccount" => "default"
},
"autoscalingProfile" => "OPTIMIZE_UTILIZATION",
Expand Down

0 comments on commit 4a61f76

Please sign in to comment.