Skip to content

Commit a94b8d5

Browse files
committed
Auto-detect AWS Region from Config
Signed-off-by: Connor Catlett <[email protected]>
1 parent f3adda7 commit a94b8d5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

hack/e2e/config.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ mkdir -p "${TEST_DIR}"
2222
CLUSTER_FILE=${TEST_DIR}/${CLUSTER_NAME}.${CLUSTER_TYPE}.yaml
2323
KUBECONFIG=${KUBECONFIG:-"${TEST_DIR}/${CLUSTER_NAME}.${CLUSTER_TYPE}.kubeconfig"}
2424

25-
export AWS_REGION=${AWS_REGION:-us-west-2}
26-
ZONES=${AWS_AVAILABILITY_ZONES:-us-west-2a,us-west-2b,us-west-2c}
25+
# Use AWS_REGION as priority, fallback to region from awscli config, fallback to us-west-2
26+
REGION_FROM_CONFIG="$(aws configure get region)"
27+
export AWS_REGION=${AWS_REGION:-${REGION_FROM_CONFIG:-us-west-2}}
28+
# If zones are not provided, auto-detect the first 3 AZs that are not opt in
29+
ZONES=${AWS_AVAILABILITY_ZONES:-$(aws ec2 describe-availability-zones | jq -r '[.AvailabilityZones[] | select(.OptInStatus == "opt-in-not-required") | .ZoneName][:3] | join(",")')}
2730
FIRST_ZONE=$(echo "${ZONES}" | cut -d, -f1)
2831
NODE_COUNT=${NODE_COUNT:-3}
2932
INSTANCE_TYPE=${INSTANCE_TYPE:-c5.large}

0 commit comments

Comments
 (0)