Skip to content

Commit d494b0f

Browse files
bharathkkbcloud-foundation-botjackwhelptonmorgante
authored
feat!: update TPG version constraints to 4.0 (#1129)
* feat: update TPG version constraints to allow 4.0 * Removes basic auth, renames namespace_identity * Regenerates modules and documentation * Updates tests to use latest Google provider * addresses warning about multiple provider blocks * Updates network module for Google provider 4.0 compatibility * Temporarily uses "main" for gcloud module (until next release is cut) * Comments out version constraint (temporary change) * fetches main branch by default? * Uses master branch for gcloud module (until release is cut) * Uses kubectl-wrapper where appropriate * Uses released version of gcloud module * Returns instance group URLs per node pool * Extends use of cluster_output_node_pools_ variables * Fixes documentation * Updates more modules * Updates READMEs to match variables * Uses master branch of bastion * temporary change until new version is released * Updates node pools versions description * Adds locals for node pool instance group URLs * Uses master branch of terraform-google-project-factory * temporary change until new version of that dependency is released * Updates project version ready for release * Updates pinned version of Google provider for example * Updates pinned version of Google provider in example * Addresses code review comments * Temporarily applies an empty source_tags setting. * this should be removed once hashicorp/terraform-provider-google#10494 is addressed * Fixes indentation * Uses newly-released version of project factory * Uses released version of bastion host * Removes use of SECURE mode (deprecated) * test empty source tag workaround * fix wi test * refactor IAM test for loose match * map old node meta value, add validations * update docs * Update autogen/main/variables.tf.tmpl Co-authored-by: Morgante Pell <[email protected]> * remove local Co-authored-by: cloud-foundation-bot <[email protected]> Co-authored-by: Jack Whelpton <[email protected]> Co-authored-by: Morgante Pell <[email protected]>
1 parent 3b5ddb9 commit d494b0f

File tree

161 files changed

+1077
-578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+1077
-578
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ Then perform the following commands on the root folder:
128128
| add\_master\_webhook\_firewall\_rules | Create master\_webhook firewall rules for ports defined in `firewall_inbound_ports` | `bool` | `false` | no |
129129
| add\_shadow\_firewall\_rules | Create GKE shadow firewall (the same as default firewall rules with firewall logs enabled). | `bool` | `false` | no |
130130
| authenticator\_security\_group | The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format [email protected] | `string` | `null` | no |
131-
| basic\_auth\_password | The password to be used with Basic Authentication. | `string` | `""` | no |
132-
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | `string` | `""` | no |
133131
| cluster\_autoscaling | Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling) | <pre>object({<br> enabled = bool<br> min_cpu_cores = number<br> max_cpu_cores = number<br> min_memory_gb = number<br> max_memory_gb = number<br> gpu_resources = list(object({ resource_type = string, minimum = number, maximum = number }))<br> })</pre> | <pre>{<br> "enabled": false,<br> "gpu_resources": [],<br> "max_cpu_cores": 0,<br> "max_memory_gb": 0,<br> "min_cpu_cores": 0,<br> "min_memory_gb": 0<br>}</pre> | no |
134132
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | `any` | `null` | no |
135133
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | `map(string)` | `{}` | no |
@@ -151,7 +149,7 @@ Then perform the following commands on the root folder:
151149
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer and artifactregistry.reader roles. | `bool` | `false` | no |
152150
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | `bool` | `true` | no |
153151
| http\_load\_balancing | Enable httpload balancer addon | `bool` | `true` | no |
154-
| identity\_namespace | Workload Identity namespace. (Default value of `enabled` automatically sets project based namespace `[project_id].svc.id.goog`) | `string` | `"enabled"` | no |
152+
| identity\_namespace | The workload pool to attach all Kubernetes service accounts to. (Default value of `enabled` automatically sets project-based pool `[project_id].svc.id.goog`) | `string` | `"enabled"` | no |
155153
| impersonate\_service\_account | An optional service account to impersonate for gcloud commands. If this service account is not specified, the module will use Application Default Credentials. | `string` | `""` | no |
156154
| initial\_node\_count | The number of nodes to create in this cluster's default node pool. | `number` | `0` | no |
157155
| ip\_masq\_link\_local | Whether to masquerade traffic to the link-local prefix (169.254.0.0/16). | `bool` | `false` | no |
@@ -170,7 +168,7 @@ Then perform the following commands on the root folder:
170168
| network\_policy | Enable network policy addon | `bool` | `false` | no |
171169
| network\_policy\_provider | The network policy provider. | `string` | `"CALICO"` | no |
172170
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
173-
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA_SERVER"` | no |
171+
| node\_metadata | Specifies how node metadata is exposed to the workload running on the node | `string` | `"GKE_METADATA"` | no |
174172
| node\_pools | List of maps containing node pools | `list(map(string))` | <pre>[<br> {<br> "name": "default-node-pool"<br> }<br>]</pre> | no |
175173
| node\_pools\_labels | Map of maps containing node labels by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
176174
| node\_pools\_metadata | Map of maps containing node metadata by node-pool name | `map(map(string))` | <pre>{<br> "all": {},<br> "default-node-pool": {}<br>}</pre> | no |
@@ -202,7 +200,7 @@ Then perform the following commands on the root folder:
202200
| endpoint | Cluster endpoint |
203201
| horizontal\_pod\_autoscaling\_enabled | Whether horizontal pod autoscaling enabled |
204202
| http\_load\_balancing\_enabled | Whether http load balancing enabled |
205-
| identity\_namespace | Workload Identity namespace |
203+
| identity\_namespace | Workload Identity pool |
206204
| instance\_group\_urls | List of GKE generated instance groups |
207205
| location | Cluster location (region if regional cluster, zone if zonal cluster) |
208206
| logging\_service | Logging service used |
@@ -213,7 +211,7 @@ Then perform the following commands on the root folder:
213211
| name | Cluster name |
214212
| network\_policy\_enabled | Whether network policy enabled |
215213
| node\_pools\_names | List of node pools names |
216-
| node\_pools\_versions | List of node pools versions |
214+
| node\_pools\_versions | Node pool versions by node pool name |
217215
| region | Cluster region |
218216
| release\_channel | The release channel of this cluster |
219217
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |

