Skip to content
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ A Concourse CI resource to check for new Amazon Machine Images (AMI).

- `aws_access_key_id`: Your AWS access key ID.

- `aws_secret_access_key`: Your AWS secret access key.
- `aws_secret_access_key`: Your AWS secret access key.

- `aws_role_arn`: ARN of a AWS IAM role to assume.

- `region`: *Required.* The AWS region to search for AMIs.

Expand Down
14 changes: 14 additions & 0 deletions bin/check
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ AMI=$(jq -r '.version.ami // empty' /tmp/input)
export AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // empty' /tmp/input)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // empty' /tmp/input)
export AWS_DEFAULT_REGION=$(jq -r '.source.region // empty' /tmp/input)
export AWS_ROLE_ARN=$(jq -r '.source.aws_role_arn // empty' /tmp/input)

# if role arn has been provided, assume role
if ! [ -z "$AWS_ROLE_ARN" ]; then
aws sts assume-role \
--duration 900 \
--role-arn $AWS_ROLE_ARN \
--role-session-name ci \
--output json \
> /tmp/session
export AWS_ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' /tmp/session)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' /tmp/session)
export AWS_SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' /tmp/session)
fi

# remove any empty credentials vars so the AWS client will try instance profiles
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
Expand Down
14 changes: 14 additions & 0 deletions bin/in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ AMI=$(jq -r '.version.ami // empty' /tmp/input)
export AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // empty' /tmp/input)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // empty' /tmp/input)
export AWS_DEFAULT_REGION=$(jq -r '.source.region // empty' /tmp/input)
export AWS_ROLE_ARN=$(jq -r '.source.aws_role_arn // empty' /tmp/input)

# if role arn has been provided, assume role
if ! [ -z "$AWS_ROLE_ARN" ]; then
aws sts assume-role \
--duration 900 \
--role-arn $AWS_ROLE_ARN \
--role-session-name ci \
--output json \
> /tmp/session
export AWS_ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' /tmp/session)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' /tmp/session)
export AWS_SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' /tmp/session)
fi

# remove any empty credentials vars so the AWS client will try instance profiles
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
Expand Down