Skip to content

Commit

Permalink
Updates handling of login
Browse files Browse the repository at this point in the history
closes #30

Signed-off-by: Sean Sundberg <seansund@us.ibm.com>
  • Loading branch information
seansund committed May 12, 2022
1 parent 28b31cd commit f4a2960
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
25 changes: 11 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,39 @@ resource "ibm_resource_key" "logdna_instance_key" {
}
}

resource null_resource ibmcloud_login {
provisioner "local-exec" {
command = "${path.module}/scripts/ibmcloud-login.sh ${var.region} ${var.resource_group_name}"

environment = {
BIN_DIR = module.setup_clis.bin_dir
APIKEY = var.ibmcloud_api_key
}
}
}

resource "null_resource" "logdna_bind" {
count = local.bind ? 1 : 0
depends_on = [null_resource.ibmcloud_login]

triggers = {
bin_dir = module.setup_clis.bin_dir
cluster_id = var.cluster_id
instance_id = var.logdna_id
region = var.region
resource_group = var.resource_group_name
ibmcloud_api_key = var.ibmcloud_api_key
}

provisioner "local-exec" {
command = "${path.module}/scripts/bind-instance.sh ${self.triggers.cluster_id} ${self.triggers.instance_id} ${ibm_resource_key.logdna_instance_key[0].name} ${var.private_endpoint}"
command = "${path.module}/scripts/bind-instance.sh '${self.triggers.cluster_id}' '${self.triggers.instance_id}' '${ibm_resource_key.logdna_instance_key[0].name}' '${var.private_endpoint}'"

environment = {
BIN_DIR = self.triggers.bin_dir
SYNC = var.sync
REGION = self.triggers.region
RESOURCE_GROUP = self.triggers.resource_group
IBMCLOUD_API_KEY = self.triggers.ibmcloud_api_key
}
}

provisioner "local-exec" {
when = destroy
command = "${path.module}/scripts/unbind-instance.sh ${self.triggers.cluster_id} ${self.triggers.instance_id}"
command = "${path.module}/scripts/unbind-instance.sh '${self.triggers.cluster_id}' '${self.triggers.instance_id}'"

environment = {
BIN_DIR = self.triggers.bin_dir
REGION = self.triggers.region
RESOURCE_GROUP = self.triggers.resource_group
IBMCLOUD_API_KEY = self.triggers.ibmcloud_api_key
}
}
}
18 changes: 17 additions & 1 deletion scripts/bind-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,25 @@ if [[ -n "${BIN_DIR}" ]]; then
export PATH="${BIN_DIR}:${PATH}"
fi

if [[ -z "${IBMCLOUD_API_KEY}" ]]; then
echo "IBMCLOUD_API_KEY must be provided as an environment variable" >&2
exit 1
fi

if [[ -z "${REGION}" ]]; then
echo "REGION must be provided as an environment variable" >&2
exit 1
fi

if [[ -z "${RESOURCE_GROUP}" ]]; then
echo "RESOURCE_GROUP must be provided as an environment variable" >&2
exit 1
fi

echo "Configuring LogDNA for ${CLUSTER_ID} cluster and ${INSTANCE_ID} LogDNA instance"

ibmcloud target
ibmcloud login -r "${REGION}" -g "${RESOURCE_GROUP}"

if ibmcloud ob logging config ls --cluster "${CLUSTER_ID}" | grep -q "Instance ID"; then
EXISTING_INSTANCE_ID=$(ibmcloud ob logging config ls --cluster "${CLUSTER_ID}" | grep "Instance ID" | sed -E "s/Instance ID: +([^ ]+)/\1/g")
if [[ "${EXISTING_INSTANCE_ID}" == "${INSTANCE_ID}" ]]; then
Expand Down
17 changes: 0 additions & 17 deletions scripts/ibmcloud-login.sh

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/unbind-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ if [[ -n "${BIN_DIR}" ]]; then
export PATH="${BIN_DIR}:${PATH}"
fi

if [[ -z "${IBMCLOUD_API_KEY}" ]]; then
echo "IBMCLOUD_API_KEY must be provided as an environment variable" >&2
exit 1
fi

if [[ -z "${REGION}" ]]; then
echo "REGION must be provided as an environment variable" >&2
exit 1
fi

if [[ -z "${RESOURCE_GROUP}" ]]; then
echo "RESOURCE_GROUP must be provided as an environment variable" >&2
exit 1
fi

ibmcloud login -r "${REGION}" -g "${RESOURCE_GROUP}"

ibmcloud ob logging config delete \
--cluster "${CLUSTER_ID}" \
--instance "${INSTANCE_ID}" \
Expand Down

0 comments on commit f4a2960

Please sign in to comment.