Skip to content

Commit c9b6744

Browse files
Chris Nelsonjdub
authored andcommitted
use the same strategy for instance profiles as jdub/packer-resource
1 parent fd75923 commit c9b6744

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

bin/check

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ cat | jq . <&0 > /tmp/input
66

77
AMI=$(jq -r '.version.ami // empty' /tmp/input)
88

9-
AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // empty' /tmp/input)
10-
AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // empty' /tmp/input)
11-
if [ -n "${AWS_ACCESS_KEY_ID}" ] && [ -n "${AWS_SECRET_ACCESS_KEY}" ]; then
12-
export AWS_ACCESS_KEY_ID
13-
export AWS_SECRET_ACCESS_KEY
14-
fi
9+
export AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // empty' /tmp/input)
10+
export AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // empty' /tmp/input)
1511
export AWS_DEFAULT_REGION=$(jq -r '.source.region // empty' /tmp/input)
1612

13+
# remove any empty credentials vars so the AWS client will try instance profiles
14+
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
15+
unset AWS_ACCESS_KEY_ID
16+
fi
17+
18+
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
19+
unset AWS_SECRET_ACCESS_KEY
20+
fi
21+
1722
jq '.source.filters | to_entries | map({"Name": .key, "Values": [(.value|select(type!="array") = [.])|.[]|tostring]})' /tmp/input > /tmp/filters.json
1823

1924
aws ec2 describe-images \

bin/in

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ DEST="$1"
88

99
AMI=$(jq -r '.version.ami // empty' /tmp/input)
1010

11-
AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // empty' /tmp/input)
12-
AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // empty' /tmp/input)
13-
if [ -n "${AWS_ACCESS_KEY_ID}" ] && [ -n "${AWS_SECRET_ACCESS_KEY}" ]; then
14-
export AWS_ACCESS_KEY_ID
15-
export AWS_SECRET_ACCESS_KEY
16-
fi
11+
export AWS_ACCESS_KEY_ID=$(jq -r '.source.aws_access_key_id // empty' /tmp/input)
12+
export AWS_SECRET_ACCESS_KEY=$(jq -r '.source.aws_secret_access_key // empty' /tmp/input)
1713
export AWS_DEFAULT_REGION=$(jq -r '.source.region // empty' /tmp/input)
1814

15+
# remove any empty credentials vars so the AWS client will try instance profiles
16+
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
17+
unset AWS_ACCESS_KEY_ID
18+
fi
19+
20+
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
21+
unset AWS_SECRET_ACCESS_KEY
22+
fi
23+
1924
aws ec2 describe-images --image-ids "$AMI" --query 'Images[0]' \
2025
| tee "$DEST/output.json"
2126

0 commit comments

Comments
 (0)