Skip to content

Commit

Permalink
Merge pull request #5 from echoboomer/v1.0.7
Browse files Browse the repository at this point in the history
Adds ability to skip running on master branch.
  • Loading branch information
echoboomer authored Sep 11, 2020
2 parents 75eb0f6 + c4001ba commit bc10f92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ If this is provided and set to `true`, the Buildkite pipeline will fail if the p

The Docker image to run for Open Policy Agent. Defaults to `openpolicyagent/opa`. The `version` option specified below correlates with the `tag` option.

### `skip_master_branch` (Not Required, boolean)

If this is provided and set to `true`, the plugin looks for `BUILDKITE_BRANCH` and won't run if the value is `master`. This is useful is the plugin runs alongside others in one step using the example above.

### `tests_dir` (Not Required, string)

The path of the directory in your Terraform repository containing the required files for running Open Policy Agent assessments against Terraform code. Since Buildkite agents typically operate from the root of a repository, this is in relation to that top level path. This defaults to `./terraform/tests`. You may override this as long as your files are available in the given location.
Expand Down
8 changes: 7 additions & 1 deletion hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cNone="\033[00m"
cRed="\033[01;31m"
cGreen="\033[01;32m"

BUILDKITE_BRANCH=${BUILDKITE_BRANCH:-}
IMAGE_NAME=${BUILDKITE_PLUGIN_TERRAFORM_OPA_IMAGE:-"openpolicyagent/opa"}
VERSION=${BUILDKITE_PLUGIN_TERRAFORM_OPA_VERSION:-"latest"}
OPA_IMAGE="${IMAGE_NAME}:${VERSION}"
Expand All @@ -28,6 +29,7 @@ function terraform-opa-run() {
local POLICY_FILE=${BUILDKITE_PLUGIN_TERRAFORM_OPA_POLICY_FILE:-"${TESTS_DIR}/terraform.rego"}
local RESOURCE_TYPES_FILE=${BUILDKITE_PLUGIN_TERRAFORM_OPA_RESOURCE_TYPES_FILE:-"${TESTS_DIR}/resource_types.json"}
local RESOURCE_WEIGHTS_FILE=${BUILDKITE_PLUGIN_TERRAFORM_OPA_RESOURCE_WEIGHTS_FILE:-"${TESTS_DIR}/resource_weights.json"}
local SKIP_MASTER_BRANCH=${BUILDKITE_PLUGIN_TERRAFORM_OPA_SKIP_MASTER_BRANCH:-false}
local TERRAFORM_PLAN=${BUILDKITE_PLUGIN_TERRAFORM_OPA_TERRAFORM_PLAN}

if [[ "${DEBUG}" == true ]]; then
Expand Down Expand Up @@ -112,4 +114,8 @@ function terraform-opa-run() {
echo ""
}

terraform-opa-run
if [[ "${SKIP_MASTER_BRANCH}" == true && "${BUILDKITE_BRANCH}" == "master" ]]; then
exit 0
else
terraform-opa-run
fi
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ configuration:
type: boolean
image:
type: string
skip_master_branch:
type: boolean
policy_file:
type: string
resource_types_file:
Expand Down

0 comments on commit bc10f92

Please sign in to comment.