• 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 Tokens

»Agent Tokens API

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 Tokens

GET /agent-pools/:agent_pool_id/authentication-tokens

ParameterDescription
:agent_pool_idThe ID of the Agent Pool.

The objects returned by this endpoint only contain metadata, and do not include the secret text of any authentication tokens. A token is only shown upon creation, and cannot be recovered later.

StatusResponseReason
200JSON API document (type: "authentication-tokens")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
page[number]Optional. If omitted, the endpoint will return the first page.
page[size]Optional. If omitted, the endpoint will return 20 tokens 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-MCf6kkxu5FyHbqhd/authentication-tokens

Sample Response

{
    "data": [
        {
            "id": "at-bonpPzYqv2bGD7vr",
            "type": "authentication-tokens",
            "attributes": {
                "created-at": "2020-08-07T19:38:20.868Z",
                "last-used-at": "2020-08-07T19:40:55.139Z",
                "description": "asdfsdf",
                "token": null
            },
            "relationships": {
                "created-by": {
                    "data": {
                        "id": "user-Nxv6svuhVrTW7eb1",
                        "type": "users"
                    }
                }
            }
        }
    ],
    "links": {
        "self": "https://app.terraform.io/api/v2/agent-pools/apool-MCf6kkxu5FyHbqhd/authentication-tokens?page%5Bnumber%5D=1&page%5Bsize%5D=20",
        "first": "https://app.terraform.io/api/v2/agent-pools/apool-MCf6kkxu5FyHbqhd/authentication-tokens?page%5Bnumber%5D=1&page%5Bsize%5D=20",
        "prev": null,
        "next": null,
        "last": "https://app.terraform.io/api/v2/agent-pools/apool-MCf6kkxu5FyHbqhd/authentication-tokens?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
        }
    }
}

Show an Agent Token

GET /authentication-tokens/:id

ParameterDescription
:idThe ID of the Agent Token to show
StatusResponseReason
200JSON API document (type: "authentication-tokens")Success
404JSON API error objectAgent Token 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/authentication-tokens/at-bonpPzYqv2bGD7vr

Sample Response

{
    "data": {
        "id": "at-bonpPzYqv2bGD7vr",
        "type": "authentication-tokens",
        "attributes": {
            "created-at": "2020-08-07T19:38:20.868Z",
            "last-used-at": "2020-08-07T19:40:55.139Z",
            "description": "test token",
            "token": null
        },
        "relationships": {
            "created-by": {
                "data": {
                    "id": "user-Nxv6svuhVrTW7eb1",
                    "type": "users"
                }
            }
        }
    }
}

Create an Agent Token

POST /agent-pools/:agent_pool_id/authentication-tokens

ParameterDescription
:agent_pool_idThe ID of the Agent Pool

This endpoint returns the secret text of the created authentication token. A token is only shown upon creation, and cannot be recovered later.

StatusResponseReason
201JSON API document (type: "authentication-tokens")The request was successful
404JSON API error objectAgent Pool not found or user unauthorized to perform action
422JSON API error objectMalformed request body (missing attributes, wrong types, etc.)
500JSON API error objectFailure during Agent Token creation

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 "authentication-tokens".
data.attributes.descriptionstringThe description for the Agent Token.

Sample Payload

{
  "data": {
    "type": "authentication-tokens",
    "attributes": {
      "description":"api"
    }
  }
}

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/agent-pools/apool-xkuMi7x4LsEnBUdY/authentication-tokens

Sample Response

{
    "data": {
        "id": "at-2rG2oYU9JEvfaqji",
        "type": "authentication-tokens",
        "attributes": {
            "created-at": "2020-08-10T22:29:21.907Z",
            "last-used-at": null,
            "description": "api",
            "token": "eHub7TsW7fz7LQ.atlasv1.cHGFcvf2VxVfUH4PZ7UNdaGB6SjyKWs5phdZ371zkI2KniZs2qKgrAcazhlsiy02awk"
        },
        "relationships": {
            "created-by": {
                "data": {
                    "id": "user-Nxv6svuhVrTW7eb1",
                    "type": "users"
                }
            }
        }
    }
}

Destroy an Agent Token

DELETE /api/v2/authentication-tokens/:id

ParameterDescription
:idThe ID of the Agent Token to destroy.
StatusResponseReason
204Empty responseThe Agent Token was successfully destroyed
404JSON API error objectAgent Token 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/authentication-tokens/at-6yEmxNAhaoQLH1Da
Edit this page on GitHub

On this page

  1. Agent Tokens API
  2. List Agent Tokens
  3. Show an Agent Token
  4. Create an Agent Token
  5. Destroy an Agent Token
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)