diff --git a/README.md b/README.md index 2ace5da..5b8d075 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,10 @@ use this module. | function\_labels | A set of key/value label pairs to assign to the function. | map | `` | no | | function\_runtime | The runtime in which the function will be executed. | string | `"nodejs6"` | no | | function\_source\_archive\_bucket\_labels | A set of key/value label pairs to assign to the function source archive bucket. | map | `` | no | -| function\_source\_archive\_bucket\_location | The Google Cloud Storage location in which to create the function source archive bucket. | string | `"US"` | no | | function\_source\_directory | The contents of this directory will be archived and used as the function source. | string | n/a | yes | | function\_timeout\_s | The amount of time in seconds allotted for the execution of the function. | string | `"60"` | no | | log\_export\_filter | The filter to apply when exporting logs to the Pub/Sub topic. | string | n/a | yes | -| name | The name to apply to any nameable resources. | string | `"event-function"` | no | +| name | The name to apply to any nameable resources. | string | n/a | yes | | project\_id | The ID of the project to which resources will be applied. | string | n/a | yes | | region | The region in which resources will be applied. | string | n/a | yes | diff --git a/examples/automatic_labelling/README.md b/examples/automatic_labelling/README.md index b65fa58..ac9c13d 100644 --- a/examples/automatic_labelling/README.md +++ b/examples/automatic_labelling/README.md @@ -35,6 +35,7 @@ The project against which this module will be invoked requires no additional API | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| +| name | The name to apply to any nameable resources. | string | n/a | yes | | project\_id | The ID of the project to which resources will be applied. | string | n/a | yes | | region | The region in which resources will be applied. | string | n/a | yes | diff --git a/examples/automatic_labelling/main.tf b/examples/automatic_labelling/main.tf index c6ef76a..850c798 100644 --- a/examples/automatic_labelling/main.tf +++ b/examples/automatic_labelling/main.tf @@ -14,22 +14,6 @@ * limitations under the License. */ -provider "archive" { - version = "~> 1.1" -} - -provider "google" { - version = "~> 1.20" -} - -provider "random" { - version = "~> 2.0" -} - -resource "random_pet" "main" { - separator = "-" -} - module "event_function" { source = "../../" @@ -53,7 +37,7 @@ module "event_function" { ) }" - name = "${random_pet.main.id}" + name = "${var.name}" project_id = "${var.project_id}" region = "${var.region}" } diff --git a/examples/automatic_labelling/variables.tf b/examples/automatic_labelling/variables.tf index 0579e01..b3102f9 100644 --- a/examples/automatic_labelling/variables.tf +++ b/examples/automatic_labelling/variables.tf @@ -14,6 +14,11 @@ * limitations under the License. */ +variable "name" { + type = "string" + description = "The name to apply to any nameable resources." +} + variable "project_id" { type = "string" description = "The ID of the project to which resources will be applied." diff --git a/test/fixtures/automatic_labelling/main.tf b/test/fixtures/automatic_labelling/main.tf index f0bf003..06385d8 100644 --- a/test/fixtures/automatic_labelling/main.tf +++ b/test/fixtures/automatic_labelling/main.tf @@ -14,14 +14,31 @@ * limitations under the License. */ +provider "archive" { + version = "~> 1.1" +} + +provider "google" { + version = "~> 1.20" +} + +provider "random" { + version = "~> 2.0" +} + provider "null" { - version = "~> 1.0" + version = "~> 2.0" +} + +resource "random_pet" "main" { + separator = "-" } module "automatic_labelling" { source = "../../../examples/automatic_labelling" project_id = "${var.project_id}" + name = "automatic-labelling-${random_pet.main.id}" region = "${var.region}" } diff --git a/test/integration.sh b/test/integration.sh index 7e780c7..4d7b64a 100755 --- a/test/integration.sh +++ b/test/integration.sh @@ -14,34 +14,49 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -e -set -x +# Always clean up. +DELETE_AT_EXIT="$(mktemp -d)" +finish() { + echo 'BEGIN: finish() trap handler' >&2 + kitchen destroy + [[ -d "${DELETE_AT_EXIT}" ]] && rm -rf "${DELETE_AT_EXIT}" + echo 'END: finish() trap handler' >&2 +} -if [ -z "${PROJECT_ID}" ]; then - echo "The PROJECT_ID ENV variable must be set to proceed. Aborting." - exit 1 -fi +# Map the input parameters provided by Concourse CI, or whatever mechanism is +# running the tests to Terraform input variables. Also setup credentials for +# use with kitchen-terraform, inspec, and gcloud. +setup_environment() { + local tmpfile + tmpfile="$(mktemp)" + echo "${SERVICE_ACCOUNT_JSON}" > "${tmpfile}" -if [ -z "${SERVICE_ACCOUNT_JSON}" ]; then - echo "The SERVICE_ACCOUNT_JSON ENV variable must be set to proceed. Aborting." - exit 1 -fi + # gcloud variables + export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE="${tmpfile}" + # Application default credentials (Terraform google provider and inspec-gcp) + export GOOGLE_APPLICATION_CREDENTIALS="${tmpfile}" + + # Terraform variables + export TF_VAR_project_id="${PROJECT_ID}" + export TF_VAR_region="${REGION:-us-east1}" + export TF_VAR_zone="${ZONE:-us-east1-b}" +} -export TF_VAR_project_id="${PROJECT_ID}" -export TF_VAR_region="${REGION:-us-east1}" -export TF_VAR_zone="${ZONE:-us-east1-b}" +main() { + set -eu + # Setup trap handler to auto-cleanup + export TMPDIR="${DELETE_AT_EXIT}" + trap finish EXIT -DELETE_AT_EXIT="$(mktemp -d)" -finish() { - [[ -d "${DELETE_AT_EXIT}" ]] && rm -rf "${DELETE_AT_EXIT}" + # Setup environment variables + setup_environment + set -x + + # Execute the test lifecycle + kitchen verify } -trap finish EXIT -CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE="$(TMPDIR="${DELETE_AT_EXIT}" mktemp)" -set +x -echo "${SERVICE_ACCOUNT_JSON}" > "${CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE}" -set -x -GOOGLE_APPLICATION_CREDENTIALS="${CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE}" -declare -rx CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE GOOGLE_APPLICATION_CREDENTIALS -set +e -bundle install -bundle exec kitchen test --destroy=always + +# if script is being executed and not sourced. +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main "$@" +fi