Skip to content

Commit 2124137

Browse files
authored
Merge pull request #310 from ideasculptor/private_zonal_example
Private zonal example
2 parents d27cc7a + 1e1ed91 commit 2124137

File tree

13 files changed

+636
-0
lines changed

13 files changed

+636
-0
lines changed

.kitchen.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ suites:
5252
systems:
5353
- name: simple_regional
5454
backend: local
55+
- name: "private_zonal_with_networking"
56+
driver:
57+
root_module_directory: test/fixtures/private_zonal_with_networking
58+
verifier:
59+
systems:
60+
- name: private_zonal_with_networking
61+
backend: local
62+
controls:
63+
- gcloud
64+
- name: private_zonal_with_networking
65+
backend: local
66+
controls:
67+
- subnet
68+
- name: network
69+
backend: gcp
70+
controls:
71+
- network
5572
- name: "simple_regional_with_networking"
5673
driver:
5774
root_module_directory: test/fixtures/simple_regional_with_networking
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 = var.subnetwork
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+
61+
// This craziness gets a plain network name from the reference link which is the
62+
// only way to force cluster creation to wait on network creation without a
63+
// depends_on link. Tests use terraform 0.12.6, which does not have regex or regexall
64+
network = reverse(split("/", data.google_compute_subnetwork.subnetwork.network))[0]
65+
66+
subnetwork = data.google_compute_subnetwork.subnetwork.name
67+
ip_range_pods = var.ip_range_pods_name
68+
ip_range_services = var.ip_range_services_name
69+
create_service_account = true
70+
enable_private_endpoint = true
71+
enable_private_nodes = true
72+
master_ipv4_cidr_block = "172.16.0.0/28"
73+
74+
master_authorized_networks_config = [
75+
{
76+
cidr_blocks = [
77+
{
78+
cidr_block = data.google_compute_subnetwork.subnetwork.ip_cidr_range
79+
display_name = "VPC"
80+
},
81+
]
82+
},
83+
]
84+
}
85+
86+
data "google_client_config" "default" {
87+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
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 "network" {
25+
value = var.network
26+
}
27+
28+
output "subnetwork" {
29+
value = var.subnetwork
30+
}
31+
32+
output "location" {
33+
value = module.gke.location
34+
}
35+
36+
output "region" {
37+
value = var.region
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+
}
29+
30+
variable "zones" {
31+
type = list(string)
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 created to host the cluster in"
37+
default = "gke-network"
38+
}
39+
40+
variable "subnetwork" {
41+
description = "The subnetwork created to host the cluster in"
42+
default = "gke-subnet"
43+
}
44+
45+
variable "ip_range_pods_name" {
46+
description = "The secondary ip range to use for pods"
47+
default = "ip-range-pods"
48+
}
49+
50+
variable "ip_range_services_name" {
51+
description = "The secondary ip range to use for pods"
52+
default = "ip-range-scv"
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+
}

0 commit comments

Comments
 (0)