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

Updates handling of login #32

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
2 changes: 1 addition & 1 deletion test/stages/stage1-resource-group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module "resource_group" {
source = "github.com/cloud-native-toolkit/terraform-ibm-resource-group.git"

resource_group_name = var.resource_group_name
provision = false
ibmcloud_api_key = var.ibmcloud_api_key
}