Terraform Cloud API response payload to create/trigger a run for the workspace

210 views Asked by At

error image Im new to Terraform Cloud learning and implementing facing challenge on following Terraform Cloud REST API triggering it from postman.

POST: https://app.terraform.io/api/v2/runs

{
  "data": {
    "attributes": {
      "message": "Triggered by Postman",
      "is-destroy": false,
       "auto-apply": true,
       "var": {
        "resource_group": "terraformcloud-RG",
        "storage_account": "MicrosoftWindowsServer",
        "region": "eastus"
        
        }
    },
    "relationships": {
      "workspace": {
        "data": {
          "type": "workspaces",
          "id": "id"
        }
      }
    },
    "type": "runs"
  }
}

Here my concern is it not retrieving the values of varaibles which am passing on the response body even my terraform script has main.tf and var.tf and i have set the variable and values on the under workspace by default it is picking those values from that not from which im passing on above response body. I'm sure I'm missing some concept. Can someone please explain me or link a specific part of Terraform docs?

Thanks for anyone who'll help!

1

There are 1 answers

2
Martin Atkins On

The API operation you are accessing here is Create a Run.

The documentation for that operation does not mention a request property named var. Instead, the property is named variables.

Also, the documentation describes this property as expecting an array of objects with key and value properties, rather than a single object acting as a dynamic map.

Therefore it seems the correct way to specify this property with the values you showed in your question would be:

  "variables": [
    {"key": "resource_group", "value": "terraformcloud-RG"},
    {"key": "storage_account", "value": "MicrosoftWindowsServer"},
    {"key": "region", "value": "eastus"}
  ]