• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Terraform
  • Install
  • Tutorials
    • About the Docs
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • CDK for Terraform
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
  • Registry(opens in new tab)
  • Try Cloud(opens in new tab)
  • Sign up
Terraform Home

Terraform Cloud

Skip to main content
  • Terraform Cloud
  • Plans and Features
  • Getting Started
    • Overview
    • Account
    • Agent Pools
    • Agent Tokens
    • Applies
    • Audit Trails
    • Assessment Results
    • 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
    • Projects
    • Project Team Access
    • Runs
    • Run Triggers
    • SSH Keys
    • State Versions
    • State Version Outputs
    • Subscriptions
    • Team Membership
    • Team Tokens
    • Teams
    • User Tokens
    • Users
    • Variables
    • VCS Events
    • Workspaces
    • Workspace-Specific Variables
    • Workspace Team Access
    • Workspace Resources
    • Variable Sets
    • Changelog
    • Stability Policy
  • Migrating to Terraform Cloud

  • Terraform Cloud Agents

  • Resources

  • Tutorial Library
  • Certifications
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  • Terraform Registry
    (opens in new tab)
  1. Developer
  2. Terraform
  3. Terraform Cloud
  4. API
  5. Agent Pools

»Agent Pools and Agents API

An Agent Pool represents a group of Agents, often related to one another by sharing a common network segment or purpose. A workspace may be configured to use one of the organization's agent pools to run remote operations with isolated, private, or on-premises infrastructure.

Note: Terraform Cloud Agents are a paid feature, available as part of the Terraform Cloud for Business upgrade package. Learn more about Terraform Cloud pricing here.

List Agent Pools

GET /organizations/:organization_name/agent-pools

ParameterDescription
:organization_nameThe name of the organization.

This endpoint allows you to list agent pools, their agents, and their tokens for an organization.

StatusResponseReason
200JSON API document (type: "agent-pools")Success
404JSON API error objectOrganization not found

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
qOptional. A search query string. Agent pools are searchable by name.
sortOptional. Allows sorting the returned agents pools. Valid values are "name" and "created-at". Prepending a hyphen to the sort parameter will reverse the order (e.g. "-name").
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 agent pools per page.
filter[allowed_workspaces][name]Optional. Filters agent pools to those associated with the given workspace. The workspace must have permission to use the agent pool. Refer to Scoping Agent Pools to Specific Workspaces.

Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request GET \
  https://app.terraform.io/api/v2/organizations/my-organization/agent-pools

Sample Response

{
  "data": [
    {
      "id": "apool-yoGUFz5zcRMMz53i",
      "type": "agent-pools",
      "attributes": {
        "name": "example-pool",
        "created-at": "2020-08-05T18:10:26.964Z",
        "organization-scoped": false,
        "agent-count": 3
      },
      "relationships": {
        "agents": {
          "links": {
            "related": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/agents"
          }
        },
        "authentication-tokens": {
          "links": {
            "related": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/authentication-tokens"
          }
        },
        "workspaces": {
          "data": [
            {
              "id": "ws-9EEkcEQSA3XgWyGe",
              "type": "workspaces"
            }
          ]
        },
        "allowed-workspaces": {
          "data": [
            {
              "id": "ws-x9taqV23mxrGcDrn",
              "type": "workspaces"
            }
          ]
        }
      },
      "links": {
        "self": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i"
      }
    }
  ],
  "links": {
    "self": "https://app.terraform.io/api/v2/organizations/my-organization/agent-pools?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "first": "https://app.terraform.io/api/v2/organizations/my-organization/agent-pools?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "prev": null,
    "next": null,
    "last": "https://app.terraform.io/api/v2/organizations/my-organization/agent-pools?page%5Bnumber%5D=1&page%5Bsize%5D=20"
  },
  "meta": {
    "pagination": {
      "current-page": 1,
      "prev-page": null,
      "next-page": null,
      "total-pages": 1,
      "total-count": 1
    },
    "status-counts": {
      "total": 1,
      "matching": 1
    }
  }
}

List Agents

GET /agent-pools/:agent_pool_id/agents

ParameterDescription
:agent_pool_idThe ID of the Agent Pool to list.
StatusResponseReason
200JSON API document (type: "agents")Success
404JSON API error objectAgent Pool 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
filter[last-ping-since]Optional. Accepts a date in ISO8601 format (ex. 2020-08-11T10:41:23Z).
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 agents per page.

Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request GET \
  https://app.terraform.io/api/v2/agent-pools/apool-xkuMi7x4LsEnBUdY/agents

Sample Response

