Skip to content

Commit

Permalink
fix(integration): support special characters in exec module (#113)
Browse files Browse the repository at this point in the history
This commit supports passing in environment variables with special
characters to scripts in our "exec" module. The testcase has been
modified to exemplify this functionality. Prior to this change, the
testcase would fail due the variable getting clobbered after the first
argument:

```
aws: error: argument --output: expected one argument
```
  • Loading branch information
jta authored Nov 29, 2023
1 parent 96bb327 commit f0751e6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions integration/modules/exec/exec
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -o pipefail
# source environment variables from a JSON blob from stdin
STDIN=$(</dev/stdin)
ENV=$(echo $STDIN | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]")
export $ENV
ENV=$(echo "$STDIN" | jq -r 'to_entries | map("\(.key)=\(.value)") | @sh')
eval "export ${ENV}"

# if debug file is provided, write out and wait for it to be deleted
# before proceeding
Expand Down
1 change: 1 addition & 0 deletions integration/modules/exec/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ variable "args" {
nullable = false
default = []
}

variable "env_vars" {
description = <<-EOF
Environment variables
Expand Down
3 changes: 2 additions & 1 deletion integration/scripts/check_bucket_not_empty
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ DIE() { echo "$*" 1>&2; exit 1; }
[[ ! -z "${SOURCE:-}" ]] || DIE "source not set"

echo "listing ${SOURCE}"
[[ ! -z $(aws s3 ls ${SOURCE}) ]] || DIE "bucket is empty"
RESULT=$(aws s3 ls ${SOURCE} ${OPTS:-})
[[ ! -z ${RESULT} ]] || DIE "bucket is empty"
3 changes: 2 additions & 1 deletion integration/tests/simple.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ run "check" {
command = "./scripts/check_bucket_not_empty"
env_vars = {
SOURCE = run.setup.access_point.bucket
OPTS = "--output json"
}
}

assert {
condition = output.exitcode != 0
condition = output.error == "bucket is empty"
error_message = "Bucket isn't empty"
}
}

0 comments on commit f0751e6

Please sign in to comment.