• Overview
    • Enforce Policy as Code
    • Infrastructure as Code
    • Inject Secrets into Terraform
    • Integrate with Existing Workflows
    • Manage Kubernetes
    • Manage Virtual Machine Images
    • Multi-Cloud Deployment
    • Network Infrastructure Automation
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
  • Registry
  • Tutorials
    • About the Docs
    • Intro to Terraform
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
    • Terraform Tools
    • CDK for Terraform
    • Glossary
  • Community
GitHubTerraform Cloud
Download

    Terraform Cloud and Enterprise

  • Overview
  • Plans and Features
  • Getting Started
    • API Docs template
    • Overview
    • Account
    • Agent Pools
    • Agent Tokens
    • Applies
    • Audit Trails
    • Comments
    • Configuration Versions
    • Cost Estimates
    • Feature Sets
    • Invoices
    • IP Ranges
    • Notification Configurations
    • OAuth Clients
    • OAuth Tokens
    • Organizations
    • Organization Memberships
    • Organization Tags
    • Organization Tokens
    • Plan Exports
    • Plans
    • Policies
    • Policy Checks
    • Policy Sets
    • Policy Set Parameters
      • Modules
      • Providers
      • Private Provider Versions and Platforms
      • GPG Keys
    • Runs
      • Run Tasks
      • Stages and Results
      • Custom Integration
    • Run Triggers
    • SSH Keys
    • State Versions
    • State Version Outputs
    • Subscriptions
    • Team Access
    • Team Membership
    • Team Tokens
    • Teams
    • User Tokens
    • Users
    • Variables
    • VCS Events
    • Workspaces
    • Workspace-Specific Variables
    • Workspace Resources
    • Variable Sets
      • Overview
      • Module Sharing
      • Organizations
      • Runs
      • Settings
      • Terraform Versions
      • Users
      • Workspaces
    • Changelog
    • Stability Policy
    • Overview
    • Creating Workspaces
    • Naming
    • Terraform Configurations
      • Overview
      • Managing Variables
      • Overview
      • VCS Connections
      • Access
      • Drift Detection
      • Notifications
      • SSH Keys for Modules
      • Run Triggers
      • Run Tasks
    • Terraform State
    • JSON Filtering
    • Remote Operations
    • Viewing and Managing Runs
    • Run States and Stages
    • Run Modes and Options
    • UI/VCS-driven Runs
    • API-driven Runs
    • CLI-driven Runs
    • The Run Environment
    • Installing Software
    • Users
    • Teams
    • Organizations
    • Permissions
    • Two-factor Authentication
    • API Tokens
      • Overview
      • Microsoft Azure AD
      • Okta
      • SAML
      • Linking a User Account
      • Testing
    • Overview
    • GitHub.com
    • GitHub.com (OAuth)
    • GitHub Enterprise
    • GitLab.com
    • GitLab EE and CE
    • Bitbucket Cloud
    • Bitbucket Server and Data Center
    • Azure DevOps Services
    • Azure DevOps Server
    • Troubleshooting
    • Overview
    • Adding Public Providers and Modules
    • Publishing Private Providers
    • Publishing Private Modules
    • Using Providers and Modules
    • Configuration Designer
  • Migrating to Terraform Cloud
    • Overview
    • Using Sentinel with Terraform 0.12
    • Manage Policies
    • Enforce and Override Policies
    • Mocking Terraform Sentinel Data
    • Working With JSON Result Data
      • Overview
      • tfconfig
      • tfconfig/v2
      • tfplan
      • tfplan/v2
      • tfstate
      • tfstate/v2
      • tfrun
    • Example Policies
    • Overview
    • AWS
    • GCP
    • Azure
      • Overview
      • Service Catalog
      • Admin Guide
      • Developer Reference
      • Example Customizations
      • V1 Setup Instructions
    • Splunk Integration
    • Kubernetes Integration
    • Run Tasks Integration
    • Overview
    • IP Ranges
    • Data Security
    • Security Model
    • Overview
    • Part 1: Overview of Our Recommended Workflow
    • Part 2: Evaluating Your Current Provisioning Practices
    • Part 3: How to Evolve Your Provisioning Practices
    • Part 3.1: From Manual Changes to Semi-Automation
    • Part 3.2: From Semi-Automation to Infrastructure as Code
    • Part 3.3: From Infrastructure as Code to Collaborative Infrastructure as Code
    • Part 3.4: Advanced Workflow Improvements

  • Terraform Cloud Agents

  • Terraform Enterprise Admin

  • Other Docs

  • Intro to Terraform
  • Configuration Language
  • Terraform CLI
  • Terraform Cloud
  • Terraform Enterprise
  • Provider Use
  • Plugin Development
  • Registry Publishing
  • Integration Program
  • Terraform Tools
  • CDK for Terraform
  • Glossary
