-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
576 additions
and
1,595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Contributing | ||
|
||
This document provides guidelines for contributing to the module. | ||
|
||
## Dependencies | ||
|
||
The following dependencies must be installed on the development system: | ||
|
||
- [Docker Engine][docker-engine] | ||
- [Google Cloud SDK][google-cloud-sdk] | ||
- [make] | ||
- [bats](https://github.com/sstephenson/bats) 0.4.0 | ||
- [jq](https://stedolan.github.io/jq/) 1.5 | ||
- [terraform-docs](https://github.com/segmentio/terraform-docs/releases) 0.3.0 | ||
|
||
## Generating Documentation for Inputs and Outputs | ||
|
||
The Inputs and Outputs tables in the READMEs of the root module, | ||
submodules, and example modules are automatically generated based on | ||
the `variables` and `outputs` of the respective modules. These tables | ||
must be refreshed if the module interfaces are changed. | ||
|
||
### Execution | ||
|
||
Run `make generate_docs` to generate new Inputs and Outputs tables. | ||
|
||
## Integration Testing | ||
|
||
### File structure | ||
The project has the following folders and files: | ||
|
||
- /: root folder | ||
- /examples: examples for using this module | ||
- /test: Folders with files for testing the module (see Testing section on this file) | ||
- /main.tf: main file for this module, contains primary logic for operate the module | ||
- /*_constraints.tf: files for manage the policy resources | ||
- /variables.tf: all the variables for the module | ||
- /output.tf: the outputs of the module | ||
- /readme.MD: this file | ||
|
||
Integration tests are used to verify the behaviour of the root module, | ||
submodules, and example modules. Additions, changes, and fixes should | ||
be accompanied with tests. | ||
|
||
The integration tests should be using [Kitchen][kitchen](the module is in transition to it and uses bats tests | ||
hooked up to Cloud Build with a make target for local tests),[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These | ||
tools are packaged within a Docker image for convenience. | ||
|
||
The general strategy for these tests is to verify the behaviour of the | ||
[example modules](./examples/), thus ensuring that the root module, | ||
submodules, and example modules are all functionally correct. | ||
|
||
### Test Environment | ||
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. | ||
|
||
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: | ||
|
||
``` | ||
export SERVICE_ACCOUNT_JSON=$(< credentials.json) | ||
``` | ||
|
||
You will also need to set a few environment variables: | ||
``` | ||
export TF_VAR_org_id="your_org_id" | ||
export TF_VAR_folder_id="your_folder_id" | ||
export TF_VAR_billing_account="your_billing_account_id" | ||
``` | ||
|
||
With these settings in place, you can prepare a test project using Docker: | ||
``` | ||
make docker_test_prepare | ||
``` | ||
|
||
### Noninteractive Execution | ||
|
||
Run `make docker_test_integration` to test all of the example modules | ||
noninteractively, using the prepared test project. | ||
|
||
### Manual Execution | ||
The integration tests for this module are built with bats, basically the test checks the following: | ||
- Perform `terraform init` command | ||
- Perform `terraform get` command | ||
- Perform `terraform plan` command and check that it'll create *n* resources, modify 0 resources and delete 0 resources | ||
- Perform `terraform apply -auto-approve` command and check that it has created the *n* resources, modified 0 resources and deleted 0 resources | ||
- Perform several `gcloud` commands and check the policies are in the desired state | ||
- Perform `terraform destroy -force` command and check that it has destroyed the *n* resources | ||
|
||
Please edit the *test/integration/<list|boolean>_constraints/launch.sh* files in order to specify the test beahvior | ||
|
||
You can use the following command to run the integration tests in the folder */test/integration/<list|boolean>_constraints/* | ||
|
||
`. launch.sh` | ||
|
||
## Linting and Formatting | ||
|
||
Many of the files in the repository can be linted or formatted to | ||
maintain a standard of quality. | ||
|
||
### Execution | ||
|
||
Run `make docker_test_lint`. | ||
|
||
[docker-engine]: https://www.docker.com/products/docker-engine | ||
[flake8]: http://flake8.pycqa.org/en/latest/ | ||
[gofmt]: https://golang.org/cmd/gofmt/ | ||
[google-cloud-sdk]: https://cloud.google.com/sdk/install | ||
[hadolint]: https://github.com/hadolint/hadolint | ||
[inspec]: https://inspec.io/ | ||
[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform | ||
[kitchen]: https://kitchen.ci/ | ||
[make]: https://en.wikipedia.org/wiki/Make_(software) | ||
[shellcheck]: https://www.shellcheck.net/ | ||
[terraform-docs]: https://github.com/segmentio/terraform-docs | ||
[terraform]: https://terraform.io/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
timeout: 3600s | ||
steps: | ||
- id: prepare | ||
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' | ||
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && prepare_environment'] | ||
env: | ||
- 'TF_VAR_org_id=$_ORG_ID' | ||
- 'TF_VAR_folder_id=$_FOLDER_ID' | ||
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT' | ||
- id: test_list_constraints | ||
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' | ||
args: ['/bin/bash', '-c', 'cd test/integration/list_constraints && bash launch.sh'] | ||
env: | ||
- 'TF_VAR_org_id=$_ORG_ID' | ||
- 'TF_VAR_folder_id=$_FOLDER_ID' | ||
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT' | ||
- id: test_boolean_constraints | ||
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' | ||
args: ['/bin/bash', '-c', 'cd test/integration/boolean_constraints && bash launch.sh'] | ||
env: | ||
- 'TF_VAR_org_id=$_ORG_ID' | ||
- 'TF_VAR_folder_id=$_FOLDER_ID' | ||
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT' | ||
- id: cleanup | ||
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' | ||
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && cleanup_environment'] | ||
env: | ||
- 'TF_VAR_org_id=$_ORG_ID' | ||
- 'TF_VAR_folder_id=$_FOLDER_ID' | ||
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT' | ||
tags: | ||
- 'ci' | ||
- 'integration' | ||
substitutions: | ||
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools' | ||
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.1' |
Oops, something went wrong.