Skip to content

Commit 1556a25

Browse files
Update integration tests to use new approach
* Fix #245 * Fixed lint-tests * Backwards compatibility of the `generate` function * Disabled kitchen test `stub-domains-private-local` (issue #264)
1 parent 6dae1f3 commit 1556a25

File tree

72 files changed

+651
-2424
lines changed

Some content is hidden

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

72 files changed

+651
-2424
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ test/fixtures/*/.terraform
77
test/fixtures/*/terraform.tfstate.d
88
examples/.kitchen
99
examples/*/.terraform
10-
examples/*/terraform.tfstate.d
10+
examples/*/terraform.tfstate.d
11+

.kitchen.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ suites:
9898
systems:
9999
- name: stub_domains
100100
backend: local
101-
- name: stub_domains_private
102-
driver:
103-
root_module_directory: test/fixtures/stub_domains_private
104-
systems:
105-
- name: stub_domains_private
106-
backend: local
101+
# Disabled due to issue #264
102+
# (https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/264)
103+
# - name: stub_domains_private
104+
# driver:
105+
# root_module_directory: test/fixtures/stub_domains_private
106+
# systems:
107+
# - name: stub_domains_private
108+
# backend: local
107109
- name: "upstream_nameservers"
108110
driver:
109111
root_module_directory: test/fixtures/upstream_nameservers

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Contributing
2+
3+
This document provides guidelines for contributing to the module.
4+
5+
## Dependencies
6+
7+
The following dependencies must be installed on the development system:
8+
9+
- [Docker Engine][docker-engine]
10+
- [Google Cloud SDK][google-cloud-sdk]
11+
- [make]
12+
13+
## Generating Documentation for Inputs and Outputs
14+
15+
The Inputs and Outputs tables in the READMEs of the root module,
16+
submodules, and example modules are automatically generated based on
17+
the `variables` and `outputs` of the respective modules. These tables
18+
must be refreshed if the module interfaces are changed.
19+
20+
## Templating
21+
22+
To more cleanly handle cases where desired functionality would require complex duplication of Terraform resources (i.e. [PR 51](https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/51)), this repository is largely generated from the [`autogen`](/autogen) directory.
23+
24+
The root module is generated by running `make generate`. Changes to this repository should be made in the [`autogen`](/autogen) directory where appropriate.
25+
26+
Note: The correct sequence to update the repo using autogen functionality is to run
27+
`make docker_generate && make docker_generate_docs`. This will create the various Terraform files, and then
28+
generate the Terraform documentation using `terraform-docs`.
29+
30+
### Autogeneration of documentation from .tf files
31+
To generate new Inputs and Outputs tables run
32+
```
33+
make docker_generate_docs
34+
```
35+
36+
## Integration Testing
37+
38+
Integration tests are used to verify the behaviour of the root module,
39+
submodules, and example modules. Additions, changes, and fixes should
40+
be accompanied with tests.
41+
42+
The integration tests are run using [Kitchen][kitchen],
43+
[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These
44+
tools are packaged within a Docker image for convenience.
45+
46+
The general strategy for these tests is to verify the behaviour of the
47+
[example modules](./examples/), thus ensuring that the root module,
48+
submodules, and example modules are all functionally correct.
49+
50+
Six test-kitchen instances are defined:
51+
52+
- `deploy-service`
53+
- `node-pool`
54+
- `shared-vpc`
55+
- `simple-regional`
56+
- `simple-zonal`
57+
- `stub-domains`
58+
59+
The test-kitchen instances in `test/fixtures/` wrap identically-named examples in the `examples/` directory.`
60+
61+
### Test Environment
62+
The easiest way to test the module is in an isolated test project. The setup for such a project is defined in [test/setup](./test/setup/) directory.
63+
64+
To use this setup, you need a service account with Project Creator access on a folder. Export the Service Account credentials to your environment like so:
65+
66+
```
67+
export SERVICE_ACCOUNT_JSON=$(< credentials.json)
68+
```
69+
70+
You will also need to set a few environment variables:
71+
```
72+
export TF_VAR_org_id="your_org_id"
73+
export TF_VAR_folder_id="your_folder_id"
74+
export TF_VAR_billing_account="your_billing_account_id"
75+
```
76+
77+
With these settings in place, you can prepare a test project using Docker:
78+
```
79+
make docker_test_prepare
80+
```
81+
82+
### Noninteractive Execution
83+
84+
Run `make docker_test_integration` to test all of the example modules
85+
noninteractively, using the prepared test project.
86+
87+
### Interactive Execution
88+
89+
1. Run `make docker_run` to start the testing Docker container in
90+
interactive mode.
91+
92+
1. Run `kitchen_do create <EXAMPLE_NAME>` to initialize the working
93+
directory for an example module.
94+
95+
1. Run `kitchen_do converge <EXAMPLE_NAME>` to apply the example module.
96+
97+
1. Run `kitchen_do verify <EXAMPLE_NAME>` to test the example module.
98+
99+
1. Run `kitchen_do destroy <EXAMPLE_NAME>` to destroy the example module
100+
state.
101+
102+
## Linting and Formatting
103+
104+
Many of the files in the repository can be linted or formatted to
105+
maintain a standard of quality.
106+
107+
### Execution
108+
109+
Run `make docker_test_lint`.
110+
111+
[docker-engine]: https://www.docker.com/products/docker-engine
112+
[flake8]: http://flake8.pycqa.org/en/latest/
113+
[gofmt]: https://golang.org/cmd/gofmt/
114+
[google-cloud-sdk]: https://cloud.google.com/sdk/install
115+
[hadolint]: https://github.com/hadolint/hadolint
116+
[inspec]: https://inspec.io/
117+
[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform
118+
[kitchen]: https://kitchen.ci/
119+
[make]: https://en.wikipedia.org/wiki/Make_(software)
120+
[shellcheck]: https://www.shellcheck.net/
121+
[terraform-docs]: https://github.com/segmentio/terraform-docs
122+
[terraform]: https://terraform.io/

Makefile

Lines changed: 64 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Google LLC
1+
# Copyright 2019 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,172 +12,85 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Please note that this file was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template).
16+
# Please make sure to contribute relevant changes upstream!
17+
1518
# Make will use bash instead of sh
1619
SHELL := /usr/bin/env bash
1720

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 ?= 2.3.0
22-
DOCKER_REPO_BASE_KITCHEN_TERRAFORM := ${DOCKER_ORG}/cft/kitchen-terraform:${DOCKER_TAG_BASE_KITCHEN_TERRAFORM}
23-
24-
# All is the first target in the file so it will get picked up when you just run 'make' on its own
25-
.PHONY: all
26-
all: check generate_docs
27-
28-
.PHONY: check
29-
check: check_shell check_python check_golang check_terraform check_base_files test_check_headers check_headers check_trailing_whitespace check_generate check_generate_docs
30-
31-
# The .PHONY directive tells make that this isn't a real target and so
32-
# the presence of a file named 'check_shell' won't cause this target to stop
33-
# working
34-
.PHONY: check_shell
35-
check_shell:
36-
@source test/make.sh && check_shell
37-
38-
.PHONY: check_python
39-
check_python:
40-
@source test/make.sh && check_python
41-
42-
.PHONY: check_golang
43-
check_golang:
44-
@source test/make.sh && golang
45-
46-
.PHONY: check_terraform
47-
check_terraform:
48-
@source test/make.sh && check_terraform
49-
50-
.PHONY: check_base_files
51-
check_base_files:
52-
@source test/make.sh && basefiles
21+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.1.0
22+
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
23+
REGISTRY_URL := gcr.io/cloud-foundation-cicd
5324

54-
.PHONY: check_shebangs
55-
check_shebangs:
56-
@source test/make.sh && check_bash
57-
58-
.PHONY: check_trailing_whitespace
59-
check_trailing_whitespace:
60-
@source test/make.sh && check_trailing_whitespace
61-
62-
.PHONY: test_check_headers
63-
test_check_headers:
64-
@echo "Testing the validity of the header check"
65-
@python test/test_verify_boilerplate.py
66-
67-
.PHONY: check_headers
68-
check_headers:
69-
@echo "Checking file headers"
70-
@python test/verify_boilerplate.py
71-
72-
.PHONY: check_generate
73-
check_generate: ## Check that `make generate` does not generate a diff
74-
@source test/make.sh && check_generate
75-
76-
.PHONY: check_generate_docs
77-
check_generate_docs: ## Check that `make generate_docs` does not generate a diff
78-
@source test/make.sh && check_generate_docs
79-
80-
# Integration tests
81-
.PHONY: test_integration
82-
test_integration:
83-
test/ci_integration.sh
84-
85-
.PHONY: generate_docs
86-
generate_docs:
87-
@source test/make.sh && generate_docs
88-
89-
.PHONY: generate
90-
generate:
91-
@source test/make.sh && generate
92-
93-
.PHONY: dev
94-
dev: generate generate_docs
95-
@echo "Updated files"
96-
97-
# Versioning
98-
.PHONY: version
99-
version:
100-
@source helpers/version-repo.sh
101-
102-
# Run docker
25+
# Enter docker container for local development
10326
.PHONY: docker_run
10427
docker_run:
10528
docker run --rm -it \
106-
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
107-
-e PROJECT_ID \
108-
-e REGION \
109-
-e ZONES \
11029
-e SERVICE_ACCOUNT_JSON \
111-
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
112-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
113-
-v "$(CURDIR)":/cft/workdir \
114-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
115-
/bin/bash -c "source test/ci_integration.sh && setup_environment && exec /bin/bash"
30+
-v $(CURDIR):/workspace \
31+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
32+
/bin/bash
11633

117-
.PHONY: docker_create
118-
docker_create: docker_build_kitchen_terraform
34+
# Execute prepare tests within the docker container
35+
.PHONY: docker_test_prepare
36+
docker_test_prepare:
11937
docker run --rm -it \
120-
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
121-
-e PROJECT_ID \
122-
-e REGION \
123-
-e ZONES \
12438
-e SERVICE_ACCOUNT_JSON \
125-
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
126-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
127-
-v "$(CURDIR)":/cft/workdir \
128-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
129-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"
130-
131-
.PHONY: docker_converge
132-
docker_converge:
39+
-e TF_VAR_org_id \
40+
-e TF_VAR_folder_id \
41+
-e TF_VAR_billing_account \
42+
-v $(CURDIR):/workspace \
43+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
44+
/usr/local/bin/execute_with_credentials.sh prepare_environment
45+
46+
# Clean up test environment within the docker container
47+
.PHONY: docker_test_cleanup
48+
docker_test_cleanup:
13349
docker run --rm -it \
134-
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
135-
-e PROJECT_ID \
136-
-e REGION \
137-
-e ZONES \
13850
-e SERVICE_ACCOUNT_JSON \
139-
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
140-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
141-
-v "$(CURDIR)":/cft/workdir \
142-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
143-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge && kitchen converge"
144-
145-
.PHONY: docker_verify
146-
docker_verify:
51+
-e TF_VAR_org_id \
52+
-e TF_VAR_folder_id \
53+
-e TF_VAR_billing_account \
54+
-v $(CURDIR):/workspace \
55+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
56+
/usr/local/bin/execute_with_credentials.sh cleanup_environment
57+
58+
# Execute integration tests within the docker container
59+
.PHONY: docker_test_integration
60+
docker_test_integration:
14761
docker run --rm -it \
148-
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
149-
-e PROJECT_ID \
150-
-e REGION \
151-
-e ZONES \
15262
-e SERVICE_ACCOUNT_JSON \
153-
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
154-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
155-
-v "$(CURDIR)":/cft/workdir \
156-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
157-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen verify"
63+
-v $(CURDIR):/workspace \
64+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
65+
/usr/local/bin/test_integration.sh
15866

159-
.PHONY: docker_destroy
160-
docker_destroy:
67+
# Execute lint tests within the docker container
68+
.PHONY: docker_test_lint
69+
docker_test_lint:
16170
docker run --rm -it \
162-
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
163-
-e PROJECT_ID \
164-
-e REGION \
165-
-e ZONES \
166-
-e SERVICE_ACCOUNT_JSON \
167-
-e CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=${CREDENTIALS_PATH} \
168-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
169-
-v "$(CURDIR)":/cft/workdir \
170-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
171-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen destroy"
71+
-v $(CURDIR):/workspace \
72+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
73+
/usr/local/bin/test_lint.sh
17274

173-
.PHONY: test_integration_docker
174-
test_integration_docker:
75+
# Generate documentation
76+
.PHONY: docker_generate_docs
77+
docker_generate_docs:
17578
docker run --rm -it \
176-
-e COMPUTE_ENGINE_SERVICE_ACCOUNT \
177-
-e PROJECT_ID \
178-
-e REGION \
179-
-e ZONES \
180-
-e SERVICE_ACCOUNT_JSON \
181-
-v "$(CURDIR)":/cft/workdir \
182-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
183-
/bin/bash -c "test/ci_integration.sh"
79+
-v $(CURDIR):/workspace \
80+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
81+
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs'
82+
83+
# Generate files from autogen
84+
.PHONY: docker_generate
85+
docker_generate:
86+
docker run --rm -it \
87+
-v $(CURDIR):/workspace \
88+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
89+
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate'
90+
91+
# Alias for backwards compatibility
92+
.PHONY: generate_docs
93+
generate_docs: docker_generate_docs
94+
95+
.PHONY: generate
96+
generate: docker_generate

0 commit comments

Comments
 (0)