Skip to content

Commit ec1b045

Browse files
committed
add example and test fixture for gateway api
1 parent 31c73d2 commit ec1b045

File tree

11 files changed

+309
-0
lines changed

11 files changed

+309
-0
lines changed

.kitchen.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ suites:
8080
systems:
8181
- name: simple_regional_private
8282
backend: local
83+
- name: "simple_regional_with_gateway_api"
84+
driver:
85+
root_module_directory: test/fixtures/simple_regional_with_gateway_api
86+
verifier:
87+
systems:
88+
- name: simple_regional_with_gateway_api
89+
backend: local
8390
- name: "simple_regional_with_kubeconfig"
8491
driver:
8592
root_module_directory: test/fixtures/simple_regional_with_kubeconfig
Lines changed: 47 additions & 0 deletions
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.
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\_binary\_authorization | Enable BinAuthZ Admission controller | `bool` | `false` | no |
13+
| gateway\_api\_channel | The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`. | `string` | `null` | no |
14+
| ip\_range\_pods | The secondary ip range to use for pods | `any` | n/a | yes |
15+
| ip\_range\_services | The secondary ip range to use for services | `any` | n/a | yes |
16+
| network | The VPC network to host the cluster in | `any` | n/a | yes |
17+
| project\_id | The project ID to host the cluster in | `any` | n/a | yes |
18+
| region | The region to host the cluster in | `any` | n/a | yes |
19+
| skip\_provisioners | Flag to skip local-exec provisioners | `bool` | `false` | no |
20+
| subnetwork | The subnetwork to host the cluster in | `any` | n/a | yes |
21+
22+
## Outputs
23+
24+
| Name | Description |
25+
|------|-------------|
26+
| ca\_certificate | n/a |
27+
| client\_token | n/a |
28+
| cluster\_name | Cluster name |
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 | n/a |
32+
| location | n/a |
33+
| master\_kubernetes\_version | The master Kubernetes version |
34+
| network | n/a |
35+
| project\_id | n/a |
36+
| region | n/a |
37+
| service\_account | The default service account used for running nodes. |
38+
| subnetwork | n/a |
39+
| zones | List of zones in which the cluster resides |
40+
41+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
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
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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"
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+
module "gke" {
30+
source = "../../"
31+
project_id = var.project_id
32+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
33+
regional = true
34+
region = var.region
35+
network = var.network
36+
subnetwork = var.subnetwork
37+
ip_range_pods = var.ip_range_pods
38+
ip_range_services = var.ip_range_services
39+
create_service_account = false
40+
service_account = var.compute_engine_service_account
41+
enable_cost_allocation = true
42+
enable_binary_authorization = var.enable_binary_authorization
43+
skip_provisioners = var.skip_provisioners
44+
gateway_api_channel = var.gateway_api_channel
45+
}
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 "skip_provisioners" {
51+
type = bool
52+
description = "Flag to skip local-exec provisioners"
53+
default = false
54+
}
55+
56+
variable "enable_binary_authorization" {
57+
description = "Enable BinAuthZ Admission controller"
58+
default = false
59+
}
60+
61+
variable "gateway_api_channel" {
62+
type = string
63+
description = "The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`."
64+
default = null
65+
}
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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_with_gateway_api"
19+
20+
project_id = var.project_ids[0]
21+
cluster_name_suffix = "-${random_string.suffix.result}"
22+
region = var.region
23+
network = google_compute_network.main.name
24+
subnetwork = google_compute_subnetwork.main.name
25+
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
26+
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
27+
compute_engine_service_account = var.compute_engine_service_accounts[0]
28+
skip_provisioners = true
29+
enable_binary_authorization = true
30+
gateway_api_channel = "CHANNEL_STANDARD"
31+
}
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+
resource "random_string" "suffix" {
18+
length = 4
19+
special = false
20+
upper = false
21+
}
22+
23+
provider "google" {
24+
project = var.project_ids[0]
25+
}
26+
27+
resource "google_compute_network" "main" {
28+
name = "cft-gke-test-${random_string.suffix.result}"
29+
auto_create_subnetworks = false
30+
}
31+
32+
resource "google_compute_subnetwork" "main" {
33+
name = "cft-gke-test-${random_string.suffix.result}"
34+
ip_cidr_range = "10.0.0.0/17"
35+
region = var.region
36+
network = google_compute_network.main.self_link
37+
38+
secondary_ip_range {
39+
range_name = "cft-gke-test-pods-${random_string.suffix.result}"
40+
ip_cidr_range = "192.168.0.0/18"
41+
}
42+
43+
secondary_ip_range {
44+
range_name = "cft-gke-test-services-${random_string.suffix.result}"
45+
ip_cidr_range = "192.168.64.0/18"
46+
}
47+
}
48+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/outputs.tf
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/variables.tf

0 commit comments

Comments
 (0)