Skip to content

Commit 0afe243

Browse files
Get New Relic app ID dynamically
1 parent 3214df9 commit 0afe243

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

bin/terraform.sh

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function output () {
9393

9494
function plan() {
9595
local extra
96+
local nr_app_id
9697
local output
9798
local -i retcode
9899
local targets
@@ -101,6 +102,15 @@ function plan() {
101102
targets=$(get_targets)
102103

103104
set +e
105+
106+
nr_app_id=$(curl \
107+
-s \
108+
-X GET \
109+
'https://api.newrelic.com/v2/applications.json' \
110+
-H "X-Api-Key:${NEWRELIC_API_KEY}" \
111+
-d "filter[name]=${NEWRELIC_APP_NAME}" \
112+
| jq '.applications[].id')
113+
104114
#shellcheck disable=SC2086
105115
$DOCKER_TERRAFORM plan \
106116
$extra \
@@ -111,6 +121,7 @@ function plan() {
111121
-var newrelic_license_key="$NEWRELIC_LICENSE_KEY" \
112122
-var newrelic_api_key="$NEWRELIC_API_KEY" \
113123
-var newrelic_alert_email="$NEWRELIC_ALERT_EMAIL" \
124+
-var newrelic_apm_entities="[$nr_app_id]" \
114125
-var-file="/app/build/extra.tfvars" \
115126
-out="$TF_PLAN" \
116127
"$TF_DIR" \

env.sh.sample

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ export GOOGLE_REGION=us-east1
3636
export NEWRELIC_LICENSE_KEY=ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
3737
export NEWRELIC_API_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3838
39+
export NEWRELIC_APP_NAME=Spin

0 commit comments

Comments
 (0)