1

I am trying to make a POST request to Azure DevOps API using curl code within a terraform script.

resource "null_resource" "AzDo_API_request" {
  provisioner "local-exec" {
      command = <<EOT
        curl -L -X POST "https://dev.azure.com/altabhussain0027/_apis/hooks/subscriptions?api-version=7.1-preview.1"
        -H "Authorization: Basic OnBobHdxcm1sb2Fvb3ZwZDZmbHZobjdiMnNoYXJ2aTRqdWNsYjJqNnpyemQ3dG9jYWh0eGE="
        -H "Content-Type: application/json"
        --data-raw "{
            \"consumerActionId\": \"httpRequest\",
            \"consumerId\": \"webHooks\",
            \"consumerInputs\": {
                \"url\": \"https://pulse-xxx.com/webhook/c29ac65b-xxxx-xxxx-xxxx-f4dc16d3114e\"
            },
            \"eventType\": \"workitem.updated\",
            \"publisherId\": \"tfs\",
            \"publisherInputs\": {
                \"areaPath\": \"any\",
                \"workItemType\": \"Feature\",
                \"projectId\": \"b0eb9e33-xxxx-xxx-xxxx-68866d0dd821\"
            },
            \"resourceVersion\": \"1.0\",
            \"scope\": \"all\"
        }"
EOT
  }
}

The above curl code is generated from Postman wherein the POST request are successfull without giving error. However, when executing the same using terraform, I am getting the below error:

null_resource.AzDo_API_request (local-exec): curl: (3) URL using bad/illegal format or missing URL
    │ Error: local-exec provisioner error
    │
    │   with null_resource.AzDo_API_request,
    │   on servicehook.tf line 2, in resource "null_resource" "AzDo_API_request":

I am running the above in Windows 11 machine, it might have to do with the double quotes. Any help is appreciated.

  • 1
    I'd put that curl call into a shell script and provide that instead of a command. – Marko E Jul 14 '22 at 16:41
  • I doubt you get support for this. As @MarkoE said it's better to put into a shell script & execute or even [external data source](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/data_source) is desirable. – harshavmb Jul 15 '22 at 08:28
  • @harshavmb https://stackoverflow.com/questions/51197781/terraform-rest-api-calls-with-curl . This one wold work on linux only? – Abhishek Rai Jul 15 '22 at 09:51
  • In that case, [restapi](https://github.com/Mastercard/terraform-provider-restapi) generic API provider could be used. @AbhishekRai – harshavmb Jul 15 '22 at 10:08

0 Answers0