Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/no prefix #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ Parameter name | Type | Required | Default Value | Description
--- | --- | --- | --- | ---
`ssm_parameter_list` | string | true | | AWS Systems Manager parameter name (path) or comma separated list of paths
`prefix` | string | false | AWS_SSM_ | Custom environmental variables prefix
`simple_json` | boolean | true | false | Parse parameter values as one-level JSON object and convert keys to environmental variables (see example below).
`jq_params` | string | true | | Custom space-separated [`jq` filters](https://stedolan.github.io/jq/) (see example below).
`skip_prefix` | boolean | false | false | Custom environmental variables prefix
`simple_json` | boolean | false | false | Parse parameter values as one-level JSON object and convert keys to environmental variables (see example below).
`jq_params` | string | false | | Custom space-separated [`jq` filters](https://stedolan.github.io/jq/) (see example below).

### Examples

Expand Down Expand Up @@ -123,6 +124,32 @@ jobs:

Example above will set environmental variable `FOO_MY_PARAMETER_NAME` with value from the AWS SSM parameter itself.

##### Skipping the prefix

It's also possible to completely skip prefixing environmental variables by using `skip_prefix` parameter:
```yaml
name: Parse SSM parameter

on:
push

jobs:
aws-ssm-to-env:
runs-on: ubuntu-latest
steps:
- name: aws-ssm-to-env
uses: bomb-on/aws-ssm-to-env@master
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
with:
ssm_parameter_list: 'my_parameter_name'
skip_prefix: true
```

Example above will set environmental variable `MY_PARAMETER_NAME` with value from the AWS SSM parameter itself.

#### Simple JSON parameter values

Parse simple one-level JSON object and create environmental variables from all keys:
Expand Down
11 changes: 6 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fi
region="$AWS_REGION"
parameter_name_list="$INPUT_SSM_PARAMETER_LIST"
prefix="${INPUT_PREFIX:-AWS_SSM_}"
[ -n "$INPUT_SKIP_PREFIX" ] && prefix=""
jq_filter="$INPUT_JQ_FILTER"
simple_json="$INPUT_SIMPLE_JSON"

Expand All @@ -28,25 +29,25 @@ get_ssm_param() {
if [ -n "$jq_filter" ] || [ -n "$simple_json" ]; then
ssm_param_value=$(echo "$ssm_param" | jq '.Parameter.Value | fromjson')
if [ -n "$simple_json" ] && [ "$simple_json" == "true" ]; then
for p in $(echo "$ssm_param_value" | jq -r --arg v "$prefix" 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' ); do
for p in $(echo "$ssm_param_value" | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' ); do
IFS='=' read -r var_name var_value <<< "$p"
echo "$(format_var_name "$var_name")=$var_value" >> $GITHUB_ENV
echo "$(format_var_name "$var_name")=$var_value" >> "$GITHUB_ENV"
done
else
IFS=' ' read -r -a params <<< "$jq_filter"
for var_name in "${params[@]}"; do
var_value=$(echo "$ssm_param_value" | jq -r -c "$var_name")
echo "$(format_var_name "$var_name")=$var_value" >> $GITHUB_ENV
echo "$(format_var_name "$var_name")=$var_value" >> "$GITHUB_ENV"
done
fi
else
var_name=$(echo "$ssm_param" | jq -r '.Parameter.Name' | awk -F/ '{print $NF}')
var_value=$(echo "$ssm_param" | jq -r '.Parameter.Value')
echo "$(format_var_name "$var_name")=$var_value" >> $GITHUB_ENV
echo "$(format_var_name "$var_name")=$var_value" >> "$GITHUB_ENV"
fi
}

for parameter in $(echo $parameter_name_list | sed "s/,/ /g"); do
for parameter in ${parameter_name_list//,/ }; do
get_ssm_param "$parameter"
done

Expand Down