Skip to content

Commit 58bd1f2

Browse files
authored
fix: updated the confirm_lb_active.sh and reset_iks_api_key.sh scripts to honour IBM Cloud enviornemnt variable overrides (#583)
1 parent d794438 commit 58bd1f2

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ module "ocp_base" {
119119

120120
### Customizing default cloud service endpoints.
121121

122-
The user must export the endpoint as an environment variable in order to use custom cloud service endpoints with this module. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints#1-define-service-endpoints-by-using-environment-variables).
122+
The user must export the endpoint as an environment variable in order to use custom cloud service endpoints with this module. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints#getting-started-with-custom-service-endpoints).
123123

124-
**Important** The only supported method for customizing cloud service endpoints is to export the endpoint; be sure to export the value for `IBMCLOUD_API_ENDPOINT`. For example,
124+
**Important** The only supported method for customizing cloud service endpoints is to export the enviroment variables endpoint; be sure to export the value for `IBMCLOUD_IAM_API_ENDPOINT`, `IBMCLOUD_CS_API_ENDPOINT` and `IBMCLOUD_IS_NG_API_ENDPOINT`. For example,
125125
```
126-
export IBMCLOUD_API_ENDPOINT="<endpoint_url>"
126+
export IBMCLOUD_IAM_API_ENDPOINT="<endpoint_url>"
127+
export IBMCLOUD_CS_API_ENDPOINT="<endpoint_url>"
128+
export IBMCLOUD_IS_NG_API_ENDPOINT="<endpoint_url>"
127129
```
128130

129131
### Secure by default cluster settings

scripts/confirm_lb_active.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set -euo pipefail
55
REGION="$1"
66
LB_ID="$2"
77
PRIVATE_ENV="$3"
8-
CLOUD_ENDPOINT=""
98
API_VERSION="2024-03-01"
109

1110
if [[ -z "${REGION}" ]]; then
@@ -14,16 +13,21 @@ if [[ -z "${REGION}" ]]; then
1413
fi
1514

1615
get_cloud_endpoint() {
17-
cloud_endpoint="${IBMCLOUD_API_ENDPOINT:-"cloud.ibm.com"}"
18-
CLOUD_ENDPOINT=${cloud_endpoint#https://}
16+
cloud_endpoint="${IBMCLOUD_IS_NG_API_ENDPOINT:-"iaas.cloud.ibm.com"}"
17+
IBMCLOUD_IS_NG_API_ENDPOINT=${cloud_endpoint#https://}
1918
}
2019

2120
get_cloud_endpoint
21+
2222
lb_attempts=1
23-
if [ "$PRIVATE_ENV" = true ]; then
24-
URL="https://$REGION.private.iaas.$CLOUD_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
23+
if [ "$IBMCLOUD_IS_NG_API_ENDPOINT" = "iaas.cloud.ibm.com" ]; then
24+
if [ "$PRIVATE_ENV" = true ]; then
25+
URL="https://$REGION.private.$IBMCLOUD_IS_NG_API_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
26+
else
27+
URL="https://$REGION.$IBMCLOUD_IS_NG_API_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
28+
fi
2529
else
26-
URL="https://$REGION.iaas.$CLOUD_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
30+
URL="https://$IBMCLOUD_IS_NG_API_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
2731
fi
2832

2933
while true; do

scripts/reset_iks_api_key.sh

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RESOURCE_GROUP_ID="$2"
77
APIKEY_KEY_NAME="containers-kubernetes-key"
88
PRIVATE_ENV="$3"
99
CLUSTER_ENDPOINT="$4"
10-
CLOUD_ENDPOINT=""
1110

1211
if [[ -z "${REGION}" ]]; then
1312
echo "Region must be passed as first input script argument" >&2
@@ -20,16 +19,24 @@ if [[ -z "${RESOURCE_GROUP_ID}" ]]; then
2019
fi
2120

2221
get_cloud_endpoint() {
23-
cloud_endpoint="${IBMCLOUD_API_ENDPOINT:-"cloud.ibm.com"}"
24-
CLOUD_ENDPOINT=${cloud_endpoint#https://}
22+
iam_cloud_endpoint="${IBMCLOUD_IAM_API_ENDPOINT:-"iam.cloud.ibm.com"}"
23+
IBMCLOUD_IAM_API_ENDPOINT=${iam_cloud_endpoint#https://}
24+
25+
cs_api_endpoint="${IBMCLOUD_CS_API_ENDPOINT:-"containers.cloud.ibm.com"}"
26+
cs_api_endpoint=${cs_api_endpoint#https://}
27+
IBMCLOUD_CS_API_ENDPOINT=${cs_api_endpoint%/global}
2528
}
2629

2730
get_cloud_endpoint
2831

29-
if [ "$PRIVATE_ENV" = true ]; then
30-
IAM_URL="https://private.iam.$CLOUD_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
32+
if [ "$IBMCLOUD_IAM_API_ENDPOINT" = "iam.cloud.ibm.com" ]; then
33+
if [ "$PRIVATE_ENV" = true ]; then
34+
IAM_URL="https://private.$IBMCLOUD_IAM_API_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
35+
else
36+
IAM_URL="https://$IBMCLOUD_IAM_API_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
37+
fi
3138
else
32-
IAM_URL="https://iam.$CLOUD_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
39+
IAM_URL="https://$IBMCLOUD_IAM_API_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
3340
fi
3441

3542
reset=true
@@ -59,18 +66,24 @@ fetch_data() {
5966
fetch_data
6067

6168
if [ "${reset}" == true ]; then
62-
if [ "$PRIVATE_ENV" = true ]; then
63-
if [ "$CLUSTER_ENDPOINT" == "private" ] || [ "$CLUSTER_ENDPOINT" == "default" ]; then
64-
RESET_URL="https://private.$REGION.containers.$CLOUD_ENDPOINT/v1/keys"
65-
result=$(curl -i -H "accept: application/json" -H "Authorization: $IAM_TOKEN" -H "X-Auth-Resource-Group: $RESOURCE_GROUP_ID" -X POST "$RESET_URL" 2>/dev/null)
66-
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
67-
elif [ "$CLUSTER_ENDPOINT" == "vpe" ]; then
68-
RESET_URL="https://api.$REGION.containers.$CLOUD_ENDPOINT/v1/keys"
69-
result=$(curl -i -H "accept: application/json" -H "Authorization: $IAM_TOKEN" -H "X-Auth-Resource-Group: $RESOURCE_GROUP_ID" -X POST "$RESET_URL" 2>/dev/null)
69+
if [ "$IBMCLOUD_CS_API_ENDPOINT" = "containers.cloud.ibm.com" ]; then
70+
if [ "$PRIVATE_ENV" = true ]; then
71+
if [ "$CLUSTER_ENDPOINT" == "private" ] || [ "$CLUSTER_ENDPOINT" == "default" ]; then
72+
RESET_URL="https://private.$REGION.$IBMCLOUD_CS_API_ENDPOINT/v1/keys"
73+
result=$(curl -i -H "accept: application/json" -H "Authorization: $IAM_TOKEN" -H "X-Auth-Resource-Group: $RESOURCE_GROUP_ID" -X POST "$RESET_URL" 2>/dev/null)
74+
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
75+
elif [ "$CLUSTER_ENDPOINT" == "vpe" ]; then
76+
RESET_URL="https://api.$REGION.$IBMCLOUD_CS_API_ENDPOINT/v1/keys"
77+
result=$(curl -i -H "accept: application/json" -H "Authorization: $IAM_TOKEN" -H "X-Auth-Resource-Group: $RESOURCE_GROUP_ID" -X POST "$RESET_URL" 2>/dev/null)
78+
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
79+
fi
80+
else
81+
RESET_URL="https://$IBMCLOUD_CS_API_ENDPOINT/global/v1/keys"
82+
result=$(curl -i -H "accept: application/json" -H "X-Region: $REGION" -H "Authorization: $IAM_TOKEN" -H "X-Auth-Resource-Group: $RESOURCE_GROUP_ID" -X POST "$RESET_URL" -d '' 2>/dev/null)
7083
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
7184
fi
7285
else
73-
RESET_URL="https://containers.$CLOUD_ENDPOINT/global/v1/keys"
86+
RESET_URL="https://$IBMCLOUD_CS_API_ENDPOINT/global/v1/keys"
7487
result=$(curl -i -H "accept: application/json" -H "X-Region: $REGION" -H "Authorization: $IAM_TOKEN" -H "X-Auth-Resource-Group: $RESOURCE_GROUP_ID" -X POST "$RESET_URL" -d '' 2>/dev/null)
7588
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
7689
fi

0 commit comments

Comments
 (0)