Skip to content

Commit d5df31f

Browse files
committed
Adding tests
1 parent 06820a4 commit d5df31f

File tree

14 files changed

+366
-0
lines changed

14 files changed

+366
-0
lines changed

.kitchen.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ suites:
104104
systems:
105105
- name: stub_domains_private
106106
backend: local
107+
- name: "workload_metadata_config"
108+
driver:
109+
root_module_directory: test/fixtures/workload_metadata_config
110+
verifier:
111+
systems:
112+
- name: workload_metadata_config
113+
backend: local
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Workload Metadata Config Cluster
2+
3+
This example illustrates how to use a cluster with `workload_metadata_config` defined.
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+
| ip\_range\_pods | The secondary ip range to use for pods | string | n/a | yes |
14+
| ip\_range\_services | The secondary ip range to use for pods | string | n/a | yes |
15+
| network | The VPC network to host the cluster in | string | n/a | yes |
16+
| project\_id | The project ID to host the cluster in | string | n/a | yes |
17+
| region | The region to host the cluster in | string | n/a | yes |
18+
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
19+
| zones | The zone to host the cluster in (required if is a zonal cluster) | list | n/a | yes |
20+
21+
## Outputs
22+
23+
| Name | Description |
24+
|------|-------------|
25+
| ca\_certificate | |
26+
| client\_token | |
27+
| cluster\_name | Cluster name |
28+
| ip\_range\_pods | The secondary IP range used for pods |
29+
| ip\_range\_services | The secondary IP range used for services |
30+
| kubernetes\_endpoint | |
31+
| location | |
32+
| master\_kubernetes\_version | The master Kubernetes version |
33+
| network | |
34+
| project\_id | |
35+
| region | |
36+
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. |
37+
| subnetwork | |
38+
| zones | List of zones in which the cluster resides |
39+
40+
[^]: (autogen_docs_end)
41+
42+
To provision this example, run the following from within this directory:
43+
- `terraform init` to get the plugins
44+
- `terraform plan` to see the infrastructure plan
45+
- `terraform apply` to apply the infrastructure build
46+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 = "workload-metadata-private"
19+
}
20+
21+
provider "google-beta" {
22+
version = "~> 2.9.0"
23+
region = "${var.region}"
24+
}
25+
26+
data "google_compute_subnetwork" "subnetwork" {
27+
name = "${var.subnetwork}"
28+
project = "${var.project_id}"
29+
region = "${var.region}"
30+
}
31+
32+
module "gke" {
33+
source = "../../modules/beta-private-cluster/"
34+
project_id = "${var.project_id}"
35+
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
36+
regional = false
37+
region = "${var.region}"
38+
zones = "${var.zones}"
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+
enable_private_endpoint = true
45+
enable_private_nodes = true
46+
master_ipv4_cidr_block = "172.16.0.0/28"
47+
node_metadata = "SECURE"
48+
49+
master_authorized_networks_config = [{
50+
cidr_blocks = [{
51+
cidr_block = "${data.google_compute_subnetwork.subnetwork.ip_cidr_range}"
52+
display_name = "VPC"
53+
}]
54+
}]
55+
}
56+
57+
data "google_client_config" "default" {}
Lines changed: 34 additions & 0 deletions
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+
}
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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 "zones" {
31+
type = "list"
32+
description = "The zone to host the cluster in (required if is a zonal cluster)"
33+
}
34+
35+
variable "network" {
36+
description = "The VPC network to host the cluster in"
37+
}
38+
39+
variable "subnetwork" {
40+
description = "The subnetwork to host the cluster in"
41+
}
42+
43+
variable "ip_range_pods" {
44+
description = "The secondary ip range to use for pods"
45+
}
46+
47+
variable "ip_range_services" {
48+
description = "The secondary ip range to use for pods"
49+
}
50+
51+
variable "compute_engine_service_account" {
52+
description = "Service account to associate to the nodes in the cluster"
53+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
3+
platform: linux
4+
5+
inputs:
6+
- name: pull-request
7+
path: terraform-google-kubernetes-engine
8+
9+
run:
10+
path: make
11+
args: ['test_integration']
12+
dir: terraform-google-kubernetes-engine
13+
14+
params:
15+
SUITE: "workload-metadata-config-local"
16+
COMPUTE_ENGINE_SERVICE_ACCOUNT: ""
17+
REGION: "us-east4"
18+
ZONES: '["us-east4-a", "us-east4-b", "us-east4-c"]'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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/workload_metadata_config"
19+
20+
project_id = "${var.project_id}"
21+
cluster_name_suffix = "-${random_string.suffix.result}"
22+
region = "${var.region}"
23+
zones = ["${slice(var.zones,0,1)}"]
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_account}"
29+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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-beta" {
24+
project = "${var.project_id}"
25+
}
26+
27+
resource "google_compute_network" "main" {
28+
project = "${var.project_id}"
29+
name = "cft-gke-test-${random_string.suffix.result}"
30+
auto_create_subnetworks = "false"
31+
}
32+
33+
resource "google_compute_subnetwork" "main" {
34+
project = "${var.project_id}"
35+
name = "cft-gke-test-${random_string.suffix.result}"
36+
ip_cidr_range = "10.0.0.0/17"
37+
region = "${var.region}"
38+
network = "${google_compute_network.main.self_link}"
39+
40+
secondary_ip_range {
41+
range_name = "cft-gke-test-pods-${random_string.suffix.result}"
42+
ip_cidr_range = "192.168.0.0/18"
43+
}
44+
45+
secondary_ip_range {
46+
range_name = "cft-gke-test-services-${random_string.suffix.result}"
47+
ip_cidr_range = "192.168.64.0/18"
48+
}
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/outputs.tf

0 commit comments

Comments
 (0)