Type '/' to Search

»Run Tasks API

Note: Run Tasks is a paid feature, available as part of the Team & Governance upgrade package. Refer to Terraform Cloud pricing for details.

Run tasks allow Terraform Cloud to interact with external systems at specific points in the Terraform Cloud run lifecycle. Run tasks are reusable configurations that you can attach to any workspace in an organization. This page lists the API endpoints for run tasks in an organization and explains how to attach run tasks to workspaces.

Refer to run tasks Integration for the API endpoints related triggering run tasks and the expected integration response.

»Required Permissions

To interact with run tasks on an organization, you need the Manage Run Tasks permission. To associate or dissociate run tasks in a workspace, you need the Manage Workspace Run Tasks permission on that particular workspace.

»Create a Run Task

POST /organizations/:organization_name/tasks

ParameterDescription
:organization_nameThe organization to create a run task in. The organization must already exist in Terraform Cloud, and the token authenticating the API request must have owner permission.
StatusResponseReason
201JSON API document (type: "tasks")Successfully created a run task
404JSON API error objectOrganization not found, or user unauthorized to perform action
422JSON API error objectMalformed request body (missing attributes, wrong types, etc.)

»Request Body

This POST endpoint requires a JSON object with the following properties as a request payload.

Properties without a default value are required unless otherwise specified.

Key pathTypeDefaultDescription
data.typestringMust be "tasks".
data.attributes.namestringThe name of the task. Can include letters, numbers, -, and _.
data.attributes.urlstringURL to send a run task payload.
data.attributes.descriptionstringThe description of the run task. Can include spaces, letters, numbers, and special characters
data.attributes.categorystringMust be "task".
data.attributes.hmac-keystring(Optional) HMAC key to verify run task.
data.attributes.enabledbooltrue(Optional) Whether the task will be run.

»Sample Payload

{
  "data": {
    "type": "tasks",
      "attributes": {
        "name": "example",
        "url": "http://example.com",
        "description": "Simple description",
        "hmac_key": "secret",
        "enabled": "true",
        "category": "task"
      }
  }
}
{
  "data": {
    "type": "tasks",
      "attributes": {
        "name": "example",
        "url": "http://example.com",
        "description": "Simple description",
        "hmac_key": "secret",
        "enabled": "true",
        "category": "task"
      }
  }
}

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request POST \
  --data @payload.json \
  https://app.terraform.io/api/v2/organizations/my-organization/tasks
curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request POST \
  --data @payload.json \
  https://app.terraform.io/api/v2/organizations/my-organization/tasks

»Sample Response

{
  "data": {
    "id": "task-7oD7doVTQdAFnMLV",
      "type": "tasks",
      "attributes": {
        "category": "task",
        "name": "my-run-task",
        "url": "http://example.com",
        "description": "Simple description",
        "enabled": "true",
        "hmac-key": null,
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "hashicorp",
            "type": "organizations"
          }
        },
        "tasks": {
          "data": []
        }
      },
      "links": {
        "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
      }
  }
}
{
  "data": {
    "id": "task-7oD7doVTQdAFnMLV",
      "type": "tasks",
      "attributes": {
        "category": "task",
        "name": "my-run-task",
        "url": "http://example.com",
        "description": "Simple description",
        "enabled": "true",
        "hmac-key": null,
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "hashicorp",
            "type": "organizations"
          }
        },
        "tasks": {
          "data": []
        }
      },
      "links": {
        "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
      }
  }
}

