productivity
Terraform Cloud Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the Terraform Cloud KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.terraform.*.
Use lua_read_doc("integrations.terraform") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
Terraform Cloud workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.terraform.list_workspaces({organization = "example_organization", pageNumber = 1, pageSize = 1}))' --json kosmo integrations:lua --eval 'print(docs.read("terraform"))' --json
kosmo integrations:lua --eval 'print(docs.read("terraform.list_workspaces"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local terraform = app.integrations.terraform
local result = terraform.list_workspaces({organization = "example_organization", pageNumber = 1, pageSize = 1})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.terraform, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.terraform.default.* or app.integrations.terraform.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need Terraform Cloud, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
Terraform Cloud — Lua API Reference
list_workspaces
List workspaces in a Terraform Cloud organization.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
organization | string | yes | The organization name to list workspaces for |
pageNumber | integer | no | Page number for pagination (default: 1) |
pageSize | integer | no | Number of results per page, max 100 (default: 20) |
Examples
-- List workspaces for an organization
local result = app.integrations.terraform.list_workspaces({
organization = "my-org"
})
for _, ws in ipairs(result.data) do
print(ws.attributes.name .. " — " .. ws.attributes["terraform-version"])
end
-- Paginate through workspaces
local result = app.integrations.terraform.list_workspaces({
organization = "my-org",
pageNumber = 2,
pageSize = 50
})
get_workspace
Get details of a specific Terraform Cloud workspace by its ID.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
workspaceId | string | yes | The workspace ID (starts with “ws-”) |
Example
local result = app.integrations.terraform.get_workspace({
workspaceId = "ws-abc123xyz456"
})
local ws = result.data.attributes
print("Workspace: " .. ws.name)
print("Terraform version: " .. ws["terraform-version"])
print("Locked: " .. tostring(ws.locked))
print("Working directory: " .. (ws["working-directory"] or "default"))
list_runs
List runs for a Terraform Cloud workspace.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
workspaceId | string | yes | The workspace ID to list runs for (starts with “ws-”) |
pageNumber | integer | no | Page number for pagination (default: 1) |
pageSize | integer | no | Number of results per page, max 100 (default: 20) |
Example
local result = app.integrations.terraform.list_runs({
workspaceId = "ws-abc123xyz456"
})
for _, run in ipairs(result.data) do
print(run.id .. " — status: " .. run.attributes.status)
end
get_run
Get details of a specific Terraform Cloud run by its ID.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
runId | string | yes | The run ID (starts with “run-”) |
Example
local result = app.integrations.terraform.get_run({
runId = "run-abc123xyz456"
})
local run = result.data.attributes
print("Status: " .. run.status)
print("Trigger: " .. run["trigger-reason"])
print("Created: " .. run["created-at"])
list_variables
List variables for a Terraform Cloud workspace.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
workspaceId | string | yes | The workspace ID to list variables for (starts with “ws-”) |
Example
local result = app.integrations.terraform.list_variables({
workspaceId = "ws-abc123xyz456"
})
for _, v in ipairs(result.data) do
local attrs = v.attributes
print(attrs.key .. " = " .. (attrs.sensitive and "***" or tostring(attrs.value)))
print(" category: " .. attrs.category .. ", sensitive: " .. tostring(attrs.sensitive))
end
list_organizations
List Terraform Cloud organizations the authenticated user has access to.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
pageNumber | integer | no | Page number for pagination (default: 1) |
pageSize | integer | no | Number of results per page, max 50 (default: 20) |
Examples
-- List organizations
local result = app.integrations.terraform.list_organizations({})
for _, org in ipairs(result.data) do
print(org.attributes.name .. " — " .. (org.attributes["external-id"] or ""))
end
-- Paginate
local result = app.integrations.terraform.list_organizations({
pageNumber = 2,
pageSize = 10
})
get_current_user
Get the currently authenticated Terraform Cloud user. Useful for verifying authentication.
Parameters
None.
Example
local result = app.integrations.terraform.get_current_user({})
print("Username: " .. result.data.attributes.username)
print("Email: " .. (result.data.attributes.email or "N/A"))
Multi-Account Usage
If you have multiple Terraform Cloud accounts configured, use account-specific namespaces:
-- Default account (always works)
app.integrations.terraform.list_organizations({})
-- Explicit default (portable across setups)
app.integrations.terraform.default.list_organizations({})
-- Named accounts
app.integrations.terraform.production.list_workspaces({
organization = "prod-org"
})
app.integrations.terraform.staging.list_workspaces({
organization = "staging-org"
})
All functions are identical across accounts — only the credentials differ.
Raw agent markdown
# Terraform Cloud — Lua API Reference
## list_workspaces
List workspaces in a Terraform Cloud organization.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `organization` | string | yes | The organization name to list workspaces for |
| `pageNumber` | integer | no | Page number for pagination (default: 1) |
| `pageSize` | integer | no | Number of results per page, max 100 (default: 20) |
### Examples
```lua
-- List workspaces for an organization
local result = app.integrations.terraform.list_workspaces({
organization = "my-org"
})
for _, ws in ipairs(result.data) do
print(ws.attributes.name .. " — " .. ws.attributes["terraform-version"])
end
-- Paginate through workspaces
local result = app.integrations.terraform.list_workspaces({
organization = "my-org",
pageNumber = 2,
pageSize = 50
})
```
---
## get_workspace
Get details of a specific Terraform Cloud workspace by its ID.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `workspaceId` | string | yes | The workspace ID (starts with "ws-") |
### Example
```lua
local result = app.integrations.terraform.get_workspace({
workspaceId = "ws-abc123xyz456"
})
local ws = result.data.attributes
print("Workspace: " .. ws.name)
print("Terraform version: " .. ws["terraform-version"])
print("Locked: " .. tostring(ws.locked))
print("Working directory: " .. (ws["working-directory"] or "default"))
```
---
## list_runs
List runs for a Terraform Cloud workspace.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `workspaceId` | string | yes | The workspace ID to list runs for (starts with "ws-") |
| `pageNumber` | integer | no | Page number for pagination (default: 1) |
| `pageSize` | integer | no | Number of results per page, max 100 (default: 20) |
### Example
```lua
local result = app.integrations.terraform.list_runs({
workspaceId = "ws-abc123xyz456"
})
for _, run in ipairs(result.data) do
print(run.id .. " — status: " .. run.attributes.status)
end
```
---
## get_run
Get details of a specific Terraform Cloud run by its ID.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `runId` | string | yes | The run ID (starts with "run-") |
### Example
```lua
local result = app.integrations.terraform.get_run({
runId = "run-abc123xyz456"
})
local run = result.data.attributes
print("Status: " .. run.status)
print("Trigger: " .. run["trigger-reason"])
print("Created: " .. run["created-at"])
```
---
## list_variables
List variables for a Terraform Cloud workspace.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `workspaceId` | string | yes | The workspace ID to list variables for (starts with "ws-") |
### Example
```lua
local result = app.integrations.terraform.list_variables({
workspaceId = "ws-abc123xyz456"
})
for _, v in ipairs(result.data) do
local attrs = v.attributes
print(attrs.key .. " = " .. (attrs.sensitive and "***" or tostring(attrs.value)))
print(" category: " .. attrs.category .. ", sensitive: " .. tostring(attrs.sensitive))
end
```
---
## list_organizations
List Terraform Cloud organizations the authenticated user has access to.
### Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|
| `pageNumber` | integer | no | Page number for pagination (default: 1) |
| `pageSize` | integer | no | Number of results per page, max 50 (default: 20) |
### Examples
```lua
-- List organizations
local result = app.integrations.terraform.list_organizations({})
for _, org in ipairs(result.data) do
print(org.attributes.name .. " — " .. (org.attributes["external-id"] or ""))
end
-- Paginate
local result = app.integrations.terraform.list_organizations({
pageNumber = 2,
pageSize = 10
})
```
---
## get_current_user
Get the currently authenticated Terraform Cloud user. Useful for verifying authentication.
### Parameters
None.
### Example
```lua
local result = app.integrations.terraform.get_current_user({})
print("Username: " .. result.data.attributes.username)
print("Email: " .. (result.data.attributes.email or "N/A"))
```
---
## Multi-Account Usage
If you have multiple Terraform Cloud accounts configured, use account-specific namespaces:
```lua
-- Default account (always works)
app.integrations.terraform.list_organizations({})
-- Explicit default (portable across setups)
app.integrations.terraform.default.list_organizations({})
-- Named accounts
app.integrations.terraform.production.list_workspaces({
organization = "prod-org"
})
app.integrations.terraform.staging.list_workspaces({
organization = "staging-org"
})
```
All functions are identical across accounts — only the credentials differ. local result = app.integrations.terraform.list_workspaces({organization = "example_organization", pageNumber = 1, pageSize = 1})
print(result) Functions
list_workspaces Read
List workspaces in a Terraform Cloud organization. Returns workspace IDs, names, Terraform versions, and locked status.
- Lua path
app.integrations.terraform.list_workspaces- Full name
terraform.terraform_list_workspaces
| Parameter | Type | Required | Description |
|---|---|---|---|
organization | string | no | The organization name to list workspaces for. |
pageNumber | integer | no | Page number for pagination (default: 1). |
pageSize | integer | no | Number of results per page, max 100 (default: 20). |
get_workspace Read
Get details of a specific Terraform Cloud workspace by its ID. Returns workspace configuration, status, and VCS settings.
- Lua path
app.integrations.terraform.get_workspace- Full name
terraform.terraform_get_workspace
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | no | The workspace ID (starts with "ws-"). |
list_runs Read
List runs for a Terraform Cloud workspace. Returns run IDs, statuses, trigger reasons, and timestamps.
- Lua path
app.integrations.terraform.list_runs- Full name
terraform.terraform_list_runs
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | no | The workspace ID to list runs for (starts with "ws-"). |
pageNumber | integer | no | Page number for pagination (default: 1). |
pageSize | integer | no | Number of results per page, max 100 (default: 20). |
get_run Read
Get details of a specific Terraform Cloud run by its ID. Returns run status, plan/apply results, and configuration version info.
- Lua path
app.integrations.terraform.get_run- Full name
terraform.terraform_get_run
| Parameter | Type | Required | Description |
|---|---|---|---|
runId | string | no | The run ID (starts with "run-"). |
list_variables Read
List variables for a Terraform Cloud workspace. Returns variable names, types (Terraform or environment), and sensitivity flags.
- Lua path
app.integrations.terraform.list_variables- Full name
terraform.terraform_list_variables
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | no | The workspace ID to list variables for (starts with "ws-"). |
list_organizations Read
List Terraform Cloud organizations the authenticated user has access to. Returns organization names and IDs.
- Lua path
app.integrations.terraform.list_organizations- Full name
terraform.terraform_list_organizations
| Parameter | Type | Required | Description |
|---|---|---|---|
pageNumber | integer | no | Page number for pagination (default: 1). |
pageSize | integer | no | Number of results per page, max 50 (default: 20). |
get_current_user Read
Get the currently authenticated Terraform Cloud user. Useful for verifying authentication and retrieving user details.
- Lua path
app.integrations.terraform.get_current_user- Full name
terraform.terraform_get_current_user
| Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||