From 7c083e421d1cfe7a9637760f1a01e5fbda3c528d Mon Sep 17 00:00:00 2001 From: Sean Sundberg Date: Mon, 28 Mar 2022 16:32:55 -0500 Subject: [PATCH] Updates handling of ibmcloud cli (#18) - Loads ibmcloud cli and ob plugin using cli submodule - Removes unneeded setup-ob-plugin script - Updates tests to run on terraform v1.1 image with minimal dependencies - Updates module metadata to refer to clusters using the interface Closes #17 Signed-off-by: Sean Sundberg --- .github/scripts/validate-deploy.sh | 4 ++++ .github/workflows/verify.yaml | 2 +- main.tf | 21 ++++++++++++++------- module.yaml | 9 ++------- scripts/bind-instance.sh | 4 ++++ scripts/ibmcloud-login.sh | 4 ++++ scripts/setup-ob-plugin.sh | 11 ----------- scripts/unbind-instance.sh | 4 ++++ test/stages/stage-logdna.tf | 2 +- test/stages/stage0.tf | 12 ++++++++++++ 10 files changed, 46 insertions(+), 27 deletions(-) delete mode 100755 scripts/setup-ob-plugin.sh diff --git a/.github/scripts/validate-deploy.sh b/.github/scripts/validate-deploy.sh index 25a5d0c..1396ed3 100755 --- a/.github/scripts/validate-deploy.sh +++ b/.github/scripts/validate-deploy.sh @@ -2,6 +2,10 @@ KUBECONFIG=$(cat ./kubeconfig) +BIN_DIR=$(cat .bin_dir) + +export PATH="${BIN_DIR}:${PATH}" + echo "Checking for logdna-agent daemonset" if ! kubectl get daemonset logdna-agent -n ibm-observe; then echo "logdna-agent daemonset not found" diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index ba61ab5..7c2b9e8 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -13,7 +13,7 @@ jobs: verify: if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }} runs-on: ubuntu-latest - container: quay.io/ibmgaragecloud/cli-tools:v0.12.0-lite + container: quay.io/cloudnativetoolkit/terraform:v1.1 strategy: matrix: diff --git a/main.tf b/main.tf index e9b0879..65be15e 100644 --- a/main.tf +++ b/main.tf @@ -5,6 +5,12 @@ locals { bind = true } +module setup_clis { + source = "github.com/cloud-native-toolkit/terraform-util-clis.git" + + clis = ["ibmcloud-ob"] +} + resource null_resource print_names { provisioner "local-exec" { @@ -37,22 +43,18 @@ resource null_resource ibmcloud_login { 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" "setup-ob-plugin" { - provisioner "local-exec" { - command = "${path.module}/scripts/setup-ob-plugin.sh" - } -} - resource "null_resource" "logdna_bind" { count = local.bind ? 1 : 0 - depends_on = [null_resource.setup-ob-plugin, null_resource.ibmcloud_login] + depends_on = [null_resource.ibmcloud_login] triggers = { + bin_dir = module.setup_clis.bin_dir cluster_id = var.cluster_id instance_id = var.logdna_id } @@ -61,6 +63,7 @@ resource "null_resource" "logdna_bind" { 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 } } @@ -68,5 +71,9 @@ resource "null_resource" "logdna_bind" { provisioner "local-exec" { when = destroy command = "${path.module}/scripts/unbind-instance.sh ${self.triggers.cluster_id} ${self.triggers.instance_id}" + + environment = { + BIN_DIR = self.triggers.bin_dir + } } } diff --git a/module.yaml b/module.yaml index c4ec013..1a7ced4 100644 --- a/module.yaml +++ b/module.yaml @@ -11,13 +11,8 @@ versions: - ocp4 dependencies: - id: cluster - refs: - - source: github.com/cloud-native-toolkit/terraform-ibm-container-platform - version: ">= 1.7.0" - - source: github.com/cloud-native-toolkit/terraform-ibm-ocp-vpc - version: ">= 1.0.0" - - source: github.com/cloud-native-toolkit/terraform-k8s-ocp-cluster - version: ">= 2.0.0" + interface: github.com/cloud-native-toolkit/automation-modules#cluster + refs: [] - id: resource_group refs: - source: github.com/cloud-native-toolkit/terraform-ibm-resource-group diff --git a/scripts/bind-instance.sh b/scripts/bind-instance.sh index c63e738..fb41c6c 100755 --- a/scripts/bind-instance.sh +++ b/scripts/bind-instance.sh @@ -14,6 +14,10 @@ else PRIVATE="" fi +if [[ -n "${BIN_DIR}" ]]; then + export PATH="${BIN_DIR}:${PATH}" +fi + echo "Configuring LogDNA for ${CLUSTER_ID} cluster and ${INSTANCE_ID} LogDNA instance" ibmcloud target diff --git a/scripts/ibmcloud-login.sh b/scripts/ibmcloud-login.sh index 34c45d3..ffad49c 100755 --- a/scripts/ibmcloud-login.sh +++ b/scripts/ibmcloud-login.sh @@ -8,6 +8,10 @@ if [[ -z "${APIKEY}" ]]; then exit 1 fi +if [[ -n "${BIN_DIR}" ]]; then + export PATH="${BIN_DIR}:${PATH}" +fi + ibmcloud config --check-version=false ibmcloud login -r "${REGION}" -g "${RESOURCE_GROUP}" --apikey "${APIKEY}" diff --git a/scripts/setup-ob-plugin.sh b/scripts/setup-ob-plugin.sh deleted file mode 100755 index 5eccaa4..0000000 --- a/scripts/setup-ob-plugin.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -if ibmcloud plugin list | grep -q observe-service; then - echo "The ibmcloud cli observe-service plugin is already installed" -else - sleep $(( (RANDOM % 60) + 10 )) - if ! ibmcloud plugin list | grep -q observe-service; then - echo "Installing the ibmcloud cli observe-service" - ibmcloud plugin install observe-service -f - fi -fi diff --git a/scripts/unbind-instance.sh b/scripts/unbind-instance.sh index e0354b6..515c108 100755 --- a/scripts/unbind-instance.sh +++ b/scripts/unbind-instance.sh @@ -6,6 +6,10 @@ MODULE_DIR=$(cd ${SCRIPT_DIR}/..; pwd -P) CLUSTER_ID="$1" INSTANCE_ID="$2" +if [[ -n "${BIN_DIR}" ]]; then + export PATH="${BIN_DIR}:${PATH}" +fi + ibmcloud ob logging config delete \ --cluster "${CLUSTER_ID}" \ --instance "${INSTANCE_ID}" \ diff --git a/test/stages/stage-logdna.tf b/test/stages/stage-logdna.tf index b63670d..4b2c16a 100644 --- a/test/stages/stage-logdna.tf +++ b/test/stages/stage-logdna.tf @@ -3,6 +3,6 @@ module "logdna" { resource_group_name = var.resource_group_name region = var.region - provision = false + provision = true name_prefix = var.name_prefix } diff --git a/test/stages/stage0.tf b/test/stages/stage0.tf index ca88e62..6e03bb5 100644 --- a/test/stages/stage0.tf +++ b/test/stages/stage0.tf @@ -1,2 +1,14 @@ terraform { } +module setup_clis { + source = "github.com/cloud-native-toolkit/terraform-util-clis.git" + + bin_dir = "${path.cwd}/test_bin_dir" + clis = ["kubectl", "oc"] +} + +resource local_file bin_dir { + filename = "${path.cwd}/.bin_dir" + + content = module.setup_clis.bin_dir +}