»List Run Tasks

GET /organizations/:organization_name/tasks

ParameterDescription
:organization_nameThe organization to list tasks for.
StatusResponseReason
200JSON API document (type: "tasks")Request was successful
404JSON API error objectOrganization not found, or user unauthorized to perform action

»Query Parameters

This endpoint supports pagination with standard URL query parameters. Remember to percent-encode [ as %5B and ] as %5D if your tooling doesn't automatically encode URLs.

ParameterDescription
includeOptional. Allows including related resource data. Value must be a comma-separated list containing one or more of workspace_tasks or workspace_tasks.workspace.
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 policy sets per page.

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  https://app.terraform.io/api/v2/organizations/my-organization/tasks
curl \
  --header "Authorization: Bearer $TOKEN" \
  https://app.terraform.io/api/v2/organizations/my-organization/tasks

»Sample Response

{
    "data": [
        {
            "id": "task-7oD7doVTQdAFnMLV",
            "type": "tasks",
            "attributes": {
                "category": "task",
                "name": "my-task",
                "url": "http://example.com",
                "description": "Simple description",
                "enabled": "true",
                "hmac-key": null,
            },
            "relationships": {
                "organization": {
                    "data": {
                        "id": "hashicorp",
                        "type": "organizations"
                    }
                },
                "tasks": {
                    "data": []
                }
            },
            "links": {
                "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
            }
        }
    ],
    "links": {
        "self": "https://app.terraform.io/api/v2/organizations/hashicorp/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
        "first": "https://app.terraform.io/api/v2/organizations/hashicorp/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
        "prev": null,
        "next": null,
        "last": "https://app.terraform.io/api/v2/organizations/hashicorp/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20"
    },
    "meta": {
        "pagination": {
            "current-page": 1,
            "page-size": 20,
            "prev-page": null,
            "next-page": null,
            "total-pages": 1,
            "total-count": 1
        }
    }
}
{
    "data": [
        {
            "id": "task-7oD7doVTQdAFnMLV",
            "type": "tasks",
            "attributes": {
                "category": "task",
                "name": "my-task",
                "url": "http://example.com",
                "description": "Simple description",
                "enabled": "true",
                "hmac-key": null,
            },
            "relationships": {
                "organization": {
                    "data": {
                        "id": "hashicorp",
                        "type": "organizations"
                    }
                },
                "tasks": {
                    "data": []
                }
            },
            "links": {
                "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
            }
        }
    ],
    "links": {
        "self": "https://app.terraform.io/api/v2/organizations/hashicorp/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
        "first": "https://app.terraform.io/api/v2/organizations/hashicorp/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
        "prev": null,
        "next": null,
        "last": "https://app.terraform.io/api/v2/organizations/hashicorp/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20"
    },
    "meta": {
        "pagination": {
            "current-page": 1,
            "page-size": 20,
            "prev-page": null,
            "next-page": null,
            "total-pages": 1,
            "total-count": 1
        }
    }
}

»Show a Run Task

GET /tasks/:id

ParameterDescription
:idThe ID of the task to show. Use the "List Run Tasks" endpoint to find IDs.
StatusResponseReason
200JSON API document (type: "tasks")The request was successful
404JSON API error objectRun task not found or user unauthorized to perform action
ParameterDescription
includeOptional. Allows including related resource data. Value must be a comma-separated list containing one or more of workspace_tasks or workspace_tasks.workspace.

»Sample Request

