Terraform-provider-newrelic: Unable to specify payload for webhook in json

Created on 19 Sep 2018  路  6Comments  路  Source: newrelic/terraform-provider-newrelic

Terraform Version

Terraform v0.10.8

Affected Resource(s)

  • newrelic_alert_channel with type of webhook

Terraform Configuration Files

resource "newrelic_alert_channel" "webhooktest" {
  name = "webhooktest"
  type = "webhook"

  configuration = {
    payload_type    = "application/json"
    auth_username   = "my_user",
    auth_password   = "my_password",
    base_url        = "thirdpartyurl",
    payload         = {"priority": 3, "status": 2, "description": "New Relic Notification"}
  }
}

Expected Behavior

Create alert channel with payload in json format.

Actual Behavior

Error: Error parsing main.tf: At 28:34: illegal char

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Most helpful comment

@danger-cabbage @bridgetlane
I was able to get around the error in the terraform provider by using this hack:

resource "null_resource" "fresh_alert_channel" {

provisioner "local-exec" {
command = < curl -X POST 'https://api.newrelic.com/v2/alerts_channels.json' \
-H 'X-Api-Key:my_key -i \
-H 'Content-Type: application/json' \
-d \
'{
"channel": {
"name": "my_channel",
"type": "webhook",
"configuration": {
"base_url": "thirdpartyurl",
"auth_username": "my_user",
"auth_password": "my_password",
"payload_type": "application/json",
"headers": {"Content-Type": "application/json"},
"payload": {"priority": 3, "status": 2, "description": "New Relic Notification"}
}
}
}'
EOF
}

provisioner "local-exec" {
when = "destroy"

command = <<EOF

export channel_id=curl -X GET 'https://api.newrelic.com/v2/alerts_channels.json' -H 'X-Api-Key:my_key' | jq --raw-output '.channels[] | select(.name=="my_channel")'.id;
curl -X DELETE "https://api.newrelic.com/v2/alerts_channels/$channel_id.json" \
-H 'X-Api-Key:my_key' -i
EOF
}
}

All 6 comments

@sharpjl What line is line 28? Can you either direct me to the line or include your entire .tf file so that I can try to reproduce?

@sharpjl, did you ever figure this out?

Does anyone have an example of setting the payload? @bridgetlane

`resource "newrelic_alert_channel" "alert_bla" {
name = "bla bla"
type = "webhook"

configuration = {
base_url = "url here"
payload_type = "application/json"
payload = "${map("account_id","$ACCOUNT_ID")}"
}
}`

I've tried all below

payload = { "key" : "value" } // Inappropriate value for attribute "configuration": element "payload": string required.

payload = "${map("key","value")}" // Inappropriate value for attribute "configuration": element "payload": string required.

payload = "{ \"key\" : \"value\" }" // Error: configuration.payload must be in key/value format.

payload = "${file(var.json_file_name)}" // Error: configuration.payload must be in key/value format.

@danger-cabbage @bridgetlane
No. Well I solved it but in a hacky way. To reproduce the error that I'm seeing, drop this code

resource "newrelic_alert_channel" "webhooktest" {
name = "webhooktest"
type = "webhook"

configuration = {
payload_type = "application/json"
auth_username = "my_user",
auth_password = "my_password",
base_url = "thirdpartyurl",
payload = {"priority": 3, "status": 2, "description": "New Relic Notification"}
}
}

into a file called temp.tf and execute terraform init and you will see this error:

$ terraform init
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Error parsing /home/sharpjl/newrelic/main.tf: At 10:34: illegal char

Where line 10 character 34 is the first : in the payload line.

@danger-cabbage @bridgetlane
I was able to get around the error in the terraform provider by using this hack:

resource "null_resource" "fresh_alert_channel" {

provisioner "local-exec" {
command = < curl -X POST 'https://api.newrelic.com/v2/alerts_channels.json' \
-H 'X-Api-Key:my_key -i \
-H 'Content-Type: application/json' \
-d \
'{
"channel": {
"name": "my_channel",
"type": "webhook",
"configuration": {
"base_url": "thirdpartyurl",
"auth_username": "my_user",
"auth_password": "my_password",
"payload_type": "application/json",
"headers": {"Content-Type": "application/json"},
"payload": {"priority": 3, "status": 2, "description": "New Relic Notification"}
}
}
}'
EOF
}

provisioner "local-exec" {
when = "destroy"

command = <<EOF

export channel_id=curl -X GET 'https://api.newrelic.com/v2/alerts_channels.json' -H 'X-Api-Key:my_key' | jq --raw-output '.channels[] | select(.name=="my_channel")'.id;
curl -X DELETE "https://api.newrelic.com/v2/alerts_channels/$channel_id.json" \
-H 'X-Api-Key:my_key' -i
EOF
}
}

Duplicate of #66

Please continue future discussion in #66.

Was this page helpful?
0 / 5 - 0 ratings