Skip to content

Commit

Permalink
#2582 Another round of datadog env vars
Browse files Browse the repository at this point in the history
Applying updated environment variables in support of datadog python api client naming expectations.
  • Loading branch information
Erik Nelsestuen committed Feb 14, 2024
1 parent 06061d1 commit a4b358a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
13 changes: 9 additions & 4 deletions helm/_shared/named_templates/_datadog.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
*/}}

{{- define "vro.datadog.envVars" -}}
- name: DATADOG_API_KEY
- name: DD_SITE
valueFrom:
secretKeyRef:
name: vro-datadog
key: DATADOG_API_KEY
- name: DATADOG_API_KEY_ID
key: DD_SITE
- name: DD_API_KEY
valueFrom:
secretKeyRef:
name: vro-datadog
key: DATADOG_API_KEY_ID
key: DD_API_KEY
- name: DD_APP_KEY
valueFrom:
secretKeyRef:
name: vro-datadog
key: DD_APP_KEY
{{- end }}
48 changes: 48 additions & 0 deletions scripts/set-datadog-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# Adds details needed for datadog api.
# Script expects to be executed from the repository's root directory
# abd_vro> ./scripts/set-datadog-secret.sh TARGET_ENV DATADOG_API_KEY DATADOG_API_KEY_ID

# https://github.com/DataDog/datadog-api-client-python/blob/4f81d425324d7719fc5ee7a56c7e4bae0f3f848f/src/datadog_api_client/configuration.py#L175
# based on DataDog Python api client we need the following environment variables populated:
# * DD_SITE (see datadog python api client - https://github.com/DataDog/datadog-api-client-python/blob/4f81d425324d7719fc5ee7a56c7e4bae0f3f848f/src/datadog_api_client/configuration.py#L175)
# * DD_API_KEY (see DATADOG_API_KEY in vault)
# * DD_APP_KEY (see DATADOG_API_KEY_ID in vault)

if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "Usage: $0 \"<TARGET_ENV>\" \"<paste DATADOG_API_KEY>\" \"<paste DATADOG_API_KEY_ID>\""
exit 1
fi

: "${TARGET_ENV:=$1}"
: "${DD_SITE:=https://api.ddog-gov.com}"
: "${DD_API_KEY:=$2}"
: "${DD_APP_KEY:=$3}"

DD_SITE="$(echo -n "$DD_SITE" | base64)"
DD_API_KEY="$(echo -n "$DD_API_KEY" | base64)"
DD_APP_KEY="$(echo -n "$DD_APP_KEY" | base64)"

case "${TARGET_ENV}" in
dev|qa|sandbox) choice="y"; echo "Executing $0 for env: $TARGET_ENV";;
prod-test|prod) read -rp "Executing $0 for env: $TARGET_ENV Please Confirm (y/n)?" choice;;
*) echo "Unknown TARGET_ENV: $TARGET_ENV"
exit 3
;;
esac


case "$choice" in
y|Y ) echo "$TARGET_ENV confirmed: yes";;
* ) echo "$TARGET_ENV was not confirmed"
exit 4
;;
esac

SECRET_MAP="
DD_SITE: \"$DD_SITE\"
DD_API_KEY: \"$DD_API_KEY\"
DD_APP_KEY: \"$DD_APP_KEY\"
"
./scripts/echo-secret-yaml.sh "vro-datadog" "$SECRET_MAP" | \
kubectl -n "va-abd-rrd-$TARGET_ENV" replace --force -f -

0 comments on commit a4b358a

Please sign in to comment.