Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update the script to use respective endpoint variable #583

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ module "ocp_base" {

### Customizing default cloud service endpoints.

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).
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).

**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,
**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,
```
export IBMCLOUD_API_ENDPOINT="<endpoint_url>"
export IBMCLOUD_IAM_API_ENDPOINT="<endpoint_url>"
export IBMCLOUD_CS_API_ENDPOINT="<endpoint_url>"
export IBMCLOUD_IS_NG_API_ENDPOINT="<endpoint_url>"
```

### Secure by default cluster settings
Expand Down
16 changes: 10 additions & 6 deletions scripts/confirm_lb_active.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -euo pipefail
REGION="$1"
LB_ID="$2"
PRIVATE_ENV="$3"
CLOUD_ENDPOINT=""
API_VERSION="2024-03-01"

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

get_cloud_endpoint() {
cloud_endpoint="${IBMCLOUD_API_ENDPOINT:-"cloud.ibm.com"}"
CLOUD_ENDPOINT=${cloud_endpoint#https://}
cloud_endpoint="${IBMCLOUD_IS_NG_API_ENDPOINT:-"iaas.cloud.ibm.com"}"
IBMCLOUD_IS_NG_API_ENDPOINT=${cloud_endpoint#https://}
}

get_cloud_endpoint

lb_attempts=1
if [ "$PRIVATE_ENV" = true ]; then
URL="https://$REGION.private.iaas.$CLOUD_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
if [ "$IBMCLOUD_IS_NG_API_ENDPOINT" = "iaas.cloud.ibm.com" ]; then
if [ "$PRIVATE_ENV" = true ]; then
URL="https://$REGION.private.$IBMCLOUD_IS_NG_API_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
else
URL="https://$REGION.$IBMCLOUD_IS_NG_API_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
fi
else
URL="https://$REGION.iaas.$CLOUD_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
URL="https://$IBMCLOUD_IS_NG_API_ENDPOINT/v1/load_balancers/$LB_ID?version=$API_VERSION&generation=2"
fi

while true; do
Expand Down
19 changes: 11 additions & 8 deletions scripts/reset_iks_api_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ RESOURCE_GROUP_ID="$2"
APIKEY_KEY_NAME="containers-kubernetes-key"
PRIVATE_ENV="$3"
CLUSTER_ENDPOINT="$4"
CLOUD_ENDPOINT=""

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

get_cloud_endpoint() {
cloud_endpoint="${IBMCLOUD_API_ENDPOINT:-"cloud.ibm.com"}"
CLOUD_ENDPOINT=${cloud_endpoint#https://}
iam_cloud_endpoint="${IBMCLOUD_IAM_API_ENDPOINT:-"iam.cloud.ibm.com"}"
iam_cloud_endpoint=${iam_cloud_endpoint#https://}

cs_api_endpoint="${IBMCLOUD_CS_API_ENDPOINT:-"containers.cloud.ibm.com"}"
cs_api_endpoint=${cs_api_endpoint#https://}
IBMCLOUD_CS_API_ENDPOINT=${cs_api_endpoint%/global}
}

get_cloud_endpoint

if [ "$PRIVATE_ENV" = true ]; then
IAM_URL="https://private.iam.$CLOUD_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
IAM_URL="https://private.$IBMCLOUD_IAM_API_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
else
IAM_URL="https://iam.$CLOUD_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
IAM_URL="https://$IBMCLOUD_IAM_API_ENDPOINT/v1/apikeys?account_id=$ACCOUNT_ID&scope=account&pagesize=100&type=user&sort=name"
fi

reset=true
Expand Down Expand Up @@ -61,16 +64,16 @@ fetch_data
if [ "${reset}" == true ]; then
if [ "$PRIVATE_ENV" = true ]; then
if [ "$CLUSTER_ENDPOINT" == "private" ] || [ "$CLUSTER_ENDPOINT" == "default" ]; then
RESET_URL="https://private.$REGION.containers.$CLOUD_ENDPOINT/v1/keys"
RESET_URL="https://private.$REGION.$IBMCLOUD_CS_API_ENDPOINT/v1/keys"
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)
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
elif [ "$CLUSTER_ENDPOINT" == "vpe" ]; then
RESET_URL="https://api.$REGION.containers.$CLOUD_ENDPOINT/v1/keys"
RESET_URL="https://api.$REGION.$IBMCLOUD_CS_API_ENDPOINT/v1/keys"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if all override API endpoints support region, will need to test this.

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)
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
fi
else
RESET_URL="https://containers.$CLOUD_ENDPOINT/global/v1/keys"
RESET_URL="https://$IBMCLOUD_CS_API_ENDPOINT/global/v1/keys"
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)
status_code=$(echo "$result" | head -n 1 | cut -d$' ' -f2)
fi
Expand Down