Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .catalog-onboard-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ offerings:
kind: solution
catalog_id: 7df1e4ca-d54c-4fd0-82ce-3d13247308cd
offering_id: b0a00765-ee91-4c2a-87fc-df46dbc58cdb
include_git_submodules: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you leave a code comment saying why this is needed?

variations:
- name: fully-configurable
mark_ready: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
- name: post deploy playbook
hosts: localhost
tasks:
- name: get running ansible env variables
set_fact:
workspace_id: "{{ lookup('env', 'workspace_id') }}"
ibmcloud_api_key: "{{ lookup('env', 'ibmcloud_api_key')}}" # pragma: allowlist secret
cluster_id: "{{ lookup('env', 'cluster_id') }}"
access_key: "{{ lookup('env', 'access_key') }}"
existing_access_key_secret_name: "{{ lookup('env', 'existing_access_key_secret_name') }}"
cluster_resource_group_id: "{{ lookup('env', 'cluster_resource_group_id') }}"
- name: Creating script
copy:
dest: "script.sh"
content: |
#!/bin/bash

workspace_id="{{ workspace_id }}"
ibmcloud_api_key="{{ ibmcloud_api_key }}" # pragma: allowlist secret
cluster_id="{{ cluster_id }}"
access_key="{{ access_key }}"
existing_access_key_secret_name="{{ existing_access_key_secret_name }}"

attempts=1
# Expects the environment variable $IBMCLOUD_API_KEY to be set
until ibmcloud login --apikey "$ibmcloud_api_key" -q --no-region || [ $attempts -ge 3 ]; do
attempts=$((attempts+1))
echo "Error logging in to IBM Cloud CLI..." >&2
sleep 5
done

if [ -n "$access_key" ]; then
input=$(ibmcloud resource service-keys -o json | jq -r --arg access_key "$access_key" '.[] | select(.credentials."Sysdig Access Key" == $access_key).source_crn')
tmp="${input%%::}"
instance_id="${tmp##*:}"
elif [ -n "$existing_access_key_secret_name" ]; then
input=$(ibmcloud resource service-key "$existing_access_key_secret_name" -o json | jq -r --arg name "$existing_access_key_secret_name" '.[] | select(.name == $name).source_crn')
tmp="${input%%::}"
instance_id="${tmp##*:}"
fi

if [ -n "$instance_id" ]; then
ibmcloud resource tag-attach --resource-id "$(ibmcloud resource service-instance "$cluster_id" --crn -q)" --tag-names "monitoring-instance:$instance_id,mwp-workspace:$workspace_id"
fi

- name: Run the script
ansible.builtin.script:
cmd: ./script.sh
register: move_list
changed_when: false
ignore_errors: yes