curl --request GET \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  https://app.terraform.io/api/v2/tasks/task-7oD7doVTQdAFnMLV
curl --request GET \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  https://app.terraform.io/api/v2/tasks/task-7oD7doVTQdAFnMLV

»Sample Response

{
  "data": {
    "id": "task-7oD7doVTQdAFnMLV",
      "type": "tasks",
      "attributes": {
        "category": "task",
        "name": "my-task",
        "url": "http://example.com",
        "description": "Simple description",
        "enabled": "true",
        "hmac-key": null,
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "hashicorp",
            "type": "organizations"
          }
        },
        "tasks": {
          "data": [
          {
            "id": "task-xjKZw9KaeXda61az",
            "type": "tasks"
          }
          ]
        }
      },
      "links": {
        "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
      }
  }
}
{
  "data": {
    "id": "task-7oD7doVTQdAFnMLV",
      "type": "tasks",
      "attributes": {
        "category": "task",
        "name": "my-task",
        "url": "http://example.com",
        "description": "Simple description",
        "enabled": "true",
        "hmac-key": null,
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "hashicorp",
            "type": "organizations"
          }
        },
        "tasks": {
          "data": [
          {
            "id": "task-xjKZw9KaeXda61az",
            "type": "tasks"
          }
          ]
        }
      },
      "links": {
        "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
      }
  }
}

»Update a Run Task

PATCH /tasks/:id

ParameterDescription
:idThe ID of the task to update. Use the "List Run Tasks" endpoint to find IDs.
StatusResponseReason
200JSON API document (type: "tasks")The request was successful
404JSON API error objectRun task not found or user unauthorized to perform action
422JSON API error objectMalformed request body (missing attributes, wrong types, etc.)

»Request Body

This PATCH endpoint requires a JSON object with the following properties as a request payload.

Properties without a default value are required unless otherwise specified.

Key pathTypeDefaultDescription
data.typestringMust be "tasks".
data.attributes.namestring(previous value)The name of the run task. Can include letters, numbers, -, and _.
data.attributes.urlstring(previous value)URL to send a run task payload.
data.attributes.descriptionstringThe description of the run task. Can include spaces, letters, numbers, and special characters
data.attributes.categorystring(previous value)Must be "task".
data.attributes.hmac-keystring(previous value)(Optional) HMAC key to verify run task.
data.attributes.enabledbool(previous value)(Optional) Whether the task will be run.

»Sample Payload

{
  "data": {
    "type": "tasks",
      "attributes": {
        "name": "new-example",
        "url": "http://new-example.com",
        "description": "New description",
        "hmac_key": "new-secret",
        "enabled": "false",
        "category": "task"
      }
  }
}
{
  "data": {
    "type": "tasks",
      "attributes": {
        "name": "new-example",
        "url": "http://new-example.com",
        "description": "New description",
        "hmac_key": "new-secret",
        "enabled": "false",
        "category": "task"
      }
  }
}

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request PATCH \
  --data @payload.json \
  https://app.terraform.io/api/v2/tasks/task-7oD7doVTQdAFnMLV
curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request PATCH \
  --data @payload.json \
  https://app.terraform.io/api/v2/tasks/task-7oD7doVTQdAFnMLV

»Sample Response

{
  "data": {
    "id": "task-7oD7doVTQdAFnMLV",
      "type": "tasks",
      "attributes": {
        "category": "task",
        "name": "new-example",
        "url": "http://new-example.com",
        "description": "New description",
        "enabled": "false",
        "hmac-key": null,
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "hashicorp",
            "type": "organizations"
          }
        },
        "tasks": {
          "data": [
          {
            "id": "wstask-xjKZw9KaeXda61az",
            "type": "workspace-tasks"
          }
          ]
        }
      },
      "links": {
        "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
      }
  }
}
{
  "data": {
    "id": "task-7oD7doVTQdAFnMLV",
      "type": "tasks",
      "attributes": {
        "category": "task",
        "name": "new-example",
        "url": "http://new-example.com",
        "description": "New description",
        "enabled": "false",
        "hmac-key": null,
      },
      "relationships": {
        "organization": {
          "data": {
            "id": "hashicorp",
            "type": "organizations"
          }
        },
        "tasks": {
          "data": [
          {
            "id": "wstask-xjKZw9KaeXda61az",
            "type": "workspace-tasks"
          }
          ]
        }
      },
      "links": {
        "self": "/api/v2/tasks/task-7oD7doVTQdAFnMLV"
      }
  }
}