{
  "data": [
    {
      "id": "agent-A726QeosTCpCumAs",
      "type": "agents",
      "attributes": {
        "name": "my-cool-agent",
        "status": "idle",
        "ip-address": "123.123.123.123",
        "last-ping-at": "2020-10-09T18:52:25.246Z"
      },
      "links": {
        "self": "/api/v2/agents/agent-A726QeosTCpCumAs"
      }
    },
    {
      "id": "agent-4cQzjbr1cnM6Pcxr",
      "type": "agents",
      "attributes": {
        "name": "my-other-cool-agent",
        "status": "exited",
        "ip-address": "123.123.123.123",
        "last-ping-at": "2020-08-12T15:25:09.726Z"
      },
      "links": {
        "self": "/api/v2/agents/agent-4cQzjbr1cnM6Pcxr"
      }
    },
    {
      "id": "agent-yEJjXQCucpNxtxd2",
      "type": "agents",
      "attributes": {
        "name": null,
        "status": "errored",
        "ip-address": "123.123.123.123",
        "last-ping-at": "2020-08-11T06:22:20.300Z"
      },
      "links": {
        "self": "/api/v2/agents/agent-yEJjXQCucpNxtxd2"
      }
    }
  ],
  "links": {
    "self": "https://app.terraform.io/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/agents?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "first": "https://app.terraform.io/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/agents?page%5Bnumber%5D=1&page%5Bsize%5D=20",
    "prev": null,
    "next": null,
    "last": "https://app.terraform.io/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/agents?page%5Bnumber%5D=1&page%5Bsize%5D=20"
  },
  "meta": {
    "pagination": {
      "current-page": 1,
      "prev-page": null,
      "next-page": null,
      "total-pages": 1,
      "total-count": 3
    }
  }
}

Show an Agent Pool

GET /agent-pools/:id

ParameterDescription
:idThe ID of the Agent Pool to show
StatusResponseReason
200JSON API document (type: "agent-pools")Success
404JSON API error objectAgent Pool not found, or user unauthorized to perform action

Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request GET \
  https://app.terraform.io/api/v2/agent-pools/apool-MCf6kkxu5FyHbqhd

Sample Response

{
  "data": {
    "id": "apool-yoGUFz5zcRMMz53i",
    "type": "agent-pools",
    "attributes": {
      "name": "example-pool",
      "created-at": "2020-08-05T18:10:26.964Z",
      "organization-scoped": false
    },
    "relationships": {
      "agents": {
        "links": {
          "related": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/agents"
        }
      },
      "authentication-tokens": {
        "links": {
          "related": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/authentication-tokens"
        }
      },
      "workspaces": {
        "data": [
          {
            "id": "ws-9EEkcEQSA3XgWyGe",
            "type": "workspaces"
          }
        ]
      },
      "allowed-workspaces": {
        "data": [
          {
            "id": "ws-x9taqV23mxrGcDrn",
            "type": "workspaces"
          }
        ]
      }
    },
    "links": {
      "self": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i"
    }
  }
}

Show an Agent

GET /agents/:id

ParameterDescription
:idThe ID of the agent to show
StatusResponseReason
200JSON API document (type: "agents")Success
404JSON API error objectAgent not found, or user unauthorized to perform action

Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request GET \
  https://app.terraform.io/api/v2/agents/agent-73PJNzbZB5idR7AQ

Sample Response

{
  "data": {
    "id": "agent-Zz9PTEcUgBtYzht8",
    "type": "agents",
    "attributes": {
      "name": "my-agent",
      "status": "busy",
      "ip-address": "123.123.123.123",
      "last-ping-at": "2020-09-08T18:47:35.361Z"
    },
    "links": {
      "self": "/api/v2/agents/agent-Zz9PTEcUgBtYzht8"
    }
  }
}

Delete an Agent

DELETE /agents/:id

ParameterDescription
:idThe ID of the agent to delete
StatusResponseReason
204NothingSuccess
412JSON API error objectAgent is not deletable. Agents must have a status of unknown, errored, or exited before being deleted.
404JSON API error objectAgent not found, or user unauthorized to perform action

Sample Request

curl \
  --header "Authorization: Bearer $TOKEN" \
  --request DELETE \
  https://app.terraform.io/api/v2/agents/agent-73PJNzbZB5idR7AQ

Create an Agent Pool

POST /organizations/:organization_name/agent-pools

ParameterDescription
:organization_nameThe name of the organization.

This endpoint allows you to create an Agent Pool for an organization. Only one Agent Pool may exist for an organization.

StatusResponseReason
201JSON API document (type: "agent-pools")Agent Pool successfully created
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.

Key pathTypeDefaultDescription
data.typestringMust be "agent-pools".
data.attributes.namestringThe name of the agent pool, which can only include letters, numbers, -, and _. This will be used as an identifier and must be unique in the organization.
data.attributes.organization-scopedbooltrueThe scope of the agent pool. If true, all workspaces in the organization can use the agent pool.
data.relationships.allowed-workspaces.data.typestringMust be "workspaces".
data.relationships.allowed-workspaces.data.idstringThe ID of the workspace that has permission to use the agent pool. Refer to Scoping Agent Pools to Specific Workspaces.

