|
| 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 generate && make 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 | +Run |
| 32 | +``` |
| 33 | +make generate_docs |
| 34 | +``` |
| 35 | + |
| 36 | +### Execution |
| 37 | + |
| 38 | +Run `make generate_docs` to generate new Inputs and Outputs tables. |
| 39 | + |
| 40 | +## Integration Testing |
| 41 | + |
| 42 | +Integration tests are used to verify the behaviour of the root module, |
| 43 | +submodules, and example modules. Additions, changes, and fixes should |
| 44 | +be accompanied with tests. |
| 45 | + |
| 46 | +The integration tests are run using [Kitchen][kitchen], |
| 47 | +[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These |
| 48 | +tools are packaged within a Docker image for convenience. |
| 49 | + |
| 50 | +The general strategy for these tests is to verify the behaviour of the |
| 51 | +[example modules](./examples/), thus ensuring that the root module, |
| 52 | +submodules, and example modules are all functionally correct. |
| 53 | + |
| 54 | +Six test-kitchen instances are defined: |
| 55 | + |
| 56 | +- `deploy-service` |
| 57 | +- `node-pool` |
| 58 | +- `shared-vpc` |
| 59 | +- `simple-regional` |
| 60 | +- `simple-zonal` |
| 61 | +- `stub-domains` |
| 62 | + |
| 63 | +The test-kitchen instances in `test/fixtures/` wrap identically-named examples in the `examples/` directory.` |
| 64 | + |
| 65 | +### Test Environment |
| 66 | +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. |
| 67 | + |
| 68 | +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: |
| 69 | + |
| 70 | +``` |
| 71 | +export SERVICE_ACCOUNT_JSON=$(< credentials.json) |
| 72 | +``` |
| 73 | + |
| 74 | +You will also need to set a few environment variables: |
| 75 | +``` |
| 76 | +export TF_VAR_org_id="your_org_id" |
| 77 | +export TF_VAR_folder_id="your_folder_id" |
| 78 | +export TF_VAR_billing_account="your_billing_account_id" |
| 79 | +``` |
| 80 | + |
| 81 | +With these settings in place, you can prepare a test project using Docker: |
| 82 | +``` |
| 83 | +make docker_test_prepare |
| 84 | +``` |
| 85 | + |
| 86 | +### Noninteractive Execution |
| 87 | + |
| 88 | +Run `make docker_test_integration` to test all of the example modules |
| 89 | +noninteractively, using the prepared test project. |
| 90 | + |
| 91 | +### Interactive Execution |
| 92 | + |
| 93 | +1. Run `make docker_run` to start the testing Docker container in |
| 94 | + interactive mode. |
| 95 | + |
| 96 | +1. Run `kitchen_do create <EXAMPLE_NAME>` to initialize the working |
| 97 | + directory for an example module. |
| 98 | + |
| 99 | +1. Run `kitchen_do converge <EXAMPLE_NAME>` to apply the example module. |
| 100 | + |
| 101 | +1. Run `kitchen_do verify <EXAMPLE_NAME>` to test the example module. |
| 102 | + |
| 103 | +1. Run `kitchen_do destroy <EXAMPLE_NAME>` to destroy the example module |
| 104 | + state. |
| 105 | + |
| 106 | +## Linting and Formatting |
| 107 | + |
| 108 | +Many of the files in the repository can be linted or formatted to |
| 109 | +maintain a standard of quality. |
| 110 | + |
| 111 | +### Execution |
| 112 | + |
| 113 | +Run `make docker_test_lint`. |
| 114 | + |
| 115 | +[docker-engine]: https://www.docker.com/products/docker-engine |
| 116 | +[flake8]: http://flake8.pycqa.org/en/latest/ |
| 117 | +[gofmt]: https://golang.org/cmd/gofmt/ |
| 118 | +[google-cloud-sdk]: https://cloud.google.com/sdk/install |
| 119 | +[hadolint]: https://github.com/hadolint/hadolint |
| 120 | +[inspec]: https://inspec.io/ |
| 121 | +[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform |
| 122 | +[kitchen]: https://kitchen.ci/ |
| 123 | +[make]: https://en.wikipedia.org/wiki/Make_(software) |
| 124 | +[shellcheck]: https://www.shellcheck.net/ |
| 125 | +[terraform-docs]: https://github.com/segmentio/terraform-docs |
| 126 | +[terraform]: https://terraform.io/ |
0 commit comments