Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ use this module.
| function\_labels | A set of key/value label pairs to assign to the function. | map | `<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 | `<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 |

Expand Down
1 change: 1 addition & 0 deletions examples/automatic_labelling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
18 changes: 1 addition & 17 deletions examples/automatic_labelling/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../../"

Expand All @@ -53,7 +37,7 @@ module "event_function" {
)
}"

name = "${random_pet.main.id}"
name = "${var.name}"
project_id = "${var.project_id}"
region = "${var.region}"
}
5 changes: 5 additions & 0 deletions examples/automatic_labelling/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
19 changes: 18 additions & 1 deletion test/fixtures/automatic_labelling/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

Expand Down
67 changes: 41 additions & 26 deletions test/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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