Skip to content

Commit d969d86

Browse files
committed
add private_zonal_with_networking example
1 parent e3494d7 commit d969d86

File tree

13 files changed

+706
-0
lines changed

13 files changed

+706
-0
lines changed

.kitchen.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ suites:
6868
systems:
6969
- name: simple_regional
7070
backend: local
71+
- name: "private_zonal_with_networking"
72+
driver:
73+
root_module_directory: test/fixtures/private_zonal_with_networking
74+
verifier:
75+
systems:
76+
- name: private_zonal_with_networking
77+
backend: local
78+
controls:
79+
- gcloud
80+
- name: subnet
81+
backend: local
82+
controls:
83+
- subnet
84+
- name: network
85+
backend: gcp
86+
controls:
87+
- network
7188
- name: "simple_regional_with_networking"
7289
driver:
7390
root_module_directory: test/fixtures/simple_regional_with_networking
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright 2019 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 "gcp-network" {
18+
source = "terraform-google-modules/network/google"
19+
version = "~> 1.4.0"
20+
project_id = var.project_id
21+
network_name = var.network
22+
23+
subnets = [
24+
{
25+
subnet_name = var.subnetwork
26+
subnet_ip = "10.0.0.0/17"
27+
subnet_region = var.region
28+
subnet_private_access = "true"
29+
},
30+
]
31+
32+
secondary_ranges = {
33+
"${var.subnetwork}" = [
34+
{
35+
range_name = var.ip_range_pods_name
36+
ip_cidr_range = "192.168.0.0/18"
37+
},
38+
{
39+
range_name = var.ip_range_services_name
40+
ip_cidr_range = "192.168.64.0/18"
41+
},
42+
]
43+
}
44+
}
45+
46+
data "google_compute_subnetwork" "subnetwork" {
47+
name = module.gcp-network.subnets_names[0]
48+
project = var.project_id
49+
region = var.region
50+
depends_on = [module.gcp-network]
51+
}
52+
53+
module "gke" {
54+
source = "../../modules/beta-private-cluster/"
55+
project_id = var.project_id
56+
name = var.cluster_name
57+
regional = false
58+
region = var.region
59+
zones = slice(var.zones, 0, 1)
60+
network = data.google_compute_subnetwork.subnetwork.network
61+
subnetwork = data.google_compute_subnetwork.subnetwork.name
62+
ip_range_pods = var.ip_range_pods_name
63+
ip_range_services = var.ip_range_services_name
64+
create_service_account = true
65+
enable_private_endpoint = true
66+
enable_private_nodes = true
67+
master_ipv4_cidr_block = "172.16.0.0/28"
68+
69+
master_authorized_networks_config = [
70+
{
71+
cidr_blocks = [
72+
{
73+
cidr_block = data.google_compute_subnetwork.subnetwork.ip_cidr_range
74+
display_name = "VPC"
75+
},
76+
]
77+
},
78+
]
79+
}
80+
81+
data "google_client_config" "default" {
82+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2019 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+
description = "The cluster endpoint"
19+
sensitive = true
20+
value = module.gke.endpoint
21+
}
22+
23+
output "client_token" {
24+
description = "The bearer token for auth"
25+
sensitive = true
26+
value = base64encode(data.google_client_config.default.access_token)
27+
}
28+
29+
output "ca_certificate" {
30+
description = "The cluster ca certificate (base64 encoded)"
31+
value = module.gke.ca_certificate
32+
}
33+
34+
output "service_account" {
35+
description = "The default service account used for running nodes."
36+
value = module.gke.service_account
37+
}
38+
39+
output "cluster_name" {
40+
description = "Cluster name"
41+
value = module.gke.name
42+
}
43+
44+
output "network_name" {
45+
description = "The name of the VPC being created"
46+
value = module.gcp-network.network_name
47+
}
48+
49+
output "subnet_name" {
50+
description = "The name of the subnet being created"
51+
value = module.gcp-network.subnets_names
52+
}
53+
54+
output "subnet_secondary_ranges" {
55+
description = "The secondary ranges associated with the subnet"
56+
value = module.gcp-network.subnets_secondary_ranges
57+
}
58+
59+
60+
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 "network" {
29+
value = var.network
30+
}
31+
32+
output "subnetwork" {
33+
value = var.subnetwork
34+
}
35+
36+
output "location" {
37+
value = module.gke.location
38+
}
39+
40+
output "ip_range_pods_name" {
41+
description = "The secondary IP range used for pods"
42+
value = var.ip_range_pods_name
43+
}
44+
45+
output "ip_range_services_name" {
46+
description = "The secondary IP range used for services"
47+
value = var.ip_range_services_name
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2019 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" {
22+
description = "The name for the GKE cluster"
23+
default = "gke-on-vpc-cluster"
24+
}
25+
26+
variable "region" {
27+
description = "The region to host the cluster in"
28+
default = "us-central1"
29+
}
30+
31+
variable "network" {
32+
description = "The VPC network created to host the cluster in"
33+
default = "gke-network"
34+
}
35+
36+
variable "subnetwork" {
37+
description = "The subnetwork created to host the cluster in"
38+
default = "gke-subnet"
39+
}
40+
41+
variable "ip_range_pods_name" {
42+
description = "The secondary ip range to use for pods"
43+
default = "ip-range-pods"
44+
}
45+
46+
variable "ip_range_services_name" {
47+
description = "The secondary ip range to use for pods"
48+
default = "ip-range-scv"
49+
}
50+
51+
variable "zones" {
52+
default = []
53+
}
54+
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: "private-zonal-with-networking-local"
16+
COMPUTE_ENGINE_SERVICE_ACCOUNT: ""
17+
REGION: "us-east4"
18+
ZONES: '["us-east4-a", "us-east4-b", "us-east4-c"]'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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/private_zonal_with_networking"
19+
20+
project_id = var.project_id
21+
region = var.region
22+
zones = var.zones
23+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright 2019 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+
18+
output "project_id" {
19+
value = var.project_id
20+
}
21+
22+
output "location" {
23+
value = module.example.location
24+
}
25+
26+
output "cluster_name" {
27+
description = "Cluster name"
28+
value = module.example.cluster_name
29+
}
30+
31+
output "kubernetes_endpoint" {
32+
sensitive = true
33+
value = module.example.kubernetes_endpoint
34+
}
35+
36+
output "client_token" {
37+
sensitive = true
38+
value = module.example.client_token
39+
}
40+
41+
output "ca_certificate" {
42+
value = module.example.ca_certificate
43+
}
44+
45+
output "service_account" {
46+
description = "The default service account used for running nodes."
47+
value = module.example.service_account
48+
}
49+
50+
output "network_name" {
51+
description = "The name of the VPC being created"
52+
value = module.example.network
53+
}
54+
55+
output "subnet_name" {
56+
description = "The name of the subnet being created"
57+
value = module.example.subnetwork
58+
}
59+
60+
output "region" {
61+
description = "The region the cluster is hosted in"
62+
value = module.example.region
63+
}
64+
65+
output "ip_range_pods_name" {
66+
description = "The secondary range name for pods"
67+
value = module.example.ip_range_pods_name
68+
}
69+
70+
output "ip_range_services_name" {
71+
description = "The secondary range name for services"
72+
value = module.example.ip_range_services_name
73+
}

0 commit comments

Comments
 (0)