Tasks
The /tasks
endpoints interact with the tasks that Consul-Terraform-Sync (CTS) is responsible for running.
If you run CTS with high availability enabled, you can send requests to the /tasks
endpoint on CTS leader or follower instances. Requests to a follower instance, however, return a 400 Bad Request and error message. The error message depends on what information the follower instance is able to obtain about the leader. Refer to Error Messages for more information.
Get Tasks
This endpoint returns information about all existing tasks.
Method | Path | Produces |
---|---|---|
GET | /tasks | application/json |
Response Statuses
Status | Reason |
---|---|
200 | Successfully retrieved and returned a list of tasks |
Response Fields
Name | Type | Description |
---|---|---|
request_id | string | The ID of the request. Used for auditing and debugging purposes. |
tasks | list[Task] | A list of Tasks |
Example: Retrieve all tasks
In this example, CTS contains a single task
Request:
Response:
Get Task
This endpoint returns information about an existing task.
Method | Path | Produces |
---|---|---|
GET | /tasks/:task_name | application/json |
Request Parameters
Name | Required | Type | Description | Default |
---|---|---|---|---|
:task_name | Required | string | Specifies the name of the task to retrieve | none |
Response Statuses
Status | Reason |
---|---|
200 | Successfully retrieved and returned task information |
404 | Task with the given name not found |
Response Fields
Name | Type | Description |
---|---|---|
request_id | string | The ID of the request. Used for auditing and debugging purposes. |
task | object | The task's configuration information. See task object for details. |
Example: Retrieve a task
Request:
Response:
Create Task
This endpoint allows for creation of a task. It only supports creation of a new task, and does not support updating a task.
Method | Path | Produces |
---|---|---|
POST | /tasks | application/json |
Request Parameters
Name | Required | Type | Description | Default |
---|---|---|---|---|
run | Optional | string | Values can only be "inspect" and "now" .
| none |
Request Body
Name | Required | Type | Description |
---|---|---|---|
task | Required | object | The task's configuration information. See task object for details. |
Response Statuses
Status | Reason |
---|---|
201 | Successfully created the task |
Response Fields
Name | Type | Description |
---|---|---|
request_id | string | The ID of the request. Used for auditing and debugging purposes. |
task | object | The task's configuration information after creation. See task object for details. |
Example: Create a task
Payload:
Request:
Response:
Update Task
This endpoint allows patch updates to specifically supported fields for existing tasks. Currently only supports updating a task's enabled
value.
Method | Path | Produces |
---|---|---|
PATCH | /tasks/:task_name | application/json |
Request Parameters
Name | Required | Type | Description | Default |
---|---|---|---|---|
:task_name | Required | string | Specifies the name of the task to update | none |
run | Optional | string | Values can only be "inspect" and "now" .
| none |
Request Body
Name | Required | Type | Description |
---|---|---|---|
enabled | Required | boolean | Whether the task is enabled to run and manage resources. |
Response Statuses
Status | Reason |
---|---|
200 | Successfully updated the task |
404 | Task with the given name not found |
Response Fields
Name | Type | Description |
---|---|---|
inspect | object | Information on how resources would be changed given a proposed task update, similar to inspect-mode. This is only returned when passed the run=inspect request parameter. |
inspect.changes_present | boolean | Whether or not changes were detected for running the proposed task update. |
inspect.plan | string | The Terraform plan generated for the proposed task update. Note: a non-empty string does not necessarily indicate changes were detected. |
Example: Disable a task
Request:
Response:
Example: Inspect enabling a task
Request:
Response if no changes present:
Response if changes present:
Delete Task
This endpoint allows for deletion of existing tasks. It marks a task for deletion based on the name provided. If the task is not running, it will be deleted immediately. Otherwise, it will be deleted once the task is completed.
Note: Deleting a task will not destroy the infrastructure managed by the task.
Method | Path | Produces |
---|---|---|
DELETE | /tasks/:task_name | application/json |
Request Parameters
Name | Required | Type | Description | Default |
---|---|---|---|---|
:task_name | Required | string | Specifies the name of the task to retrieve | none |
Response Statuses
Status | Reason |
---|---|
202 | Successfully marked the task for deletion |
404 | Task with the given name not found |
Response Fields
Name | Type | Description |
---|---|---|
request_id | string | The ID of the request. Used for auditing and debugging purposes. |
Sample Request
Sample Response
Task Object
The task object is used by the Task APIs as part of a request or response. It represents the task's configuration information.
Name | Required | Type | Description | Default |
---|---|---|---|---|
buffer_period | object | Optional | The buffer period for triggering task execution. | The global buffer period configured for CTS. |
buffer_period.enabled | bool | Optional | Whether the buffer period is enabled or disabled. | The global buffer period's enabled value configured for CTS. |
buffer_period.min | string | Optional | The minimum period of time to wait after changes are detected before triggering the task. | The global buffer period's min value configured for CTS. |
buffer_period.max | string | Optional | The maximum period of time to wait after changes are detected before triggering the task. | The global buffer period's max value configured for CTS. |
condition | object | Required | The condition on which to trigger the task to execute. If the task has the deprecated services field configured as a module input, it is represented here as condition.services . | none |
description | string | Optional | The human readable text to describe the task. | none |
enabled | bool | Optional | Whether the task is enabled or disabled from executing. | true |
module | string | Required | The location of the Terraform module. | none |
module_input | object | Optional | The additional module input(s) that the tasks provides to the Terraform module on execution. If the task has the deprecated services field configured as a module input, it is represented here as module_input.services . | none |
name | string | Required | The unique name of the task. | none |
providers | list[string] | Optional | The list of provider names that the task's module uses. | none |
variables | map[string] | Optional | The map of variables that are provided to the task's module. | none |
version | string | Optional | The version of the configured module that the task uses. | The latest version. |
terraform_version | string | Optional | Enterprise Deprecated in CTS 0.6.0 and will be removed in 0.8.0. Review terraform_version in terraform_cloud_workspace instead. The version of Terraform to use for the Terraform Cloud workspace associated with the task. This is only available when used with the Terraform Cloud driver. | The latest compatible version supported by the organization. |
terraform_cloud_workspace | object | Optional | Enterprise The configurable attributes of the Terraform Cloud workspace associated with the task. This option is only available when used with the Terraform Cloud driver. | none |