Skip to content

Commit

Permalink
Work on template testing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Aug 20, 2019
1 parent 9a592c4 commit 392cc49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ content should be modified to suit the purpose of the new module.
Changes to this template must be tested to ensure that generated
modules remain functional.

Refer to the [README][readme] and [CONTRIBUTING][contributing]
Refer to the [README][./terraform-google-{{cookiecutter.module_name}}/README.md] and [CONTRIBUTING][./terraform-google-{{cookiecutter.module_name}}/CONTRIBUTING.md]
documents of the template to understand the requirements for testing
the generated module.

The key for the service account described in the README must be located
at `./credentials.test.json`.
Export a Service Account key and env variables:

```
export SERVICE_ACCOUNT_JSON=$(< credentials.json)
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"
```

Generate a module and execute its tests by running the following
command:

```sh
PROJECT_ID="<ID of test project>" \
SERVICE_ACCOUNT_JSON="$(cat ./credentials.test.json)" \
make test
```

Expand All @@ -45,7 +49,6 @@ will be removed; otherwise, it will be left in place for inspection.
In order to execute the test following tools need to be installed:
- `make`
- `docker`
- `jq`

[cookiecutter]: https://cookiecutter.readthedocs.io/
[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform
Expand Down
13 changes: 3 additions & 10 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ _curdir="$(pwd)"
cd staging || exit 1
cookiecutter --no-input "${_curdir}" module_name=module-test
cd ./terraform-google-module-test || exit 1
cp "${_curdir}/credentials.test.json" ./credentials.json
_project_id=$(jq -r '.project_id' < ./credentials.json)
tee ./kitchen.local.yml <<EOF
---
driver:
variables:
project_id: ${_project_id}
EOF
make test_integration_docker
make docker_test_prepare
make docker_test_integration
_result=$?
if [ "$_result" -ne "0" ]; then
make docker_destroy
make docker_test_cleanup
exit $_result
fi
cd .. || exit 1
Expand Down

0 comments on commit 392cc49

Please sign in to comment.