File tree Expand file tree Collapse file tree 12 files changed +198
-3
lines changed
integration/default/inspec Expand file tree Collapse file tree 12 files changed +198
-3
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ resource "google_container_cluster" "primary" {
24
24
project = " ${ var . project_id } "
25
25
26
26
region = " ${ var . region } "
27
- additional_zones = " ${ var . zones } "
27
+ additional_zones = [ " ${ coalescelist ( compact ( var. zones ), data . google_compute_zones . available . names ) } " ]
28
28
29
29
network = " ${ data . google_compute_network . gke_network . self_link } "
30
30
subnetwork = " ${ data . google_compute_subnetwork . gke_subnetwork . self_link } "
Original file line number Diff line number Diff line change
1
+ # Simple Regional Cluster
2
+
3
+ This example illustrates how to create a simple cluster.
4
+
5
+ Expected variables:
6
+ - ` project_id `
7
+ - ` region `
8
+ - ` network `
9
+ - ` subnetwork `
10
+ - ` ip_range_pods `
11
+ - ` ip_range_services `
12
+
13
+ To provision this example, run the following from within this directory:
14
+ - ` terraform init ` to get the plugins
15
+ - ` terraform plan ` to see the infrastructure plan
16
+ - ` terraform apply ` to apply the infrastructure build
17
+ - ` terraform destroy ` to destroy the built infrastructure
Original file line number Diff line number Diff line change
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
+ credentials_file_path = " ${ path . module } /sa-key.json"
19
+ }
20
+
21
+ provider "google" {
22
+ credentials = " ${ file (local. credentials_file_path )} "
23
+ region = " us-east4" # TODO remove
24
+ }
25
+
26
+ module "gke" {
27
+ source = " ../../"
28
+ project_id = " ${ var . project_id } "
29
+ name = " simple-regional-cluster"
30
+ regional = true
31
+ region = " ${ var . region } "
32
+ network = " ${ var . network } "
33
+ subnetwork = " ${ var . subnetwork } "
34
+ ip_range_pods = " ${ var . ip_range_pods } "
35
+ ip_range_services = " ${ var . ip_range_services } "
36
+ }
Original file line number Diff line number Diff line change
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 "name_example" {
18
+ description = " Cluster name"
19
+ value = " ${ module . gke . name } "
20
+ }
21
+
22
+ output "endpoint_example" {
23
+ sensitive = true
24
+ description = " Cluster endpoint"
25
+ value = " ${ module . gke . endpoint } "
26
+ }
27
+
28
+ output "location_example" {
29
+ description = " Cluster location"
30
+ value = " ${ module . gke . location } "
31
+ }
Original file line number Diff line number Diff line change
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 "region" {
22
+ description = " The region to host the cluster in"
23
+ }
24
+
25
+ variable "network" {
26
+ description = " The VPC network to host the cluster in"
27
+ }
28
+
29
+ variable "subnetwork" {
30
+ description = " The subnetwork to host the cluster in"
31
+ }
32
+
33
+ variable "ip_range_pods" {
34
+ description = " The secondary ip range to use for pods"
35
+ }
36
+
37
+ variable "ip_range_services" {
38
+ description = " The secondary ip range to use for pods"
39
+ }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ locals {
20
20
21
21
provider "google" {
22
22
credentials = " ${ file (local. credentials_file_path )} "
23
+ region = " ${ var . region } "
23
24
}
24
25
25
26
module "gke" {
Original file line number Diff line number Diff line change 15
15
ruby '2.4.2'
16
16
17
17
source 'https://rubygems.org/' do
18
+ gem 'googleauth'
19
+ gem 'google-api-client'
18
20
gem 'kitchen-terraform' , '~> 3.3'
19
21
gem 'kitchen-inspec' , :git => 'https://github.com/inspec/kitchen-inspec.git' , :ref => '0590f1b'
20
22
end
Original file line number Diff line number Diff line change @@ -27,18 +27,34 @@ function export_vars() {
27
27
export TEST_ID=" modules_gke_integration_gcloud_${RANDOM} "
28
28
export KUBECONFIG=" ${TEMPDIR} /${CLUSTER_TYPE} /${TEST_ID} .kubeconfig"
29
29
if [[ $CLUSTER_TYPE = " regional" ]]; then
30
+ if [ -f " ./regional_config.sh" ]; then
31
+ source ./regional_config.sh
32
+ fi
30
33
export CLUSTER_REGIONAL=" true"
31
34
export CLUSTER_LOCATION=" $REGIONAL_LOCATION "
32
35
export CLUSTER_NAME=" $REGIONAL_CLUSTER_NAME "
33
36
export IP_RANGE_PODS=" $REGIONAL_IP_RANGE_PODS "
34
37
export IP_RANGE_SERVICES=" $REGIONAL_IP_RANGE_SERVICES "
35
38
else
39
+ if [ -f " ./zonal_config.sh" ]; then
40
+ source ./zonal_config.sh
41
+ fi
42
+ if [ -z " ${ZONE} " ]; then
43
+ echo " Can not create a zonal cluster without specifying \$ ZONE. Aborting..."
44
+ exit 1
45
+ fi
36
46
export CLUSTER_REGIONAL=" false"
37
47
export CLUSTER_LOCATION=" $ZONAL_LOCATION "
38
48
export CLUSTER_NAME=" $ZONAL_CLUSTER_NAME "
39
49
export IP_RANGE_PODS=" $ZONAL_IP_RANGE_PODS "
40
50
export IP_RANGE_SERVICES=" $ZONAL_IP_RANGE_SERVICES "
41
51
fi
52
+
53
+ if [ " ${ZONE} " = " " ] && [ " ${ADDITIONAL_ZONES} " = " " ]; then
54
+ export ZONES=" "
55
+ else
56
+ export ZONES=" \" $ZONE \" ,$ADDITIONAL_ZONES "
57
+ fi
42
58
}
43
59
44
60
# Activate test working directory
Original file line number Diff line number Diff line change @@ -34,11 +34,11 @@ export CLUSTER_NAME="int-test-cluster-01"
34
34
export REGION=" us-east4"
35
35
export ZONE=" us-east4-a"
36
36
export ADDITIONAL_ZONES=' "us-east4-b","us-east4-c"'
37
- export ZONES=" \" $ZONE \" ,$ADDITIONAL_ZONES "
38
37
export KUBERNETES_VERSION=" 1.10.6-gke.2"
39
38
export NODE_POOL_SERVICE_ACCOUNT=" "
40
39
export REGIONAL_CLUSTER_NAME=" int-test-regional-01"
41
40
export REGIONAL_LOCATION=" $REGION "
42
41
export ZONAL_CLUSTER_NAME=" int-test-zonal-01"
43
42
export ZONAL_LOCATION=" $ZONE "
44
43
export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=$CREDENTIALS_PATH
44
+ export GOOGLE_APPLICATION_CREDENTIALS=$CREDENTIALS_PATH
Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ require_relative '../../../../test/support/google_cloud.rb'
16
+
15
17
# Test the name output
16
18
describe command ( 'terraform output name_example' ) do
17
19
its ( 'stdout.strip' ) { should eq ENV [ 'CLUSTER_NAME' ] }
34
36
35
37
# Test the zones output
36
38
describe command ( 'terraform output -json zones_example | jq -cre \'.value\'' ) do
37
- its ( 'stdout.strip' ) { should eq '[' + ENV [ 'ZONES' ] + ']' }
39
+ if ENV [ 'ZONES' ] != ''
40
+ its ( 'stdout.strip' ) { should eq '[' + ENV [ 'ZONES' ] + ']' }
41
+ else
42
+ its ( 'stdout.strip' ) { should eq google_compute_service . get_region ( ENV [ 'PROJECT_ID' ] , ENV [ 'REGION' ] ) . zones . map { |z | z . split ( "/" ) . last } . to_json }
43
+ end
38
44
end
39
45
40
46
# Test the endpoint output
Original file line number Diff line number Diff line change
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'googleauth'
16
+ require 'google/apis/compute_v1'
17
+
18
+ def google_compute_service
19
+ Google ::Apis ::ComputeV1 ::ComputeService . new . tap do |service |
20
+ service . authorization = Google ::Auth . get_application_default ( [ 'https://www.googleapis.com/auth/cloud-platform' ] )
21
+ end
22
+ end
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
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
+ # ################################################################
18
+ # PLEASE FILL THE VARIABLES WITH VALID VALUES FOR TESTING #
19
+ # DO NOT REMOVE ANY OF THE VARIABLES #
20
+ # ################################################################
21
+
22
+ export ZONE=" us-east4-a"
23
+ export ADDITIONAL_ZONES=' "us-east4-b","us-east4-c"'
24
+ export ZONAL_LOCATION=" $ZONE "
25
+
You can’t perform that action at this time.
0 commit comments