Skip to content

Commit 7c73594

Browse files
committed
fix: opt in region test to correct account
Signed-off-by: Kevin Shan <[email protected]>
1 parent f1c23f4 commit 7c73594

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

scripts/e2e-test-regions.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{ "name": "ap-east-1", "optIn": true },
3+
{ "name": "ap-northeast-1", "optIn": false },
4+
{ "name": "ap-northeast-2", "optIn": false },
5+
{ "name": "ap-northeast-3", "optIn": false },
6+
{ "name": "ap-south-1", "optIn": false },
7+
{ "name": "ap-southeast-1", "optIn": false },
8+
{ "name": "ap-southeast-2", "optIn": false },
9+
{ "name": "ca-central-1", "optIn": false },
10+
{ "name": "eu-central-1", "optIn": false },
11+
{ "name": "eu-north-1", "optIn": false },
12+
{ "name": "eu-south-1", "optIn": true },
13+
{ "name": "eu-west-1", "optIn": false },
14+
{ "name": "eu-west-2", "optIn": false },
15+
{ "name": "eu-west-3", "optIn": false },
16+
{ "name": "me-south-1", "optIn": true },
17+
{ "name": "sa-east-1", "optIn": false },
18+
{ "name": "us-east-1", "optIn": false },
19+
{ "name": "us-east-2", "optIn": false },
20+
{ "name": "us-west-1", "optIn": false },
21+
{ "name": "us-west-2", "optIn": false }
22+
]

shared-scripts.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,26 @@ function _unassumeTestAccountCredentials {
339339
function useChildAccountCredentials {
340340
if [ -z "$USE_PARENT_ACCOUNT" ]; then
341341
export AWS_PAGER=""
342+
export AWS_MAX_ATTEMPTS=5
343+
export AWS_STS_REGIONAL_ENDPOINTS=regional
342344
parent_acct=$(aws sts get-caller-identity | jq -cr '.Account')
343345
child_accts=$(aws organizations list-accounts | jq -c "[.Accounts[].Id | select(. != \"$parent_acct\")]")
344346
org_size=$(echo $child_accts | jq 'length')
345-
pick_acct=$(echo $child_accts | jq -cr ".[$RANDOM % $org_size]")
347+
opt_in_regions=$(jq -r '.[] | select(.optIn == true) | .name' $CODEBUILD_SRC_DIR/scripts/e2e-test-regions.json)
348+
if echo "$opt_in_regions" | grep -qw "$CLI_REGION"; then
349+
child_accts=$(echo $child_accts | jq -cr '.[]')
350+
for child_acct in $child_accts; do
351+
# Get enabled opt-in regions for the child account
352+
enabled_regions=$(aws account list-regions --account-id $child_acct --region-opt-status-contains ENABLED)
353+
# Check if given opt-in region is enabled for the child account
354+
if echo "$enabled_regions" | jq -e ".Regions[].RegionName == \"$CLI_REGION\""; then
355+
pick_acct=$child_acct
356+
break
357+
fi
358+
done
359+
else
360+
pick_acct=$(echo $child_accts | jq -cr ".[$RANDOM % $org_size]")
361+
fi
346362
session_id=$((1 + $RANDOM % 10000))
347363
if [[ -z "$pick_acct" || -z "$session_id" ]]; then
348364
echo "Unable to find a child account. Falling back to parent AWS account"

0 commit comments

Comments
 (0)