»Delete a Run Task

DELETE /tasks/:id

ParameterDescription
:idThe ID of the run task to delete. Use the "List Run Tasks" endpoint to find IDs.
StatusResponseReason
204NothingSuccessfully deleted the run task
404JSON API error objectRun task not found, or user unauthorized to perform action

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request DELETE \
  https://app.terraform.io/api/v2/tasks/task-7oD7doVTQdAFnMLV
curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request DELETE \
  https://app.terraform.io/api/v2/tasks/task-7oD7doVTQdAFnMLV

»Attach a Run Task to a Workspace

POST /workspaces/:workspace_id/tasks

ParameterDescription
:workspace_idThe ID of the workspace.
StatusResponseReason
204NothingThe request was successful
404JSON API error objectWorkspace or run task not found or user unauthorized to perform action
422JSON API error objectMalformed request body

»Request Body

This POST endpoint requires a JSON object with the following properties as a request payload.

Properties without a default value are required.

Key pathTypeDefaultDescription
data.typestringMust be "workspace-tasks".
data.attributes.enforcement-levelstringThe enforcement level of the workspace task. Must be "advisory" or "mandatory".
data.relationships.task.data.idstringThe ID of the run task.
data.relationships.task.data.typestringMust be "tasks".

»Sample Payload

{
  "data": {
    "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-7oD7doVTQdAFnMLV",
            "type": "tasks"
          }
        }
      }
  }
}
{
  "data": {
    "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-7oD7doVTQdAFnMLV",
            "type": "tasks"
          }
        }
      }
  }
}

»Sample Request

curl \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  --request POST \
  --data @payload.json \
  https://app.terraform.io/api/v2/workspaces/ws-PphL7ix3yGasYGrq/tasks
curl \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  --request POST \
  --data @payload.json \
  https://app.terraform.io/api/v2/workspaces/ws-PphL7ix3yGasYGrq/tasks

»Sample Response

{
  "data": {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-7oD7doVTQdAFnMLV",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-PphL7ix3yGasYGrq",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-PphL7ix3yGasYGrq/tasks/task-tBXYu8GVAFBpcmPm"
      }
  }
}
{
  "data": {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-7oD7doVTQdAFnMLV",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-PphL7ix3yGasYGrq",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-PphL7ix3yGasYGrq/tasks/task-tBXYu8GVAFBpcmPm"
      }
  }
}

»List Workspace Run Tasks

GET /workspaces/:workspace_id/tasks

ParameterDescription
:workspace_idThe workspace to list tasks for.
StatusResponseReason
200JSON API document (type: "tasks")Request was successful
404JSON API error objectWorkspace not found, or user unauthorized to perform action

»Query Parameters

This endpoint supports pagination with standard URL query parameters. Remember to percent-encode [ as %5B and ] as %5D if your tooling doesn't automatically encode URLs.

ParameterDescription
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 policy sets per page.

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks
curl \
  --header "Authorization: Bearer $TOKEN" \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks

»Sample Response

