Skip to content

Commit ab0d07f

Browse files
committed
chore: Add example as requested in pr-review
1 parent 9cce603 commit ab0d07f

File tree

23 files changed

+323
-0
lines changed

23 files changed

+323
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Simple Regional Cluster
2+
3+
This example illustrates how to create a simple private cluster.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| cluster\_name\_suffix | A suffix to append to the default cluster name | `string` | `""` | no |
11+
| compute\_engine\_service\_account | Service account to associate to the nodes in the cluster | `any` | n/a | yes |
12+
| enable\_k8s\_beta\_apis | K8S beta apis to enable within the cluster | `any` | n/a | yes |
13+
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
14+
| network | The VPC network to host the cluster in | `any` | n/a | yes |
15+
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
16+
| region | The region to host the cluster in | `any` | n/a | yes |
17+
| subnetwork | The subnetwork to host the cluster in | `any` | n/a | yes |
18+
19+
## Outputs
20+
21+
| Name | Description |
22+
|------|-------------|
23+
| ca\_certificate | n/a |
24+
| client\_token | n/a |
25+
| cluster\_name | Cluster name |
26+
| ip\_range\_pods | The secondary IP range used for pods |
27+
| kubernetes\_endpoint | n/a |
28+
| location | n/a |
29+
| master\_kubernetes\_version | The master Kubernetes version |
30+
| network | n/a |
31+
| project\_id | n/a |
32+
| region | n/a |
33+
| service\_account | The default service account used for running nodes. |
34+
| subnetwork | n/a |
35+
| zones | List of zones in which the cluster resides |
36+
37+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
38+
39+
To provision this example, run the following from within this directory:
40+
- `terraform init` to get the plugins
41+
- `terraform plan` to see the infrastructure plan
42+
- `terraform apply` to apply the infrastructure build
43+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 = "terraform-google-modules/kubernetes-engine/google//modules/private-cluster"
37+
version = "~> 37.0"
38+
39+
project_id = var.project_id
40+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
41+
regional = true
42+
region = var.region
43+
network = var.network
44+
subnetwork = var.subnetwork
45+
ip_range_pods = var.ip_range_pods
46+
create_service_account = false
47+
service_account = var.compute_engine_service_account
48+
enable_private_endpoint = true
49+
enable_private_nodes = true
50+
enable_secret_manager_addon = true
51+
default_max_pods_per_node = 20
52+
remove_default_node_pool = true
53+
deletion_protection = false
54+
enable_k8s_beta_apis = var.enable_k8s_beta_apis
55+
56+
node_pools = [
57+
{
58+
name = "pool-01"
59+
min_count = 1
60+
max_count = 100
61+
local_ssd_count = 0
62+
disk_size_gb = 100
63+
disk_type = "pd-standard"
64+
auto_repair = true
65+
auto_upgrade = true
66+
service_account = var.compute_engine_service_account
67+
preemptible = false
68+
max_pods_per_node = 12
69+
},
70+
]
71+
72+
master_authorized_networks = [
73+
{
74+
cidr_block = data.google_compute_subnetwork.subnetwork.ip_cidr_range
75+
display_name = "VPC"
76+
},
77+
]
78+
}
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
// These outputs are used to test the module with kitchen-terraform
18+
// They do not need to be included in real-world uses of this module
19+
20+
output "project_id" {
21+
value = var.project_id
22+
}
23+
24+
output "region" {
25+
value = module.gke.region
26+
}
27+
28+
output "cluster_name" {
29+
description = "Cluster name"
30+
value = module.gke.name
31+
}
32+
33+
output "network" {
34+
value = var.network
35+
}
36+
37+
output "subnetwork" {
38+
value = var.subnetwork
39+
}
40+
41+
output "location" {
42+
value = module.gke.location
43+
}
44+
45+
output "ip_range_pods" {
46+
description = "The secondary IP range used for pods"
47+
value = var.ip_range_pods
48+
}
49+
50+
output "zones" {
51+
description = "List of zones in which the cluster resides"
52+
value = module.gke.zones
53+
}
54+
55+
output "master_kubernetes_version" {
56+
description = "The master Kubernetes version"
57+
value = module.gke.master_version
58+
}
Lines changed: 48 additions & 0 deletions
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+
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 "compute_engine_service_account" {
43+
description = "Service account to associate to the nodes in the cluster"
44+
}
45+
46+
variable "enable_k8s_beta_apis" {
47+
description = "K8S beta apis to enable within the cluster"
48+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}
22+
kubernetes = {
23+
source = "hashicorp/kubernetes"
24+
}
25+
}
26+
required_version = ">= 0.13"
27+
}

metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ spec:
118118
location: examples/simple_regional_private
119119
- name: simple_regional_private_beta
120120
location: examples/simple_regional_private_beta
121+
- name: simple_regional_private_with_beta_apis
122+
location: examples/simple_regional_private_with_beta_apis
121123
- name: simple_regional_private_with_cluster_version
122124
location: examples/simple_regional_private_with_cluster_version
123125
- name: simple_regional_with_gateway_api

modules/auth/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ spec:
8484
location: examples/simple_regional_private
8585
- name: simple_regional_private_beta
8686
location: examples/simple_regional_private_beta
87+
- name: simple_regional_private_with_beta_apis
88+
location: examples/simple_regional_private_with_beta_apis
8789
- name: simple_regional_private_with_cluster_version
8890
location: examples/simple_regional_private_with_cluster_version
8991
- name: simple_regional_with_gateway_api

modules/beta-autopilot-private-cluster/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ spec:
8484
location: examples/simple_regional_private
8585
- name: simple_regional_private_beta
8686
location: examples/simple_regional_private_beta
87+
- name: simple_regional_private_with_beta_apis
88+
location: examples/simple_regional_private_with_beta_apis
8789
- name: simple_regional_private_with_cluster_version
8890
location: examples/simple_regional_private_with_cluster_version
8991
- name: simple_regional_with_gateway_api

modules/beta-autopilot-public-cluster/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ spec:
8484
location: examples/simple_regional_private
8585
- name: simple_regional_private_beta
8686
location: examples/simple_regional_private_beta
87+
- name: simple_regional_private_with_beta_apis
88+
location: examples/simple_regional_private_with_beta_apis
8789
- name: simple_regional_private_with_cluster_version
8890
location: examples/simple_regional_private_with_cluster_version
8991
- name: simple_regional_with_gateway_api

0 commit comments

Comments
 (0)