Skip to content

Commit 628d069

Browse files
morgantepaulpalamarchuk
authored andcommitted
Merge pull request terraform-google-modules#18 from averbuks/averbuks-update-to-cloudbuild
Update testing to CloudBuild
2 parents b59cf70 + 3fc77e6 commit 628d069

Some content is hidden

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

43 files changed

+606
-1977
lines changed

‎CONTRIBUTING.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
### Execution
21+
22+
Run `make generate_docs` to generate new Inputs and Outputs tables.
23+
24+
## Integration Testing
25+
26+
Integration tests are used to verify the behaviour of the root module,
27+
submodules, and example modules. Additions, changes, and fixes should
28+
be accompanied with tests.
29+
30+
The integration tests are run using [Kitchen][kitchen],
31+
[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These
32+
tools are packaged within a Docker image for convenience.
33+
34+
The general strategy for these tests is to verify the behaviour of the
35+
[example modules](./examples/), thus ensuring that the root module,
36+
submodules, and example modules are all functionally correct.
37+
38+
### Test Environment
39+
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.
40+
41+
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:
42+
43+
```
44+
export SERVICE_ACCOUNT_JSON=$(< credentials.json)
45+
```
46+
47+
You will also need to set a few environment variables:
48+
```
49+
export TF_VAR_org_id="your_org_id"
50+
export TF_VAR_folder_id="your_folder_id"
51+
export TF_VAR_billing_account="your_billing_account_id"
52+
```
53+
54+
With these settings in place, you can prepare a test project using Docker:
55+
```
56+
make docker_test_prepare
57+
```
58+
59+
### Noninteractive Execution
60+
61+
Run `make docker_test_integration` to test all of the example modules
62+
noninteractively, using the prepared test project.
63+
64+
### Interactive Execution
65+
66+
1. Run `make docker_run` to start the testing Docker container in
67+
interactive mode.
68+
69+
1. Run `kitchen_do create <EXAMPLE_NAME>` to initialize the working
70+
directory for an example module.
71+
72+
1. Run `kitchen_do converge <EXAMPLE_NAME>` to apply the example module.
73+
74+
1. Run `kitchen_do verify <EXAMPLE_NAME>` to test the example module.
75+
76+
1. Run `kitchen_do destroy <EXAMPLE_NAME>` to destroy the example module
77+
state.
78+
79+
## Linting and Formatting
80+
81+
Many of the files in the repository can be linted or formatted to
82+
maintain a standard of quality.
83+
84+
### Execution
85+
86+
Run `make docker_test_lint`.
87+
88+
[docker-engine]: https://www.docker.com/products/docker-engine
89+
[flake8]: http://flake8.pycqa.org/en/latest/
90+
[gofmt]: https://golang.org/cmd/gofmt/
91+
[google-cloud-sdk]: https://cloud.google.com/sdk/install
92+
[hadolint]: https://github.com/hadolint/hadolint
93+
[inspec]: https://inspec.io/
94+
[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform
95+
[kitchen]: https://kitchen.ci/
96+
[make]: https://en.wikipedia.org/wiki/Make_(software)
97+
[shellcheck]: https://www.shellcheck.net/
98+
[terraform-docs]: https://github.com/segmentio/terraform-docs
99+
[terraform]: https://terraform.io/

‎LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,4 @@
199199
distributed under the License is distributed on an "AS IS" BASIS,
200200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201201
See the License for the specific language governing permissions and
202-
limitations under the License.
202+
limitations under the License.

‎Makefile

Lines changed: 52 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -12,133 +12,74 @@
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-
all: check generate_docs
26-
27-
.PHONY: check
28-
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace
29-
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_docker
51-
check_docker:
52-
@source test/make.sh && docker
53-
54-
.PHONY: check_base_files
55-
check_base_files:
56-
@source test/make.sh && basefiles
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
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
6624

67-
.PHONY: check_headers
68-
check_headers:
69-
@source test/make.sh && check_headers
70-
71-
# Integration tests
72-
.PHONY: test_integration
73-
test_integration:
74-
./test/ci_integration.sh
75-
76-
.PHONY: generate_docs
77-
generate_docs:
78-
@source test/make.sh && generate_docs
79-
80-
# Versioning
81-
.PHONY: version
82-
version:
83-
@source helpers/version-repo.sh
84-
85-
# Run docker
25+
# Enter docker container for local development
8626
.PHONY: docker_run
8727
docker_run:
8828
docker run --rm -it \
89-
-e PROJECT_ID \
9029
-e SERVICE_ACCOUNT_JSON \
91-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
92-
-v $(CURDIR):/cft/workdir \
93-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
94-
/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
9533

96-
.PHONY: docker_create
97-
docker_create:
34+
# Execute prepare tests within the docker container
35+
.PHONY: docker_test_prepare
36+
docker_test_prepare:
9837
docker run --rm -it \
99-
-e PROJECT_ID \
10038
-e SERVICE_ACCOUNT_JSON \
101-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
102-
-v $(CURDIR):/cft/workdir \
103-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
104-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen create"
105-
106-
.PHONY: docker_converge
107-
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:
10849
docker run --rm -it \
109-
-e PROJECT_ID \
11050
-e SERVICE_ACCOUNT_JSON \
111-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
112-
-v $(CURDIR):/cft/workdir \
113-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
114-
/bin/bash -c "source test/ci_integration.sh && setup_environment && kitchen converge"
115-
116-
.PHONY: docker_verify
117-
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:
11861
docker run --rm -it \
119-
-e PROJECT_ID \
12062
-e SERVICE_ACCOUNT_JSON \
121-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
122-
-v $(CURDIR):/cft/workdir \
123-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
124-
/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
12566

126-
.PHONY: docker_destroy
127-
docker_destroy:
67+
# Execute lint tests within the docker container
68+
.PHONY: docker_test_lint
69+
docker_test_lint:
12870
docker run --rm -it \
129-
-e PROJECT_ID \
130-
-e SERVICE_ACCOUNT_JSON \
131-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
132-
-v $(CURDIR):/cft/workdir \
133-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
134-
/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
13574

136-
.PHONY: test_integration_docker
137-
test_integration_docker:
75+
# Generate documentation
76+
.PHONY: docker_generate_docs
77+
docker_generate_docs:
13878
docker run --rm -it \
139-
-e PROJECT_ID \
140-
-e SERVICE_ACCOUNT_JSON \
141-
-e GOOGLE_APPLICATION_CREDENTIALS=${CREDENTIALS_PATH} \
142-
-v $(CURDIR):/cft/workdir \
143-
${DOCKER_REPO_BASE_KITCHEN_TERRAFORM} \
144-
make test_integration
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+
# Alias for backwards compatibility
84+
.PHONY: generate_docs
85+
generate_docs: docker_generate_docs

0 commit comments

Comments
 (0)