Skip to content

Instantly share code, notes, and snippets.

@stenio123
Last active January 18, 2019 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stenio123/02858799d81920d96e86a09ceeae3f01 to your computer and use it in GitHub Desktop.
Save stenio123/02858799d81920d96e86a09ceeae3f01 to your computer and use it in GitHub Desktop.
Example API calls interacting with Terraform Enterprise

Example API calls interacting with Terraform Enterprise

Get list of workspaces

curl   --header "Authorization: Bearer ${TFE_TOKEN}"   --header "Content-Type: application/vnd.api+json"   $TFE_ADDR/api/v2/organizations/$TFE_ORG/workspaces | jq .

You can have the above in a loop, or to get a specific workspace:

# id of the first workspace returned
| jq .data[0].id

# Name of the first workspace returned
| jq .data[0].attributes.name

Trigger a plan for a specific workspace

# Create a payload file with WORKSPACE_ID

# payload.json 
{
  "data": {
    "attributes": {
      "is-destroy":false
    },
    "type":"runs",
    "relationships": {
      "workspace": {
        "data": {
          "type": "workspaces",
          "id": "workspace-id"
        }
      }
    }
  }
}

curl --header "Authorization: Bearer ${TFE_TOKEN}" --header "Content-Type: application/vnd.api+json" --data @payload.json https://${TFE_ADDR}/api/v2/runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment