Skip to content
Open
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
54 changes: 54 additions & 0 deletions .circleci/ci_integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /bin/bash
# Always clean up.
DELETE_AT_EXIT="$(mktemp -d)"

finish() {
echo 'BEGIN: finish() trap handler' >&2
set +e
bundle exec kitchen destroy
[[ -d "${DELETE_AT_EXIT}" ]] && rm -rf "${DELETE_AT_EXIT}"
echo 'END: finish() trap handler' >&2
}

setup_environment() {
local tmpfile
tmpfile="$(mktemp)"

echo "$GOOGLE_APPLICATION_CREDENTIALS" > "${tmpfile}"

# Terraform and most other tools respect GOOGLE_CREDENTIALS
export GOOGLE_CREDENTIALS="$GOOGLE_APPLICATION_CREDENTIALS"

# gcloud variables
export CLOUDSDK_CORE_PROJECT="${PROJECT_ID}"
export GOOGLE_APPLICATION_CREDENTIALS="${tmpfile}"

# Terraform input variables
export TF_VAR_project_id="${PROJECT_ID}"
TF_VAR_random_string_for_testing="${RANDOM_STRING_FOR_TESTING:-$(LC_ALL=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 5 | head -n 1)}"
export TF_VAR_random_string_for_testing

# Setup auth for service account
gcloud auth activate-service-account --key-file="${tmpfile}"
}

main() {
set -eu
# Setup trap handler to auto-cleanup
export TMPDIR="${DELETE_AT_EXIT}"
trap finish EXIT

# Setup environment
setup_environment

set -x
# Execute the test lifecycle
bundle exec kitchen create
bundle exec kitchen converge
bundle exec kitchen verify
}

# if script is being executed and not sourced.
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
65 changes: 30 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
env: &docker
docker:
- image: leandevopsio/terratest:0.3
- image: leandevopsio/buildenv:0.1

version: 2
jobs:
check_terraform:
<<: *docker
steps:
- checkout
- checkout
- run:
name: terraform init validate fmt
name: Run terraform init validate fmt
command: make check_terraform
- run:
name: Check Terraform configurations with tflint
name: Run tflint
command: tflint
# run-tests:
# <<: *docker
# environment:
# BUNDLE_PATH: vendor
- run:
name: Run check_shell
command: make check_shell

# steps:
# - checkout
# - restore_cache:
# keys:
# - tf-gcp-network-{{ checksum "Gemfile.lock" }}
run-tests:
<<: *docker
environment:
BUNDLE_PATH: vendor

# - run:
# name: Bundle Install
# command: bundle check || bundle install
steps:
- checkout
- restore_cache:
keys:
- terraform-gcp-vpc-{{ checksum "Gemfile.lock" }}
- terraform-gcp-vpc-
- run:
name: Bundle Install
command: bundle check || bundle install
- save_cache:
key: terraform-gcp-vpc-{{ checksum "Gemfile.lock" }}
paths:
- vendor
- run:
name: Run test-kitchen cicle
command: .circleci/ci_integration.sh

# - save_cache:
# key: tf-gcp-network-{{ checksum "Gemfile.lock" }}
# paths:
# - vendor

# - run:
# name: Run make to zip a function code
# command: make build

# - run:
# name: Run rspec test
# command: make

workflows:
version: 2
tf-workflow:
jobs:
- check_terraform
# - check_tflint:
# requires:
# - check_terraform
# - request-run:
# type: approval
# requires:
Expand All @@ -59,9 +54,9 @@ workflows:
# filters:
# branches:
# ignore: master
# - run-tests:
# requires:
# - request-run
- run-tests:
requires:
- check_terraform
# filters:
# branches:
# ignore: master
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ crash.log
**/inspec.lock
**/.kitchen
**/.kitchen.local.yml
**/Gemfile.lock

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
Expand Down
Loading