Skip to content

Commit be765c9

Browse files
authored
Merge pull request #124 from terraform-google-modules/feature/beta-cluster
Submodules w/ beta Istio and CloudRun addons
2 parents 88eb7b0 + 2d2e4fe commit be765c9

Some content is hidden

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

49 files changed

+3621
-20
lines changed

Diff for: autogen/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Terraform Kubernetes Engine Module
22

3-
This module handles opinionated Google Cloud Platform Kubernetes Engine cluster creation and configuration with Node Pools, IP MASQ, Network Policy, etc.{% if private_cluster %} This particular submodule creates a [private cluster](https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters){% endif %}
3+
This module handles opinionated Google Cloud Platform Kubernetes Engine cluster creation and configuration with Node Pools, IP MASQ, Network Policy, etc.{% if private_cluster %} This particular submodule creates a [private cluster](https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters){% endif %}{% if beta_cluster %}Beta features are enabled on this submodule.{% endif %}
44

55
The resources/services/activations/deletions that this module will create/trigger are:
66
- Create a GKE cluster with the provided addons
@@ -36,6 +36,10 @@ module "gke" {
3636
enable_private_nodes = true
3737
master_ipv4_cidr_block = "10.0.0.0/28"
3838
{% endif %}
39+
{% if beta_cluster %}
40+
istio = true
41+
cloudrun = true
42+
{% endif %}
3943
4044
node_pools = [
4145
{
@@ -137,7 +141,7 @@ The [project factory](https://github.com/terraform-google-modules/terraform-goog
137141
- [kubectl](https://github.com/kubernetes/kubernetes/releases) 1.9.x
138142
#### Terraform and Plugins
139143
- [Terraform](https://www.terraform.io/downloads.html) 0.11.x
140-
{% if private_cluster %}
144+
{% if private_cluster or beta_cluster %}
141145
- [terraform-provider-google-beta](https://github.com/terraform-providers/terraform-provider-google-beta) v2.3, v2.6, v2.7
142146
{% else %}
143147
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) v2.3, v2.6, v2.7

Diff for: autogen/auth.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Retrieve authentication token
2121
*****************************************/
2222
data "google_client_config" "default" {
23-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
23+
provider = "{% if private_cluster or beta_cluster %}google-beta{% else %}google{% endif %}"
2424
}
2525

2626
/******************************************

Diff for: autogen/cluster_regional.tf

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Create regional cluster
2121
*****************************************/
2222
resource "google_container_cluster" "primary" {
23-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
23+
provider = "{% if private_cluster or beta_cluster %}google-beta{% else %}google{% endif %}"
2424
count = "${var.regional ? 1 : 0}"
2525
name = "${var.name}"
2626
description = "${var.description}"
@@ -73,6 +73,15 @@ resource "google_container_cluster" "primary" {
7373
network_policy_config {
7474
disabled = "${var.network_policy ? 0 : 1}"
7575
}
76+
{% if beta_cluster %}
77+
istio_config {
78+
disabled = "${var.istio ? 0 : 1}"
79+
}
80+
81+
cloudrun_config {
82+
disabled = "${var.cloudrun ? 0 : 1}"
83+
}
84+
{% endif %}
7685
}
7786

7887
ip_allocation_policy {
@@ -105,14 +114,12 @@ resource "google_container_cluster" "primary" {
105114
}
106115
}
107116
{% if private_cluster %}
108-
109117
private_cluster_config {
110118
enable_private_endpoint = "${var.enable_private_endpoint}"
111119
enable_private_nodes = "${var.enable_private_nodes}"
112120
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
113121
}
114122
{% endif %}
115-
116123
remove_default_node_pool = "${var.remove_default_node_pool}"
117124
}
118125

Diff for: autogen/cluster_zonal.tf

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Create zonal cluster
2121
*****************************************/
2222
resource "google_container_cluster" "zonal_primary" {
23-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
23+
provider = "{% if private_cluster or beta_cluster %}google-beta{% else %}google{% endif %}"
2424
count = "${var.regional ? 0 : 1}"
2525
name = "${var.name}"
2626
description = "${var.description}"
@@ -73,6 +73,15 @@ resource "google_container_cluster" "zonal_primary" {
7373
network_policy_config {
7474
disabled = "${var.network_policy ? 0 : 1}"
7575
}
76+
{% if beta_cluster %}
77+
istio_config {
78+
disabled = "${var.istio ? 0 : 1}"
79+
}
80+
81+
cloudrun_config {
82+
disabled = "${var.cloudrun ? 0 : 1}"
83+
}
84+
{% endif %}
7685
}
7786

7887
ip_allocation_policy {
@@ -105,14 +114,12 @@ resource "google_container_cluster" "zonal_primary" {
105114
}
106115
}
107116
{% if private_cluster %}
108-
109117
private_cluster_config {
110118
enable_private_endpoint = "${var.enable_private_endpoint}"
111119
enable_private_nodes = "${var.enable_private_nodes}"
112120
master_ipv4_cidr_block = "${var.master_ipv4_cidr_block}"
113121
}
114122
{% endif %}
115-
116123
remove_default_node_pool = "${var.remove_default_node_pool}"
117124
}
118125

Diff for: autogen/main.tf

+21-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Get available zones in region
2121
*****************************************/
2222
data "google_compute_zones" "available" {
23-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
23+
provider = "{% if private_cluster or beta_cluster %}google-beta{% else %}google{% endif %}"
2424
project = "${var.project_id}"
2525
region = "${var.region}"
2626
}
@@ -129,6 +129,20 @@ locals {
129129
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.kubernetes_dashboard.0.disabled, list("")), 0)}"
130130
}
131131

132+
{% if beta_cluster %}
133+
# BETA features
134+
cluster_type_output_istio_enabled = {
135+
regional = "${element(concat(google_container_cluster.primary.*.addons_config.0.istio_config.0.disabled, list("")), 0)}"
136+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.istio_config.0.disabled, list("")), 0)}"
137+
}
138+
139+
cluster_type_output_cloudrun_enabled = {
140+
regional = "${element(concat(google_container_cluster.primary.*.addons_config.0.cloudrun_config.0.disabled, list("")), 0)}"
141+
zonal = "${element(concat(google_container_cluster.zonal_primary.*.addons_config.0.cloudrun_config.0.disabled, list("")), 0)}"
142+
}
143+
# /BETA features
144+
{% endif %}
145+
132146
cluster_type_output_node_pools_names = {
133147
regional = "${concat(google_container_node_pool.pools.*.name, list(""))}"
134148
zonal = "${concat(google_container_node_pool.zonal_pools.*.name, list(""))}"
@@ -168,6 +182,12 @@ locals {
168182
cluster_http_load_balancing_enabled = "${local.cluster_type_output_http_load_balancing_enabled[local.cluster_type] ? false : true}"
169183
cluster_horizontal_pod_autoscaling_enabled = "${local.cluster_type_output_horizontal_pod_autoscaling_enabled[local.cluster_type] ? false : true}"
170184
cluster_kubernetes_dashboard_enabled = "${local.cluster_type_output_kubernetes_dashboard_enabled[local.cluster_type] ? false : true}"
185+
{% if beta_cluster %}
186+
# BETA features
187+
cluster_istio_enabled = "${local.cluster_type_output_istio_enabled[local.cluster_type] ? false : true}"
188+
cluster_cloudrun_enabled = "${local.cluster_type_output_cloudrun_enabled[local.cluster_type] ? false : true}"
189+
# /BETA features
190+
{% endif %}
171191
{% if private_cluster %}
172192
cluster_pod_security_policy_enabled = "${local.cluster_type_output_pod_security_policy_enabled[local.cluster_type] ? true : false}"
173193
{% endif %}

Diff for: autogen/networks.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
{{ autogeneration_note }}
1818

1919
data "google_compute_network" "gke_network" {
20-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
20+
provider = "{% if private_cluster %}google-beta{% else %}google{% endif %}"
2121
name = "${var.network}"
2222
project = "${local.network_project_id}"
2323
}
2424

2525
data "google_compute_subnetwork" "gke_subnetwork" {
26-
provider = "{% if private_cluster %}google-beta{%else %}google{% endif %}"
26+
provider = "{% if private_cluster %}google-beta{% else %}google{% endif %}"
2727
name = "${var.subnetwork}"
2828
region = "${var.region}"
2929
project = "${local.network_project_id}"

Diff for: autogen/outputs.tf

+12-1
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,21 @@ output "service_account" {
113113
value = "${local.service_account}"
114114
}
115115

116+
{% if beta_cluster %}
117+
output "istio_enabled" {
118+
description = "Whether Istio is enabled"
119+
value = "${local.cluster_istio_enabled}"
120+
}
121+
122+
output "cloudrun_enabled" {
123+
description = "Whether CloudRun enabled"
124+
value = "${local.cluster_cloudrun_enabled}"
125+
}
126+
{% endif %}
127+
116128
{% if private_cluster %}
117129
output "pod_security_policy_enabled" {
118130
description = "Whether pod security policy is enabled"
119131
value = "${local.cluster_pod_security_policy_enabled}"
120132
}
121-
122133
{% endif %}

Diff for: autogen/variables.tf

+13-1
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ variable "service_account" {
251251
description = "The service account to run nodes as if not overridden in `node_pools`. The default value will cause a cluster-specific service account to be created."
252252
default = "create"
253253
}
254-
{% if private_cluster %}
255254

255+
{% if private_cluster %}
256256
variable "deploy_using_private_endpoint" {
257257
description = "(Beta) A toggle for Terraform and kubectl to connect to the master's internal IP address during deployment."
258258
default = "false"
@@ -274,6 +274,18 @@ variable "master_ipv4_cidr_block" {
274274
}
275275
{% endif %}
276276

277+
{% if beta_cluster %}
278+
variable "istio" {
279+
description = "(Beta) Enable Istio addon"
280+
default = false
281+
}
282+
283+
variable "cloudrun" {
284+
description = "(Beta) Enable CloudRun addon"
285+
default = false
286+
}
287+
{% endif %}
288+
277289
variable "basic_auth_username" {
278290
description = "The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration."
279291
default = ""

Diff for: examples/simple_regional_beta/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Simple Regional Cluster
2+
3+
This example illustrates how to create a simple cluster with beta features.
4+
5+
[^]: (autogen_docs_start)
6+
7+
## Inputs
8+
9+
| Name | Description | Type | Default | Required |
10+
|------|-------------|:----:|:-----:|:-----:|
11+
| cluster\_name\_suffix | A suffix to append to the default cluster name | string | `""` | no |
12+
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | string | n/a | yes |
13+
| credentials\_path | The path to the GCP credentials JSON file | string | n/a | yes |
14+
| ip\_range\_pods | The secondary ip range to use for pods | string | n/a | yes |
15+
| ip\_range\_services | The secondary ip range to use for pods | string | n/a | yes |
16+
| network | The VPC network to host the cluster in | string | n/a | yes |
17+
| project\_id | The project ID to host the cluster in | string | n/a | yes |
18+
| region | The region to host the cluster in | string | n/a | yes |
19+
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
20+
21+
## Outputs
22+
23+
| Name | Description |
24+
|------|-------------|
25+
| ca\_certificate | |
26+
| client\_token | |
27+
| cluster\_name | Cluster name |
28+
| credentials\_path | |
29+
| ip\_range\_pods | The secondary IP range used for pods |
30+
| ip\_range\_services | The secondary IP range used for services |
31+
| kubernetes\_endpoint | |
32+
| location | |
33+
| master\_kubernetes\_version | The master Kubernetes version |
34+
| network | |
35+
| project\_id | |
36+
| region | |
37+
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
38+
| subnetwork | |
39+
| zones | List of zones in which the cluster resides |
40+
41+
[^]: (autogen_docs_end)
42+
43+
To provision this example, run the following from within this directory:
44+
- `terraform init` to get the plugins
45+
- `terraform plan` to see the infrastructure plan
46+
- `terraform apply` to apply the infrastructure build
47+
- `terraform destroy` to destroy the built infrastructure

Diff for: examples/simple_regional_beta/main.tf

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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-beta"
19+
}
20+
21+
provider "google" {
22+
version = "2.3"
23+
credentials = "${file(var.credentials_path)}"
24+
region = "${var.region}"
25+
}
26+
27+
provider "google-beta" {
28+
version = "2.3"
29+
credentials = "${file(var.credentials_path)}"
30+
region = "${var.region}"
31+
}
32+
33+
module "gke" {
34+
source = "../../modules/beta-public-cluster/"
35+
project_id = "${var.project_id}"
36+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
37+
regional = true
38+
region = "${var.region}"
39+
network = "${var.network}"
40+
subnetwork = "${var.subnetwork}"
41+
ip_range_pods = "${var.ip_range_pods}"
42+
ip_range_services = "${var.ip_range_services}"
43+
service_account = "${var.compute_engine_service_account}"
44+
istio = "${var.istio}"
45+
cloudrun = "${var.cloudrun}"
46+
}
47+
48+
data "google_client_config" "default" {}

Diff for: examples/simple_regional_beta/outputs.tf

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 service account to default running nodes as if not overridden in `node_pools`."
33+
value = "${module.gke.service_account}"
34+
}

0 commit comments

Comments
 (0)