Skip to content

Commit

Permalink
Updates handling of ibmcloud cli (#18)
Browse files Browse the repository at this point in the history
- 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 <seansund@us.ibm.com>
  • Loading branch information
seansund authored Mar 28, 2022
1 parent 1ce7b6c commit 7c083e4
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .github/scripts/validate-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 14 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
}
Expand All @@ -61,12 +63,17 @@ 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
}
}

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
}
}
}
9 changes: 2 additions & 7 deletions module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions scripts/bind-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions scripts/ibmcloud-login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
11 changes: 0 additions & 11 deletions scripts/setup-ob-plugin.sh

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/unbind-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
2 changes: 1 addition & 1 deletion test/stages/stage-logdna.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions test/stages/stage0.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7c083e4

Please sign in to comment.