{
  "data": [
  {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-hu74ST39g566Q4m5",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-kRsDRPtTmtcEme4t",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/task-tBXYu8GVAFBpcmPm"
      }
  }
  ],
  "links": {
    "self": "https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "first": "https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "prev": null,
    "next": null,
    "last": "https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20"
  },
  "meta": {
    "pagination": {
      "current-page": 1,
      "page-size": 20,
      "prev-page": null,
      "next-page": null,
      "total-pages": 1,
      "total-count": 1
    }
  }
}
{
  "data": [
  {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-hu74ST39g566Q4m5",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-kRsDRPtTmtcEme4t",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/task-tBXYu8GVAFBpcmPm"
      }
  }
  ],
  "links": {
    "self": "https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "first": "https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "prev": null,
    "next": null,
    "last": "https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks?page%5Bnumber%5D=1&page%5Bsize%5D=20"
  },
  "meta": {
    "pagination": {
      "current-page": 1,
      "page-size": 20,
      "prev-page": null,
      "next-page": null,
      "total-pages": 1,
      "total-count": 1
    }
  }
}

»Show Workspace Run Task

GET /workspaces/:workspace_id/tasks/:id

ParameterDescription
:idThe ID of the workspace task to show. Use the "List Workspace Run Tasks" endpoint to find IDs.
StatusResponseReason
200JSON API document (type: "tasks")The request was successful
404JSON API error objectWorkspace run task not found or user unauthorized to perform action

»Sample Request

curl --request GET \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm
curl --request GET \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm

»Sample Response

{
  "data": {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-hu74ST39g566Q4m5",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-kRsDRPtTmtcEme4t",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm"
      }
  }
}
{
  "data": {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "advisory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-hu74ST39g566Q4m5",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-kRsDRPtTmtcEme4t",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm"
      }
  }
}

»Update Workspace Run Task

PATCH /workspaces/:workspace_id/tasks/:id

ParameterDescription
:idThe ID of the task to update. Use the "List Workspace Run Tasks" endpoint to find IDs.
StatusResponseReason
200JSON API document (type: "tasks")The request was successful
404JSON API error objectWorkspace run task not found or user unauthorized to perform action
422JSON API error objectMalformed request body (missing attributes, wrong types, etc.)

»Request Body

This PATCH endpoint requires a JSON object with the following properties as a request payload.

Properties without a default value are required.

Key pathTypeDefaultDescription
data.typestring(previous value)Must be "workspace-tasks".
data.attributes.enforcement-levelstring(previous value)The enforcement level of the workspace run task. Must be "advisory" or "mandatory".

»Sample Payload

{
  "data": {
    "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "mandatory"
      }
  }
}
{
  "data": {
    "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "mandatory"
      }
  }
}

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request PATCH \
  --data @payload.json \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm
curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request PATCH \
  --data @payload.json \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm

»Sample Response

{
  "data": {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "mandatory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-hu74ST39g566Q4m5",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-kRsDRPtTmtcEme4t",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/task-tBXYu8GVAFBpcmPm"
      }
  }
}
{
  "data": {
    "id": "wstask-tBXYu8GVAFBpcmPm",
      "type": "workspace-tasks",
      "attributes": {
        "enforcement-level": "mandatory",
        "stage": "post_plan"
      },
      "relationships": {
        "task": {
          "data": {
            "id": "task-hu74ST39g566Q4m5",
            "type": "tasks"
          }
        },
        "workspace": {
          "data": {
            "id": "ws-kRsDRPtTmtcEme4t",
            "type": "workspaces"
          }
        }
      },
      "links": {
        "self": "/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/task-tBXYu8GVAFBpcmPm"
      }
  }
}

»Delete Workspace Run Task

DELETE /workspaces/:workspace_id/tasks/:id

ParameterDescription
:idThe ID of the Workspace run task to delete. Use the "List Workspace Run Tasks" endpoint to find IDs.
StatusResponseReason
204NothingSuccessfully deleted the workspace run task
404JSON API error objectWorkspace run task not found, or user unauthorized to perform action

»Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request DELETE \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm
curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request DELETE \
  https://app.terraform.io/api/v2/workspaces/ws-kRsDRPtTmtcEme4t/tasks/wstask-tBXYu8GVAFBpcmPm
github logoEdit this page
  • Overview
  • Docs
  • Extend
  • Privacy
  • Security
  • Press Kit
  • Consent Manager