Skip to content

Commit 7d0a23a

Browse files
author
michaelsteven / seansund
committed
Adds scripts to log into ibmcloud and ibmcloud cluster
1 parent 69cdcc1 commit 7d0a23a

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

terraform/scripts/ibmcloud-cluster

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(cd $(dirname $0); pwd -P)
4+
ROOT_DIR=$(cd "${SCRIPT_DIR}/../.."; pwd -P)
5+
SETTINGS_DIR=$(cd "${SCRIPT_DIR}/../settings"; pwd -P)
6+
7+
function prop {
8+
grep "${1}" "${2}" | cut -d '=' -f2
9+
}
10+
11+
source ${SETTINGS_DIR}/environment.tfvars
12+
13+
RESOURCE_GROUP="${resource_group_name}"
14+
if [[ -z "${RESOURCE_GROUP}" ]]; then
15+
echo "resource_group_name is required in environment.tfvars"
16+
exit 1
17+
fi
18+
19+
REGION="${vlan_region}"
20+
if [[ -z "${REGION}" ]]; then
21+
echo "vlan_region is required in environment.tfvars"
22+
exit 1
23+
fi
24+
25+
APIKEY="${IBMCLOUD_API_KEY}"
26+
if [[ -z "${APIKEY}" ]]; then
27+
if [[ -f ${ROOT_DIR}/credentials.properties ]]; then
28+
APIKEY=$(prop 'ibmcloud.api.key' "${ROOT_DIR}/credentials.properties")
29+
else
30+
echo "${ROOT_DIR}/credentials.properties not found"
31+
fi
32+
fi
33+
34+
if [[ -z "${APIKEY}" ]]; then
35+
echo "APIKEY is required either as IBMCLOUD_API_KEY environment variable or in credentials.properties"
36+
exit 1
37+
fi
38+
39+
ibmcloud config --check-version=false 1> /dev/null 2> /dev/null
40+
41+
echo "Logging into ibmcloud: ${REGION}/${RESOURCE_GROUP}"
42+
ibmcloud login \
43+
--apikey ${APIKEY} \
44+
-g ${RESOURCE_GROUP} \
45+
-r ${REGION} 1> /dev/null 2> /dev/null
46+
47+
if [[ -n "${cluster_name}" ]]; then
48+
CLUSTER_NAME="${cluster_name}"
49+
elif [[ -n "${name_prefix}" ]]; then
50+
CLUSTER_NAME="${name_prefix}-cluster"
51+
else
52+
CLUSTER_NAME="${RESOURCE_GROUP}-cluster"
53+
fi
54+
55+
echo " Determining cluster type for cluster: ${CLUSTER_NAME}"
56+
OPENSHIFT=$(ibmcloud ks cluster get --cluster "${CLUSTER_NAME}" | grep Version | grep openshift)
57+
if [[ -z "${OPENSHIFT}" ]]; then
58+
export IKS_BETA_VERSION=1.0
59+
60+
echo "Logging into IKS cluster: ${CLUSTER_NAME}"
61+
ibmcloud ks cluster config --cluster "${CLUSTER_NAME}" 1> /dev/null 2> /dev/null
62+
else
63+
echo " Getting OpenShift server url"
64+
SERVER_URL=$(ibmcloud ks cluster get --cluster "${CLUSTER_NAME}" | grep "Public Service Endpoint URL" | sed -E "s/.*(http.*)/\1/g" | xargs -I{} echo -n {})
65+
66+
echo "Logging into OpenShift cluster: ${CLUSTER_NAME}"
67+
oc login -u apikey -p ${APIKEY} --server=${SERVER_URL} 1> /dev/null 2> /dev/null
68+
fi

terraform/scripts/ibmcloud-login

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(cd $(dirname $0); pwd -P)
4+
ROOT_DIR=$(cd "${SCRIPT_DIR}/../.."; pwd -P)
5+
6+
function prop {
7+
grep "${1}" "${2}" | cut -d '=' -f2
8+
}
9+
10+
source ${SCRIPT_DIR}/../settings/environment.tfvars
11+
12+
RESOURCE_GROUP="${resource_group_name}"
13+
if [[ -z "${RESOURCE_GROUP}" ]]; then
14+
echo "resource_group_name is required in environment.tfvars"
15+
exit 1
16+
fi
17+
18+
REGION="${vlan_region}"
19+
if [[ -z "${REGION}" ]]; then
20+
echo "vlan_region is required in environment.tfvars"
21+
exit 1
22+
fi
23+
24+
APIKEY="${IBMCLOUD_API_KEY}"
25+
if [[ -z "${APIKEY}" ]]; then
26+
if [[ -f ${ROOT_DIR}/credentials.properties ]]; then
27+
APIKEY=$(prop 'ibmcloud.api.key' "${ROOT_DIR}/credentials.properties")
28+
else
29+
echo "${ROOT_DIR}/credentials.properties not found"
30+
fi
31+
fi
32+
33+
if [[ -z "${APIKEY}" ]]; then
34+
echo "APIKEY is required either as IBMCLOUD_API_KEY environment variable or in credentials.properties"
35+
exit 1
36+
fi
37+
38+
if [[ -z "${TMP_DIR}" ]]; then
39+
TMP_DIR="./.tmp"
40+
fi
41+
42+
mkdir -p "${TMP_DIR}"
43+
44+
ibmcloud config --check-version=false 1> /dev/null 2> /dev/null
45+
46+
echo "Logging into ibmcloud: ${REGION}/${RESOURCE_GROUP}"
47+
ibmcloud login \
48+
--apikey ${APIKEY} \
49+
-g ${RESOURCE_GROUP} \
50+
-r ${REGION} 1> /dev/null 2> /dev/null

0 commit comments

Comments
 (0)