Skip to content

Commit 90a122e

Browse files
committed
Bring back shared_vpc example and simple test fixture
1 parent a4a3f71 commit 90a122e

File tree

14 files changed

+289
-1
lines changed

14 files changed

+289
-1
lines changed

.kitchen.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ suites:
4848
backend: local
4949
provisioner:
5050
name: terraform
51+
- name: "shared_vpc"
52+
driver:
53+
name: "terraform"
54+
command_timeout: 1800
55+
root_module_directory: test/fixtures/shared_vpc
56+
verifier:
57+
name: terraform
58+
systems:
59+
- name: shared_vpc
60+
backend: local
61+
provisioner:
62+
name: terraform
5163
- name: "simple_regional"
5264
driver:
5365
name: "terraform"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ make generate_docs
212212

213213
Integration tests are run though [test-kitchen](https://github.com/test-kitchen/test-kitchen), [kitchen-terraform](https://github.com/newcontext-oss/kitchen-terraform), and [InSpec](https://github.com/inspec/inspec).
214214

215-
Five test-kitchen instances are defined:
215+
Six test-kitchen instances are defined:
216216

217217
- `deploy_service`
218218
- `node_pool`
219+
- `shared_vpc`
219220
- `simple_regional`
220221
- `simple_zonal`
221222
- `stub_domains`

examples/shared_vpc/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Shared VPC Cluster
2+
3+
This example illustrates how to create a simple cluster where the host network is not necessarily in the same project as the cluster.
4+
5+
[^]: (autogen_docs_start)
6+
7+
[^]: (autogen_docs_end)
8+
9+
To provision this example, run the following from within this directory:
10+
- `terraform init` to get the plugins
11+
- `terraform plan` to see the infrastructure plan
12+
- `terraform apply` to apply the infrastructure build
13+
- `terraform destroy` to destroy the built infrastructure

examples/shared_vpc/main.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 = "shared-vpc"
19+
}
20+
21+
provider "google" {
22+
credentials = "${file(var.credentials_path)}"
23+
region = "${var.region}"
24+
}
25+
26+
module "gke" {
27+
source = "../../"
28+
project_id = "${var.project_id}"
29+
name = "${local.cluster_type}-cluster"
30+
region = "${var.region}"
31+
network = "${var.network}"
32+
network_project_id = "${var.network_project_id}"
33+
subnetwork = "${var.subnetwork}"
34+
ip_range_pods = "${var.ip_range_pods}"
35+
ip_range_services = "${var.ip_range_services}"
36+
kubernetes_version = "1.11.5-gke.4"
37+
node_version = "1.11.5-gke.4"
38+
service_account = "${var.compute_engine_service_account}"
39+
}
40+
41+
data "google_client_config" "default" {}

examples/shared_vpc/outputs.tf

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+
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+
}

examples/shared_vpc/test_outputs.tf

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

examples/shared_vpc/variables.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "credentials_path" {
22+
description = "The path to the GCP credentials JSON file"
23+
}
24+
25+
variable "region" {
26+
description = "The region to host the cluster in"
27+
}
28+
29+
variable "network" {
30+
description = "The VPC network to host the cluster in"
31+
}
32+
33+
variable "network_project_id" {
34+
description = "The GCP project housing the VPC network to host the cluster in"
35+
}
36+
37+
variable "subnetwork" {
38+
description = "The subnetwork to host the cluster in"
39+
}
40+
41+
variable "ip_range_pods" {
42+
description = "The secondary ip range to use for pods"
43+
}
44+
45+
variable "ip_range_services" {
46+
description = "The secondary ip range to use for pods"
47+
}
48+
49+
variable "compute_engine_service_account" {
50+
description = "Service account to associate to the nodes in the cluster"
51+
}

test/fixtures/shared_vpc/example.tf

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/shared_vpc"
19+
20+
project_id = "${var.project_id}"
21+
credentials_path = "${local.credentials_path}"
22+
region = "${var.region}"
23+
network = "${google_compute_network.main.name}"
24+
network_project_id = "${var.project_id}"
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+
}

test/fixtures/shared_vpc/network.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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_path = "${path.module}/${var.credentials_path_relative}"
19+
}
20+
21+
resource "random_string" "suffix" {
22+
length = 4
23+
special = false
24+
upper = false
25+
}
26+
27+
provider "google" {
28+
credentials = "${file(local.credentials_path)}"
29+
project = "${var.project_id}"
30+
}
31+
32+
resource "google_compute_network" "main" {
33+
name = "cft-gke-test-${random_string.suffix.result}"
34+
auto_create_subnetworks = "false"
35+
}
36+
37+
resource "google_compute_subnetwork" "main" {
38+
name = "cft-gke-test-${random_string.suffix.result}"
39+
ip_cidr_range = "10.0.0.0/17"
40+
region = "${var.region}"
41+
network = "${google_compute_network.main.self_link}"
42+
43+
secondary_ip_range {
44+
range_name = "cft-gke-test-pods-${random_string.suffix.result}"
45+
ip_cidr_range = "192.168.0.0/18"
46+
}
47+
48+
secondary_ip_range {
49+
range_name = "cft-gke-test-services-${random_string.suffix.result}"
50+
ip_cidr_range = "192.168.64.0/18"
51+
}
52+
}

test/fixtures/shared_vpc/outputs.tf

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/terraform.tfvars

test/fixtures/shared_vpc/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/variables.tf
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
project_id = attribute('project_id')
16+
location = attribute('location')
17+
cluster_name = attribute('cluster_name')
18+
19+
credentials_path = attribute('credentials_path')
20+
ENV['CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE'] = credentials_path
21+
22+
control "gcloud" do
23+
title "Google Compute Engine GKE configuration"
24+
describe command("gcloud --project=#{project_id} container clusters --zone=#{location} describe #{cluster_name} --format=json") do
25+
its(:exit_status) { should eq 0 }
26+
its(:stderr) { should eq '' }
27+
28+
let!(:data) do
29+
if subject.exit_status == 0
30+
JSON.parse(subject.stdout)
31+
else
32+
{}
33+
end
34+
end
35+
36+
describe "cluster" do
37+
it "is running" do
38+
expect(data['status']).to eq 'RUNNING'
39+
end
40+
end
41+
end
42+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: shared_vpc
2+
attributes:
3+
- name: project_id
4+
required: true
5+
type: string
6+
- name: credentials_path
7+
required: true
8+
type: string
9+
- name: location
10+
required: true
11+
type: string
12+
- name: cluster_name
13+
required: true
14+
type: string

0 commit comments

Comments
 (0)