Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

WIP: Add and configure CI for s3 full access policy module - issue 144 #210

Closed
wants to merge 9 commits into from
7 changes: 7 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ lint:
- scripts/ci/tfinit.sh
- scripts/ci/tflint.sh
# - scripts/ci/undeclared-variables.sh

test:
script:
- scripts/ci/examples/tfbuild.sh
- scripts/ci/examples/tftest.sh
- scripts/ci/examples/tfcleanup.sh
when: manual
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* `gitlab-ha`: Update `Makefile`
* `vpc-gateway`: correct module path reference
* `legacy`: drop deprecated example

* `s3-full-access-policy`: setup CI for building and running tests

# v0.8.2

Expand Down
2 changes: 1 addition & 1 deletion examples/s3-full-access-policy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test:

# clean up terrform and any other files
clean:
@terraform destroy
@terraform destroy -auto-approve
@rm -f tf.out
@rm -f terraform.tfvars
@rm -f terraform.*.backup
Expand Down
11 changes: 11 additions & 0 deletions scripts/ci/examples/tfbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -o nounset
set -o pipefail
set -o errexit

pushd "$(dirname $(basename "${0}"))/examples/s3-full-access-policy" > /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should comment this so it's obvious to even the bash newb.

Also, this script is named tfbuild.sh but is specific to one example. When we run CI for this, are we running a bunch of examples, or only a specific example in each job?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding some comments now for this.

Copy link
Contributor Author

@mcgirr mcgirr Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this script is named tfbuild.sh but is specific to one example. When we run CI for this, are we running a bunch of examples, or only a specific example in each job?

We just have the one example at the moment. I think the best thing would be for me to change the build script name (as well as tftest.sh and tfclean.sh) to something specific to this example.

The other option is that when we do add other Haskell based tests for terraform-aws-foundation we would build them in this script as well.

The question we need answered is whether we want to manually run all the examples and their Haskell test code each time or allow the tests to be run on a per example basis.

If we're running tfbuild.sh (or similiar) in the Gitlab CI yaml with a manual action for just this example, it'd probably make more sense to rename it and keep it separate. This is if we had the aim of having different build scripts for the different examples and tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the build step is using terraform to plan and apply the infrastructure needed for the test. So if something were to go wrong when we have more examples and tests, we'd need to address how to roll back all the infrastructure tfbuild.sh created.


make init && make plan && make apply && make output 1> /dev/null

popd > /dev/null
11 changes: 11 additions & 0 deletions scripts/ci/examples/tfcleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -o nounset
set -o pipefail
set -o errexit

pushd "$(dirname $(basename "${0}"))/examples/s3-full-access-policy" > /dev/null

make clean 1> /dev/null

popd > /dev/null
11 changes: 11 additions & 0 deletions scripts/ci/examples/tftest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -o nounset
set -o pipefail
set -o errexit

pushd "$(dirname $(basename "${0}"))/examples/s3-full-access-policy" > /dev/null

make test 1> /dev/null

popd > /dev/null
8 changes: 7 additions & 1 deletion scripts/ci/tfinit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/bash
#!/usr/bin/env bash

set -o nounset
set -o pipefail
Expand All @@ -9,3 +9,9 @@ pushd "$(dirname $(basename "${0}"))/tests" > /dev/null
terraform init 1> /dev/null

popd > /dev/null

pushd "$(dirname $(basename "${0}"))/examples/s3-full-access-policy" > /dev/null

terraform init 1> /dev/null
ketzacoatl marked this conversation as resolved.
Show resolved Hide resolved

popd > /dev/null
11 changes: 9 additions & 2 deletions scripts/ci/tflint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/bash
#!/usr/bin/env bash

set -o nounset
set -o pipefail
Expand All @@ -7,6 +7,13 @@ set -o errexit
pushd "$(dirname "$(basename "${0}")")/tests" > /dev/null

terraform init 1> /dev/null 2>&1 || true
tflint --error-with-issues
tflint --error-with-issues

popd > /dev/null

pushd "$(dirname $(basename "${0}"))/examples/s3-full-access-policy" > /dev/null

terraform init 1> /dev/null 2>&1 || true
tflint --error-with-issues

popd > /dev/null