Sample Payload

{
    "data": {
        "type": "agent-pools",
        "attributes": {
            "name": "my-pool",
            "organization-scoped": false,
        },
        "relationships": {
          "allowed-workspaces": {
            "data": [
              {
                "id": "ws-x9taqV23mxrGcDrn",
                "type": "workspaces"
              }
            ]
          }
        }
    }
}

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/agent-pools

Sample Response

{
  "data": {
    "id": "apool-55jZekR57npjHHYQ",
    "type": "agent-pools",
    "attributes": {
      "name": "my-pool",
      "created-at": "2020-10-13T16:32:45.165Z",
      "organization-scoped": false,

    },
    "relationships": {
      "agents": {
        "links": {
          "related": "/api/v2/agent-pools/apool-55jZekR57npjHHYQ/agents"
        }
      },
      "authentication-tokens": {
        "links": {
          "related": "/api/v2/agent-pools/apool-55jZekR57npjHHYQ/authentication-tokens"
        }
      },
      "workspaces": {
        "data": []
      },
      "allowed-workspaces": {
        "data": [
          {
            "id": "ws-x9taqV23mxrGcDrn",
            "type": "workspaces"
          }
        ]
      }
    },
    "links": {
      "self": "/api/v2/agent-pools/apool-55jZekR57npjHHYQ"
    }
  }
}

Update an Agent Pool

PATCH /agent-pools/:id

ParameterDescription
:idThe ID of the Agent Pool to update
StatusResponseReason
200JSON API document (type: "agent-pools")Success
404JSON API error objectAgent Pool not found, or user unauthorized to perform action
422JSON error documentMalformed 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.typestringMust be "agent-pools".
data.attributes.namestring(previous value)The name of the agent pool, which can only include letters, numbers, -, and _. This will be used as an identifier and must be unique in the organization.
data.attributes.organization-scopedbooltrueThe scope of the agent pool. If true, all workspaces in the organization can use the agent pool.
data.relationships.allowed-workspaces.data.typestringMust be "workspaces".
data.relationships.allowed-workspaces.data.idstringThe ID of the workspace that has permission to use the agent pool. Refer to Scoping Agent Pools to Specific Workspaces.

Sample Payload

{
  "data": {
    "type": "agent-pools",
    "attributes": {
      "name": "example-pool",
      "organization-scoped": false,
    },
    "relationships": {
      "allowed-workspaces": {
        "data": [
          {
            "id": "ws-x9taqV23mxrGcDrn",
            "type": "workspaces"
          }
        ]
      }
    }
  }
}

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/agent-pools/apool-MCf6kkxu5FyHbqhd

Sample Response

{
  "data": {
    "id": "apool-yoGUFz5zcRMMz53i",
    "type": "agent-pools",
    "attributes": {
      "name": "example-pool",
      "created-at": "2020-08-05T18:10:26.964Z"
    },
    "relationships": {
      "agents": {
        "links": {
          "related": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/agents"
        }
      },
      "authentication-tokens": {
        "links": {
          "related": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i/authentication-tokens"
        }
      },
      "workspaces": {
        "data": [
          {
            "id": "ws-9EEkcEQSA3XgWyGe",
            "type": "workspaces"
          }
        ]
      },
      "allowed-workspaces": {
        "data": [
          {
            "id": "ws-x9taqV23mxrGcDrn",
            "type": "workspaces"
          }
        ]
      }
    },
    "links": {
      "self": "/api/v2/agent-pools/apool-yoGUFz5zcRMMz53i"
    }
  }
}

Delete an Agent Pool

DELETE /agent-pools/:agent_pool_id

ParameterDescription
:agent_pool_idThe ID of the agent pool ID to delete

Sample Request

$ curl \
  --header "Authorization: Bearer $TOKEN" \
  --header "Content-Type: application/vnd.api+json" \
  --request DELETE \
  https://app.terraform.io/api/v2/agent-pools/apool-MCf6kkxu5FyHbqhd

Available Related Resources

The GET endpoints above can optionally return related resources, if requested with the include query parameter. The following resource types are available:

Resource NameDescription
workspacesThe workspaces attached to this agent pool.
Edit this page on GitHub

On this page

  1. Agent Pools and Agents API
  2. List Agent Pools
  3. List Agents
  4. Show an Agent Pool
  5. Show an Agent
  6. Delete an Agent
  7. Create an Agent Pool
  8. Update an Agent Pool
  9. Delete an Agent Pool
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)