autogen/main/cluster.tf.tmpl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ resource "google_container_cluster" "primary" {
161161
}
162162

163163
master_auth {
164-
username = var.basic_auth_username
165-
password = var.basic_auth_password
166-
167164
client_certificate_config {
168165
issue_client_certificate = var.issue_client_certificate
169166
}
@@ -298,7 +295,7 @@ resource "google_container_cluster" "primary" {
298295
for_each = local.cluster_node_metadata_config
299296

300297
content {
301-
node_metadata = workload_metadata_config.value.node_metadata
298+
mode = workload_metadata_config.value.mode
302299
}
303300
}
304301

@@ -377,7 +374,7 @@ resource "google_container_cluster" "primary" {
377374
for_each = local.cluster_workload_identity_config
378375

379376
content {
380-
identity_namespace = workload_identity_config.value.identity_namespace
377+
workload_pool = workload_identity_config.value.workload_pool
381378
}
382379
}
383380

@@ -634,9 +631,10 @@ resource "google_container_node_pool" "pools" {
634631
for_each = local.cluster_node_metadata_config
635632

636633
content {
637-
node_metadata = lookup(each.value, "node_metadata", workload_metadata_config.value.node_metadata)
634+
mode = lookup(each.value, "node_metadata", workload_metadata_config.value.mode)
638635
}
639636
}
637+
640638
{% if beta_cluster %}
641639
dynamic "sandbox_config" {
642640
for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []

autogen/main/dns.tf.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
Delete default kube-dns configmap
2121
*****************************************/
2222
module "gcloud_delete_default_kube_dns_configmap" {
23-
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
24-
version = "~> 2.1.0"
23+
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
24+
version = "~> 3.1"
25+
2526
enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && !var.skip_provisioners
2627
cluster_name = google_container_cluster.primary.name
2728
cluster_location = google_container_cluster.primary.location

autogen/main/firewall.tf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ resource "google_compute_firewall" "master_webhooks" {
112112
direction = "INGRESS"
113113

114114
source_ranges = [local.cluster_endpoint_for_nodes]
115+
source_tags = []
115116
target_tags = [local.cluster_network_tag]
116117

117118
allow {

autogen/main/main.tf.tmpl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ locals {
111111
security_group = var.authenticator_security_group
112112
}]
113113

114+
// legacy mappings https://github.com/hashicorp/terraform-provider-google/pull/10238
115+
old_node_metadata_config_mapping = { GKE_METADATA_SERVER = "GKE_METADATA", GCE_METADATA = "EXPOSE" }
116+
114117
cluster_node_metadata_config = var.node_metadata == "UNSPECIFIED" ? [] : [{
115-
node_metadata = var.node_metadata
118+
mode = lookup(local.old_node_metadata_config_mapping, var.node_metadata, var.node_metadata)
116119
}]
117120

118121
cluster_output_name = google_container_cluster.primary.name
@@ -153,7 +156,7 @@ locals {
153156
}]
154157

155158
cluster_output_node_pools_names = concat([for np in google_container_node_pool.pools : np.name], [""])
156-
cluster_output_node_pools_versions = concat([for np in google_container_node_pool.pools : np.version], [""])
159+
cluster_output_node_pools_versions = { for np in google_container_node_pool.pools : np.name => np.version }
157160

158161
cluster_master_auth_list_layer1 = local.cluster_output_master_auth
159162
cluster_master_auth_list_layer2 = local.cluster_master_auth_list_layer1[0]
@@ -177,7 +180,7 @@ locals {
177180
cluster_horizontal_pod_autoscaling_enabled = !local.cluster_output_horizontal_pod_autoscaling_enabled
178181
workload_identity_enabled = !(var.identity_namespace == null || var.identity_namespace == "null")
179182
cluster_workload_identity_config = ! local.workload_identity_enabled ? [] : var.identity_namespace == "enabled" ? [{
180-
identity_namespace = "${var.project_id}.svc.id.goog" }] : [{ identity_namespace = var.identity_namespace
183+
workload_pool = "${var.project_id}.svc.id.goog" }] : [{ workload_pool = var.identity_namespace
181184
}]
182185
{% if beta_cluster %}
183186
# BETA features

autogen/main/outputs.tf.tmpl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ output "node_pools_names" {
114114
}
115115

116116
output "node_pools_versions" {
117-
description = "List of node pools versions"
117+
description = "Node pool versions by node pool name"
118118
value = local.cluster_node_pools_versions
119119
}
120120

@@ -123,23 +123,23 @@ output "service_account" {
123123
value = local.service_account
124124
}
125125

126+
output "instance_group_urls" {
127+
description = "List of GKE generated instance groups"
128+
value = distinct(flatten([for np in google_container_node_pool.pools : np.managed_instance_group_urls]))
129+
}
130+
126131
output "release_channel" {
127132
description = "The release channel of this cluster"
128133
value = var.release_channel
129134
}
130135

131136
output "identity_namespace" {
132-
description = "Workload Identity namespace"
133-
value = length(local.cluster_workload_identity_config) > 0 ? local.cluster_workload_identity_config[0].identity_namespace : null
137+
description = "Workload Identity pool"
138+
value = length(local.cluster_workload_identity_config) > 0 ? local.cluster_workload_identity_config[0].workload_pool : null
134139
depends_on = [
135140
google_container_cluster.primary
136141
]
137142
}
138-
139-
output "instance_group_urls" {
140-
description = "List of GKE generated instance groups"
141-
value = google_container_cluster.primary.instance_group_urls
142-
}
143143
{% if private_cluster %}
144144

145145
output "master_ipv4_cidr_block" {

autogen/main/variables.tf.tmpl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,6 @@ variable "service_account" {
394394
default = ""
395395
}
396396

397-
variable "basic_auth_username" {
398-
type = string
399-
description = "The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration."
400-
default = ""
401-
}
402-
403-
variable "basic_auth_password" {
404-
type = string
405-
description = "The password to be used with Basic Authentication."
406-
default = ""
407-
}
408-
409397
variable "issue_client_certificate" {
410398
type = bool
411399
description = "Issues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive!"
@@ -549,8 +537,13 @@ variable "authenticator_security_group" {
549537

550538
variable "node_metadata" {
551539
description = "Specifies how node metadata is exposed to the workload running on the node"
552-
default = "GKE_METADATA_SERVER"
540+
default = "GKE_METADATA"
553541
type = string
542+
543+
validation {
544+
condition = contains(["GKE_METADATA", "GCE_METADATA", "UNSPECIFIED", "GKE_METADATA_SERVER", "EXPOSE"], var.node_metadata)
545+
error_message = "The node_metadata value must be one of GKE_METADATA, GCE_METADATA or UNSPECIFIED."
546+
}
554547
}
555548

556549
variable "database_encryption" {
@@ -564,7 +557,7 @@ variable "database_encryption" {
564557
}
565558

566559
variable "identity_namespace" {
567-
description = "Workload Identity namespace. (Default value of `enabled` automatically sets project based namespace `[project_id].svc.id.goog`)"
560+
description = "The workload pool to attach all Kubernetes service accounts to. (Default value of `enabled` automatically sets project-based pool `[project_id].svc.id.goog`)"
568561
type = string
569562
default = "enabled"
570563
}

autogen/main/versions.tf.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ terraform {
2424
required_providers {
2525
google-beta = {
2626
source = "hashicorp/google-beta"
27-
version = ">= 3.87.0, <4.0.0"
27+
version = ">= 4.0.0, < 5.0"
2828
}
2929
kubernetes = {
3030
source = "hashicorp/kubernetes"
@@ -38,7 +38,7 @@ terraform {
3838
required_providers {
3939
google = {
4040
source = "hashicorp/google"
41-
version = ">= 3.55.0, <4.0.0"
41+
version = ">= 4.0.0, < 5.0"
4242
}
4343
kubernetes = {
4444
source = "hashicorp/kubernetes"

autogen/safer-cluster/main.tf.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ module "gke" {
111111
registry_project_ids = var.registry_project_ids
112112
grant_registry_access = var.grant_registry_access
113113

114-
// Basic Auth disabled
115-
basic_auth_username = ""
116-
basic_auth_password = ""
117-
118114
issue_client_certificate = false
119115

120116
cluster_resource_labels = var.cluster_resource_labels
@@ -164,7 +160,7 @@ module "gke" {
164160

165161
enable_vertical_pod_autoscaling = var.enable_vertical_pod_autoscaling
166162

167-
// We enable identity namespace by default.
163+
// We enable Workload Identity by default.
168164
identity_namespace = "${var.project_id}.svc.id.goog"
169165

170166
authenticator_security_group = var.authenticator_security_group

autogen/safer-cluster/outputs.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ output "node_pools_names" {
104104
}
105105

106106
output "node_pools_versions" {
107-
description = "List of node pools versions"
107+
description = "Node pool versions by node pool name"
108108
value = module.gke.node_pools_versions
109109
}
110110

cluster.tf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ resource "google_container_cluster" "primary" {
9898
}
9999

100100
master_auth {
101-
username = var.basic_auth_username
102-
password = var.basic_auth_password
103-
104101
client_certificate_config {
105102
issue_client_certificate = var.issue_client_certificate
106103
}
@@ -165,7 +162,7 @@ resource "google_container_cluster" "primary" {
165162
for_each = local.cluster_node_metadata_config
166163

167164
content {
168-
node_metadata = workload_metadata_config.value.node_metadata
165+
mode = workload_metadata_config.value.mode
169166
}
170167
}
171168

@@ -211,7 +208,7 @@ resource "google_container_cluster" "primary" {
211208
for_each = local.cluster_workload_identity_config
212209

213210
content {
214-
identity_namespace = workload_identity_config.value.identity_namespace
211+
workload_pool = workload_identity_config.value.workload_pool
215212
}
216213
}
217214

@@ -339,10 +336,11 @@ resource "google_container_node_pool" "pools" {
339336
for_each = local.cluster_node_metadata_config
340337

341338
content {
342-
node_metadata = lookup(each.value, "node_metadata", workload_metadata_config.value.node_metadata)
339+
mode = lookup(each.value, "node_metadata", workload_metadata_config.value.mode)
343340
}
344341
}
345342

343+
346344
shielded_instance_config {
347345
enable_secure_boot = lookup(each.value, "enable_secure_boot", false)
348346
enable_integrity_monitoring = lookup(each.value, "enable_integrity_monitoring", true)

dns.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
Delete default kube-dns configmap
2121
*****************************************/
2222
module "gcloud_delete_default_kube_dns_configmap" {
23-
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
24-
version = "~> 2.1.0"
23+
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
24+
version = "~> 3.1"
25+
2526
enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && !var.skip_provisioners
2627
cluster_name = google_container_cluster.primary.name
2728
cluster_location = google_container_cluster.primary.location

docs/upgrading_to_v18.0.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Upgrading to v18.0
2+
3+
The v18.0 release of *kubernetes-engine* is a backwards incompatible release.
4+
5+
### Google Cloud Platform Provider upgrade
6+
The Terraform Kubernetes Engine Module now requires version 4.0 or higher of
7+
the Google Cloud Platform Provider.
8+
9+
```diff
10+
terraform {
11+
required_providers {
12+
google = {
13+
source = "hashicorp/google"
14+
- version = "~> 3.0"
15+
+ version = "~> 4.0"
16+
}
17+
google-beta = {
18+
source = "hashicorp/google-beta"
19+
- version = "~> 3.0"
20+
+ version = "~> 4.0"
21+
}
22+
23+
}
24+
}
25+
```
26+
27+
### Kubernetes Basic Authentication removed
28+
Basic authentication is deprecated and has been removed in GKE 1.19 and later.
29+
Owing to this, the `basic_auth_username` and `basic_auth_password` variables
30+
have been eliminated.
31+
32+
```diff
33+
module "gke" {
34+
source = "terraform-google-modules/kubernetes-engine/google//modules/private-cluster"
35+
- version = "~> 17.0"
36+
+ version = "~> 18.0"
37+
38+
- basic_auth_username = "admin"
39+
- basic_auth_password = "s3crets!"
40+
}
41+
```
42+
43+
### Acceptable values for node_metadata modified
44+
It is recommended to update `node_metadata` variable to one of `GKE_METADATA`,
45+
`GCE_METADATA` or `UNSPECIFIED`. `GKE_METADATA` replaces the previous
46+
`GKE_METADATA_SERVER` value, `GCE_METADATA` should be used in place of
47+
`EXPOSE`, however old values continue to be supported for backwards compatibility.
48+
The `SECURE` option, previously deprecated, has now been removed.
49+
50+
```diff
51+
module "gke" {
52+
source = "../../modules/safer-cluster"
53+
54+
node_pools = [
55+
{
56+
57+
- node_metadata = "GKE_METADATA_SERVER"
58+
+ node_metadata = "GKE_METADATA"
59+
}
60+
]
61+
}
62+
```
63+
64+
### node_pools_versions is now keyed by node-pool name
65+
The `node_pools_versions` output is now an object keyed by node pool name,
66+
rather than a list as previously.

examples/acm-terraform-blog-part1/terraform/gke.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
module "enabled_google_apis" {
1818
source = "terraform-google-modules/project-factory/google//modules/project_services"
19-
version = "~> 10.0"
19+
version = "~> 11.3"
2020

2121
project_id = var.project
2222
disable_services_on_destroy = false

0 commit comments

Comments
 (0)