Skip to content

Commit e522073

Browse files
slimaticapeabody
andauthored
feat(cluster.tf): add support to set initial release channel version (#1625)
Co-authored-by: Andrew Peabody <[email protected]>
1 parent e51804e commit e522073

File tree

21 files changed

+337
-10
lines changed

21 files changed

+337
-10
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ resource "google_container_cluster" "primary" {
8383
disabled = var.disable_default_snat
8484
}
8585

86-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
86+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
8787

8888
{% if beta_cluster and autopilot_cluster != true %}
8989
dynamic "cluster_telemetry" {

cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resource "google_container_cluster" "primary" {
6969
disabled = var.disable_default_snat
7070
}
7171

72-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
72+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7373

7474
# only one of logging/monitoring_service or logging/monitoring_config can be specified
7575
logging_service = local.logmon_config_is_set ? null : var.logging_service
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Simple Regional Cluster
2+
3+
This example illustrates how to create a simple private cluster with beta features.
4+
5+
[^]: (autogen_docs_start)
6+
7+
## Inputs
8+
9+
| Name | Description | Type | Default | Required |
10+
|------|-------------|:----:|:-----:|:-----:|
11+
| cloudrun | Boolean to enable / disable CloudRun | string | `"true"` | no |
12+
| cluster\_name\_suffix | A suffix to append to the default cluster name | string | `""` | no |
13+
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | string | n/a | yes |
14+
| credentials\_path | The path to the GCP credentials JSON file | string | n/a | yes |
15+
| ip\_range\_pods | The secondary ip range to use for pods | string | n/a | yes |
16+
| ip\_range\_services | The secondary ip range to use for pods | string | n/a | yes |
17+
| istio | Boolean to enable / disable Istio | string | `"true"` | no |
18+
| network | The VPC network to host the cluster in | string | n/a | yes |
19+
| project\_id | The project ID to host the cluster in | string | n/a | yes |
20+
| region | The region to host the cluster in | string | n/a | yes |
21+
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
22+
23+
## Outputs
24+
25+
| Name | Description |
26+
|------|-------------|
27+
| ca\_certificate | |
28+
| client\_token | |
29+
| cluster\_name | Cluster name |
30+
| credentials\_path | |
31+
| ip\_range\_pods | The secondary IP range used for pods |
32+
| ip\_range\_services | The secondary IP range used for services |
33+
| kubernetes\_endpoint | |
34+
| location | |
35+
| master\_kubernetes\_version | The master Kubernetes version |
36+
| network | |
37+
| project\_id | |
38+
| region | |
39+
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
40+
| subnetwork | |
41+
| zones | List of zones in which the cluster resides |
42+
43+
[^]: (autogen_docs_end)
44+
45+
To provision this example, run the following from within this directory:
46+
- `terraform init` to get the plugins
47+
- `terraform plan` to see the infrastructure plan
48+
- `terraform apply` to apply the infrastructure build
49+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
locals {
18+
cluster_type = "simple-regional-private"
19+
}
20+
21+
data "google_client_config" "default" {}
22+
23+
provider "kubernetes" {
24+
host = "https://${module.gke.endpoint}"
25+
token = data.google_client_config.default.access_token
26+
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
27+
}
28+
29+
data "google_compute_subnetwork" "subnetwork" {
30+
name = var.subnetwork
31+
project = var.project_id
32+
region = var.region
33+
}
34+
35+
module "gke" {
36+
source = "../../modules/private-cluster/"
37+
project_id = var.project_id
38+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
39+
regional = true
40+
region = var.region
41+
network = var.network
42+
kubernetes_version = var.kubernetes_version
43+
subnetwork = var.subnetwork
44+
ip_range_pods = var.ip_range_pods
45+
ip_range_services = var.ip_range_services
46+
create_service_account = false
47+
service_account = var.compute_engine_service_account
48+
enable_private_endpoint = true
49+
enable_private_nodes = true
50+
master_ipv4_cidr_block = "172.16.0.0/28"
51+
default_max_pods_per_node = 20
52+
remove_default_node_pool = true
53+
54+
node_pools = [
55+
{
56+
name = "pool-01"
57+
min_count = 1
58+
max_count = 100
59+
local_ssd_count = 0
60+
disk_size_gb = 100
61+
disk_type = "pd-standard"
62+
auto_repair = true
63+
auto_upgrade = true
64+
service_account = var.compute_engine_service_account
65+
preemptible = false
66+
max_pods_per_node = 12
67+
},
68+
]
69+
70+
master_authorized_networks = [
71+
{
72+
cidr_block = data.google_compute_subnetwork.subnetwork.ip_cidr_range
73+
display_name = "VPC"
74+
},
75+
]
76+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "kubernetes_endpoint" {
18+
sensitive = true
19+
value = module.gke.endpoint
20+
}
21+
22+
output "client_token" {
23+
sensitive = true
24+
value = base64encode(data.google_client_config.default.access_token)
25+
}
26+
27+
output "ca_certificate" {
28+
value = module.gke.ca_certificate
29+
}
30+
31+
output "service_account" {
32+
description = "The default service account used for running nodes."
33+
value = module.gke.service_account
34+
}
35+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../test/fixtures/all_examples/test_outputs.tf
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The project ID to host the cluster in"
19+
}
20+
21+
variable "cluster_name_suffix" {
22+
description = "A suffix to append to the default cluster name"
23+
default = ""
24+
}
25+
26+
variable "region" {
27+
description = "The region to host the cluster in"
28+
}
29+
30+
variable "network" {
31+
description = "The VPC network to host the cluster in"
32+
}
33+
34+
variable "subnetwork" {
35+
description = "The subnetwork to host the cluster in"
36+
}
37+
38+
variable "ip_range_pods" {
39+
description = "The secondary ip range to use for pods"
40+
}
41+
42+
variable "ip_range_services" {
43+
description = "The secondary ip range to use for services"
44+
}
45+
46+
variable "compute_engine_service_account" {
47+
description = "Service account to associate to the nodes in the cluster"
48+
}
49+
50+
variable "kubernetes_version" {
51+
type = string
52+
description = "The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region."
53+
default = "latest"
54+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_providers {
19+
google = {
20+
source = "hashicorp/google"
21+
version = "~> 4.0"
22+
}
23+
kubernetes = {
24+
source = "hashicorp/kubernetes"
25+
}
26+
}
27+
required_version = ">= 0.13"
28+
}

modules/beta-autopilot-private-cluster/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ resource "google_container_cluster" "primary" {
6767
disabled = var.disable_default_snat
6868
}
6969

70-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
70+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7171

7272
cluster_autoscaling {
7373
dynamic "auto_provisioning_defaults" {

modules/beta-autopilot-public-cluster/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ resource "google_container_cluster" "primary" {
6767
disabled = var.disable_default_snat
6868
}
6969

70-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
70+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7171

7272
cluster_autoscaling {
7373
dynamic "auto_provisioning_defaults" {

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ resource "google_container_cluster" "primary" {
7575
disabled = var.disable_default_snat
7676
}
7777

78-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
78+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7979

8080
dynamic "cluster_telemetry" {
8181
for_each = local.cluster_telemetry_type_is_set ? [1] : []

modules/beta-private-cluster/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ resource "google_container_cluster" "primary" {
7575
disabled = var.disable_default_snat
7676
}
7777

78-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
78+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7979

8080
dynamic "cluster_telemetry" {
8181
for_each = local.cluster_telemetry_type_is_set ? [1] : []

modules/beta-public-cluster-update-variant/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ resource "google_container_cluster" "primary" {
7575
disabled = var.disable_default_snat
7676
}
7777

78-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
78+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7979

8080
dynamic "cluster_telemetry" {
8181
for_each = local.cluster_telemetry_type_is_set ? [1] : []

modules/beta-public-cluster/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ resource "google_container_cluster" "primary" {
7575
disabled = var.disable_default_snat
7676
}
7777

78-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
78+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7979

8080
dynamic "cluster_telemetry" {
8181
for_each = local.cluster_telemetry_type_is_set ? [1] : []

modules/private-cluster-update-variant/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resource "google_container_cluster" "primary" {
6969
disabled = var.disable_default_snat
7070
}
7171

72-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
72+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7373

7474
# only one of logging/monitoring_service or logging/monitoring_config can be specified
7575
logging_service = local.logmon_config_is_set ? null : var.logging_service

modules/private-cluster/cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resource "google_container_cluster" "primary" {
6969
disabled = var.disable_default_snat
7070
}
7171

72-
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : null
72+
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7373

7474
# only one of logging/monitoring_service or logging/monitoring_config can be specified
7575
logging_service = local.logmon_config_is_set ? null : var.logging_service

test/fixtures/shared/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ variable "registry_project_ids" {
3939
description = "Projects to use for granting access to GCR registries, if requested"
4040
type = list(string)
4141
}
42+
43+
variable "kubernetes_version" {
44+
type = string
45+
description = "The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region."
46+
default = "latest"
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "example" {
18+
source = "../../../examples/simple_regional_private_with_cluster_version"
19+
20+
project_id = var.project_ids[1]
21+
cluster_name_suffix = "-${random_string.suffix.result}"
22+
kubernetes_version = var.kubernetes_version
23+
region = var.region
24+
network = google_compute_network.main.name
25+
subnetwork = google_compute_subnetwork.main.name
26+
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
27+
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
28+
compute_engine_service_account = var.compute_engine_service_accounts[1]
29+
}
30+

0 commit comments

Comments
 (0)