Skip to content

Commit f43dd92

Browse files
authored
Merge pull request #28 from glarizza/gl/kitchen_terraform_tests
Migrate integration tests to Test Kitchen
2 parents f359716 + 446ef4c commit f43dd92

File tree

61 files changed

+1287
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1287
-667
lines changed

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
# OSX trash
55
.DS_Store
6-
*.pyc*
6+
7+
# Python
8+
*.pyc
79

810
# Emacs save files
911
*~
@@ -29,8 +31,17 @@ Session.vim
2931
# Crash log files
3032
crash.log
3133

34+
# Kitchen files
35+
**/inspec.lock
36+
**/.kitchen
37+
**/.kitchen.local.yml
38+
**/Gemfile.lock
39+
3240
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
3341
# .tfvars files are managed as part of configuration and so should be included in
3442
# version control.
3543
#
3644
# example.tfvars
45+
test/fixtures/shared/terraform.tfvars
46+
47+
credentials.json

.kitchen.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
---
16+
driver:
17+
name: "terraform"
18+
command_timeout: 1800
19+
20+
provisioner:
21+
name: "terraform"
22+
23+
platforms:
24+
- name: local
25+
26+
suites:
27+
- name: "simple_project"
28+
driver:
29+
name: "terraform"
30+
command_timeout: 1800
31+
root_module_directory: test/fixtures/simple_project/
32+
verifier:
33+
name: terraform
34+
color: true
35+
systems:
36+
- name: inspec-gcp
37+
backend: gcp
38+
controls:
39+
- gcp
40+
- name: local
41+
backend: local
42+
controls:
43+
- gcloud
44+
- name: "simple_project_with_regional_network"
45+
driver:
46+
name: "terraform"
47+
command_timeout: 1800
48+
root_module_directory: test/fixtures/simple_project_with_regional_network/
49+
verifier:
50+
name: terraform
51+
color: true
52+
systems:
53+
- name: inspec-gcp
54+
backend: gcp
55+
controls:
56+
- gcp
57+
- name: "secondary_ranges"
58+
driver:
59+
name: "terraform"
60+
command_timeout: 1800
61+
root_module_directory: test/fixtures/secondary_ranges/
62+
verifier:
63+
name: terraform
64+
color: true
65+
systems:
66+
- name: local
67+
backend: local
68+
controls:
69+
- gcloud
70+
- name: "multi_vpc"
71+
driver:
72+
name: "terraform"
73+
command_timeout: 1800
74+
root_module_directory: test/fixtures/multi_vpc/
75+
verifier:
76+
name: terraform
77+
color: true
78+
systems:
79+
- name: local
80+
backend: local
81+
controls:
82+
- gcloud

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.5.3

Gemfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
ruby '2.5.3'
16+
17+
source 'https://rubygems.org/' do
18+
gem 'kitchen-terraform', '~> 4.3'
19+
end

Makefile

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
# Make will use bash instead of sh
1616
SHELL := /usr/bin/env bash
1717

18+
# Docker build config variables
19+
CREDENTIALS_PATH ?= /cft/workdir/credentials.json
20+
DOCKER_ORG := gcr.io/cloud-foundation-cicd
21+
DOCKER_TAG_BASE_KITCHEN_TERRAFORM ?= 0.11.10_216.0.0_1.19.1_0.1.10
22+
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}
23+
1824
# All is the first target in the file so it will get picked up when you just run 'make' on its own
1925
all: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace generate_docs
2026

@@ -45,10 +51,6 @@ check_docker:
4551
check_base_files:
4652
@source test/make.sh && basefiles
4753

48-
.PHONY: check_shebangs
49-
check_shebangs:
50-
@source test/make.sh && check_bash
51-
5254
.PHONY: check_trailing_whitespace
5355
check_trailing_whitespace:
5456
@source test/make.sh && check_trailing_whitespace
@@ -60,9 +62,73 @@ test_check_headers:
6062

6163
.PHONY: check_headers
6264
check_headers:
63-
@echo "Checking file headers"
64-
@python test/verify_boilerplate.py
65+
@source test/make.sh && check_headers
66+
67+
# Integration tests
68+
.PHONY: test_integration
69+
test_integration:
70+
./test/ci_integration.sh
6571

