diff --git a/.circleci/config.yml b/.circleci/config.yml index 199337b..cfa1109 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1 +1,102 @@ -# NO-OP \ No newline at end of file +defaults: &defaults + machine: true + environment: + GRUNTWORK_INSTALLER_VERSION: v0.0.21 + TERRATEST_LOG_PARSER_VERSION: v0.13.24 + MODULE_CI_VERSION: v0.13.3 + TERRAFORM_VERSION: 0.11.8 + TERRAGRUNT_VERSION: NONE + PACKER_VERSION: NONE + GOLANG_VERSION: 1.11.2 + +install_gruntwork_utils: &install_gruntwork_utils + name: install gruntwork utils + command: | + curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" + gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}" + gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "${TERRATEST_LOG_PARSER_VERSION}" + configure-environment-for-gruntwork-module \ + --circle-ci-2-machine-executor \ + --terraform-version ${TERRAFORM_VERSION} \ + --terragrunt-version ${TERRAGRUNT_VERSION} \ + --packer-version ${PACKER_VERSION} \ + --use-go-dep \ + --go-version ${GOLANG_VERSION} \ + --go-src-path test +version: 2 +jobs: + build: + <<: *defaults + steps: + - checkout + - restore_cache: + keys: + - dep-v1-{{ checksum "test/Gopkg.lock" }} + + # Install gruntwork utilities + - run: + <<: *install_gruntwork_utils + + - save_cache: + key: dep-v1-{{ checksum "test/Gopkg.lock" }} + paths: + - ./test/vendor + + # Fail the build if the pre-commit hooks don't pass. Note: if you run pre-commit install locally, these hooks will + # execute automatically every time before you commit, ensuring the build never fails at this step! + - run: pip install pre-commit==1.11.2 + - run: pre-commit install + - run: pre-commit run --all-files + + - persist_to_workspace: + root: /home/circleci + paths: + - project + - terraform + - packer + + test: + <<: *defaults + steps: + - attach_workspace: + at: /home/circleci + - checkout + - run: echo 'export PATH=$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV + - run: + <<: *install_gruntwork_utils + - run: + name: update gcloud + command: | + sudo apt-get remove -y google-cloud-sdk + sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update + sudo /opt/google-cloud-sdk/bin/gcloud --quiet components update beta + - run: + name: run tests + command: | + mkdir -p /tmp/logs + # required for gcloud to authenticate correctly + echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=- + gcloud --quiet config set project ${GOOGLE_PROJECT_ID} + gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE} + # required for terraform and terratest to authenticate correctly + echo $GCLOUD_SERVICE_KEY > /tmp/gcloud.json + export GOOGLE_APPLICATION_CREDENTIALS="/tmp/gcloud.json" + # run the tests + run-go-tests --path test --timeout 60m | tee /tmp/logs/all.log + no_output_timeout: 3600s + - run: + command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs + when: always + - store_artifacts: + path: /tmp/logs + - store_test_results: + path: /tmp/logs + +workflows: + version: 2 + build-and-test: + jobs: + - build + - test: + requires: + - build \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d6ca6c5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.0.4 + hooks: + - id: terraform-fmt