|
| 1 | +# Upgrading to v34.0 |
| 2 | + |
| 3 | +The v34.0 release of _kubernetes-engine_ is a backwards incompatible release. |
| 4 | + |
| 5 | +### safer-cluster modules: Added create_service_account variable |
| 6 | + |
| 7 | +This only affects users of the `safer-cluster` modules that have set `var.compute_engine_service_account` to something other than the default `""`. |
| 8 | + |
| 9 | +A variable `var.create_service_account` was added to the `safer-cluster` modules that when explicitly set to `false` avoids the following error withing the `private-cluster` modules: |
| 10 | + |
| 11 | +```sh |
| 12 | +Error: Invalid count argument |
| 13 | + |
| 14 | + on .terraform/modules/gke_cluster.gke/modules/beta-private-cluster/sa.tf line 35, in resource "random_string" "cluster_service_account_suffix": |
| 15 | + 35: count = var.create_service_account && var.service_account_name == "" ? 1 : 0 |
| 16 | + |
| 17 | +The "count" value depends on resource attributes that cannot be determined |
| 18 | +until apply, so Terraform cannot predict how many instances will be created. |
| 19 | +To work around this, use the -target argument to first apply only the |
| 20 | +resources that the count depends on. |
| 21 | +``` |
| 22 | +
|
| 23 | +This seems to happen if `var.compute_engine_service_account` is passed in, and the externally created service account is being created at the same time, so the name/email is not computed yet: |
| 24 | +
|
| 25 | +```terraform |
| 26 | +resource "google_service_account" "cluster_service_account" { |
| 27 | + project = var.project_id |
| 28 | + account_id = "tf-gke-${var.cluster_name}-${random_string.cluster_service_account_suffix.result}" |
| 29 | + display_name = "Terraform-managed service account for cluster ${var.cluster_name}" |
| 30 | +} |
| 31 | +
|
| 32 | +module "gke" { |
| 33 | + source = "terraform-google-modules/kubernetes-engine/google//modules/safer-cluster" |
| 34 | + version = "~> 33.0" |
| 35 | +
|
| 36 | + project_id = var.project_id |
| 37 | + name = var.cluster_name |
| 38 | +
|
| 39 | + create_service_account = false |
| 40 | + compute_engine_service_account = google_service_account.cluster_service_account.email |
| 41 | +} |
| 42 | +``` |
| 43 | +
|
| 44 | +By explicitly passing a `var.create_service_account = false` it short circuits the calculations dependent on `var.service_account_name`: |
| 45 | +
|
| 46 | +```terraform |
| 47 | +resource "random_string" "cluster_service_account_suffix" { |
| 48 | + count = var.create_service_account && var.service_account_name == "" ? 1 : 0 |
| 49 | + upper = false |
| 50 | + lower = true |
| 51 | + special = false |
| 52 | + length = 4 |
| 53 | +} |
| 54 | +``` |
0 commit comments