6672
.PHONY: generate_docs
6773
generate_docs:
6874
@source test/make.sh && generate_docs
75+
76+
# Versioning
77+
.PHONY: version
78+
version:
79+
@source helpers/version-repo.sh
80+
81+
# Run docker
82+
.PHONY: docker_run
83+
docker_run:
84+
docker run --rm -it \
85+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
86+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
87+
-e TF_VAR_project_id \
88+
-v $(CURDIR):/cft/workdir \
89+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
90+
/bin/bash
91+
92+
.PHONY: docker_create
93+
docker_create:
94+
docker run --rm -it \
95+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
96+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
97+
-e TF_VAR_project_id \
98+
-v $(CURDIR):/cft/workdir \
99+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
100+
/bin/bash -c "kitchen create"
101+
102+
.PHONY: docker_converge
103+
docker_converge:
104+
docker run --rm -it \
105+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
106+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
107+
-e TF_VAR_project_id \
108+
-v $(CURDIR):/cft/workdir \
109+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
110+
/bin/bash -c "kitchen converge && kitchen converge"
111+
112+
.PHONY: docker_verify
113+
docker_verify:
114+
docker run --rm -it \
115+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
116+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
117+
-e TF_VAR_project_id \
118+
-v $(CURDIR):/cft/workdir \
119+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
120+
/bin/bash -c "kitchen verify"
121+
122+
.PHONY: docker_destroy
123+
docker_destroy:
124+
docker run --rm -it \
125+
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
126+
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
127+
-e TF_VAR_project_id \
128+
-v $(CURDIR):/cft/workdir \
129+
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
130+
/bin/bash -c "kitchen destroy"
131+
132+
.PHONY: test_integration_docker
133+
test_integration_docker: docker_create docker_converge docker_verify docker_destroy
134+
@echo "Running test-kitchen tests in docker"

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,29 @@ Then perform the following commands on the root folder:
8181
| Name | Description | Type | Default | Required |
8282
|------|-------------|:----:|:-----:|:-----:|
8383
| network_name | The name of the network being created | string | - | yes |
84-
| routing_mode | The network routing mode. Can be either 'REGIONAL' or 'GLOBAL' | string | GLOBAL | no |
8584
| project_id | The ID of the project where this VPC will be created | string | - | yes |
85+
| routes | List of routes being created in this VPC | list | `<list>` | no |
86+
| routing_mode | The network routing mode (default 'GLOBAL') | string | `GLOBAL` | no |
87+
| secondary_ranges | Secondary ranges that will be used in some of the subnets | map | - | yes |
8688
| shared_vpc_host | Makes this project a Shared VPC host if 'true' (default 'false') | string | `false` | no |
8789
| subnets | The list of subnets being created | list | - | yes |
88-
| secondary_ranges | Secondary ranges that will be used in some of the subnets | map | - | yes |
89-
| routes | The list of routes being created | list | - | no |
90+
91+
## Outputs
92+
93+
| Name | Description |
94+
|------|-------------|
95+
| network_name | The name of the VPC being created |
96+
| network_self_link | The URI of the VPC being created |
97+
| routes | The routes associated with this VPC |
98+
| subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
99+
| subnets_ips | The IPs and CIDRs of the subnets being created |
100+
| subnets_names | The names of the subnets being created |
101+
| subnets_private_access | Whether the subnets will have access to Google API's without a public IP |
102+
| subnets_regions | The region where the subnets will be created |
103+
| subnets_secondary_ranges | The secondary ranges associated with these subnets |
104+
| subnets_self_links | The self-links of subnets being created |
105+
106+
[^]: (autogen_docs_end)
90107

91108
### Subnet Inputs
92109
The subnets list contains maps, where each object represents a subnet. Each map has the following inputs (please see examples folder for additional references):
@@ -115,23 +132,6 @@ The routes list contains maps, where each object represents a route. For the nex
115132
| next_hop_vpn_tunnel | URL to a VpnTunnel that should handle matching packets | string | - | yes |
116133
| priority | The priority of this route. Priority is used to break ties in cases where there is more than one matching route of equal prefix length. In the case of two routes with equal prefix length, the one with the lowest-numbered priority value wins | string | 1000 | yes |
117134

118-
## Outputs
119-
120-
| Name | Description |
121-
|------|-------------|
122-
| network_name | The name of the VPC being created |
123-
| network_self_link | The URI of the VPC being created |
124-
| subnets_ips | The IPs and CIDRs of the subnets being created |
125-
| subnets_self_links | The `self_link`s of the subnets being created |
126-
| subnets_names | The names of the subnets being created |
127-
| subnets_private_access | Whether the subnets will have access to Google API's without a public IP |
128-
| subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
129-
| subnets_regions | The region where the subnets will be created |
130-
| subnets_secondary_ranges | The secondary ranges associated with these subnets |
131-
| routes | The routes associated with this VPC |
132-
133-
[^]: (autogen_docs_end)
134-
135135
## Requirements
136136
### Terraform plugins
137137
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x

codelabs/simple/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
117
resource "random_id" "network_id" {
218
byte_length = 8
319
}

examples/multi_vpc/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,25 @@ This example configures a host network project with two separate networks.
1515

1616
| Name | Description |
1717
|------|-------------|
18-
| network_01_name | vpc 1 |
18+
| network_01_name | The name of the VPC network-01 |
19+
| network_01_route_data | The route data for network 01 that was passed into the network module |
20+
| network_01_routes | The routes associated with network-01 |
1921
| network_01_self_link | The URI of the VPC network-01 |
2022
| network_01_subnets | The names of the subnets being created on network-01 |
2123
| network_01_subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
2224
| network_01_subnets_ips | The IP and cidrs of the subnets being created on network-01 |
2325
| network_01_subnets_private_access | Whether the subnets will have access to Google API's without a public IP on network-01 |
2426
| network_01_subnets_regions | The region where the subnets will be created on network-01 |
2527
| network_01_subnets_secondary_ranges | The secondary ranges associated with these subnets on network-01 |
26-
| network_01_routes | The routes associated with network-01 |
27-
| network_02_name | vpc 2 |
28+
| network_02_name | The name of the VPC network-02 |
29+
| network_02_route_data | The route data for network 02 that was passed into the network module |
30+
| network_02_routes | The routes associated with network-02 |
2831
| network_02_self_link | The URI of the VPC network-02 |
2932
| network_02_subnets | The names of the subnets being created on network-02 |
3033
| network_02_subnets_flow_logs | Whether the subnets will have VPC flow logs enabled |
3134
| network_02_subnets_ips | The IP and cidrs of the subnets being created on network-02 |
3235
| network_02_subnets_private_access | Whether the subnets will have access to Google API's without a public IP on network-02 |
3336
| network_02_subnets_regions | The region where the subnets will be created on network-02 |
3437
| network_02_subnets_secondary_ranges | The secondary ranges associated with these subnets on network-02 |
35-
| network_02_routes | The routes associated with network-02 |
3638

37-
[^]: (autogen_docs_end)
39+
[^]: (autogen_docs_end)

0 commit comments

Comments
 (0)