@opengeni/runtime 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2PO56VAL.js +3478 -0
- package/dist/chunk-2PO56VAL.js.map +1 -0
- package/dist/index.d.ts +912 -0
- package/dist/index.js +3663 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/index.d.ts +1738 -0
- package/dist/sandbox/index.js +187 -0
- package/dist/sandbox/index.js.map +1 -0
- package/package.json +49 -0
- package/src/bundled_hashicorp_terraform_skills/LICENSE +373 -0
- package/src/bundled_hashicorp_terraform_skills/README.md +18 -0
- package/src/bundled_hashicorp_terraform_skills/UPSTREAM_GIT_SHA +1 -0
- package/src/bundled_hashicorp_terraform_skills/azure-verified-modules/SKILL.md +613 -0
- package/src/bundled_hashicorp_terraform_skills/checkov/SKILL.md +43 -0
- package/src/bundled_hashicorp_terraform_skills/refactor-module/SKILL.md +538 -0
- package/src/bundled_hashicorp_terraform_skills/social-media-marketing/SKILL.md +35 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-search-import/SKILL.md +372 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-search-import/references/MANUAL-IMPORT.md +113 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-search-import/scripts/list_resources.sh +38 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/SKILL.md +480 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/api-monitoring.md +543 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/component-blocks.md +476 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/deployment-blocks.md +391 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/examples.md +1529 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/linked-stacks.md +187 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-stacks/references/troubleshooting.md +671 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-style-guide/SKILL.md +353 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/SKILL.md +451 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/references/CI_CD.md +80 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/references/EXAMPLES.md +314 -0
- package/src/bundled_hashicorp_terraform_skills/terraform-test/references/MOCK_PROVIDERS.md +171 -0
- package/src/codex-tool-search.ts +267 -0
- package/src/context-compaction.ts +538 -0
- package/src/history-sanitizer.ts +719 -0
- package/src/index.ts +3299 -0
- package/src/sandbox/capabilities.ts +69 -0
- package/src/sandbox/channel-a.ts +1031 -0
- package/src/sandbox/display-stack.ts +231 -0
- package/src/sandbox/errors.ts +34 -0
- package/src/sandbox/index.ts +832 -0
- package/src/sandbox/providers/blaxel.ts +35 -0
- package/src/sandbox/providers/cloudflare.ts +24 -0
- package/src/sandbox/providers/daytona.ts +34 -0
- package/src/sandbox/providers/docker.ts +17 -0
- package/src/sandbox/providers/e2b.ts +36 -0
- package/src/sandbox/providers/index.ts +107 -0
- package/src/sandbox/providers/local.ts +13 -0
- package/src/sandbox/providers/modal.ts +55 -0
- package/src/sandbox/providers/none.ts +13 -0
- package/src/sandbox/providers/runloop.ts +32 -0
- package/src/sandbox/providers/selfhosted.ts +96 -0
- package/src/sandbox/providers/types.ts +38 -0
- package/src/sandbox/providers/vercel.ts +29 -0
- package/src/sandbox/recording.ts +286 -0
- package/src/sandbox/routing/backend-resolver.ts +189 -0
- package/src/sandbox/routing/routing-session.ts +455 -0
- package/src/sandbox/select.ts +371 -0
- package/src/sandbox/selfhosted/capabilities.ts +255 -0
- package/src/sandbox/selfhosted/control-rpc.ts +351 -0
- package/src/sandbox/selfhosted/session.ts +930 -0
- package/src/sandbox/selfhosted/testing.ts +230 -0
- package/src/sandbox/stream-port.ts +185 -0
- package/src/sandbox/stream-token.ts +90 -0
- package/src/sandbox/terminal-server.ts +203 -0
- package/src/sandbox-computer.ts +835 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
# API Monitoring Reference
|
|
2
|
+
|
|
3
|
+
Complete guide for monitoring Terraform Stack deployments using the HCP Terraform API. Use this approach for automation, CI/CD pipelines, and non-interactive environments like AI agents.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [When to Use the API](#when-to-use-the-api)
|
|
8
|
+
2. [Authentication](#authentication)
|
|
9
|
+
3. [API Monitoring Workflow](#api-monitoring-workflow)
|
|
10
|
+
4. [Detailed Endpoint Reference](#detailed-endpoint-reference)
|
|
11
|
+
5. [Notes for AI Agents and Automation](#notes-for-ai-agents-and-automation)
|
|
12
|
+
|
|
13
|
+
## When to Use the API
|
|
14
|
+
|
|
15
|
+
Use the HCP Terraform API instead of CLI commands when:
|
|
16
|
+
- Running in non-interactive environments (CI/CD, automation scripts)
|
|
17
|
+
- Building tools or integrations that need programmatic access
|
|
18
|
+
- Monitoring multiple Stacks simultaneously
|
|
19
|
+
- Implementing custom retry logic or error handling
|
|
20
|
+
- Working in environments where streaming CLI commands don't work
|
|
21
|
+
|
|
22
|
+
**CLI commands that don't work in automation:**
|
|
23
|
+
- `terraform stacks deployment-run watch` - Streams output, blocks indefinitely
|
|
24
|
+
- `terraform stacks deployment-group watch` - Streams output, blocks indefinitely
|
|
25
|
+
- `terraform stacks configuration watch` - Streams output, blocks indefinitely
|
|
26
|
+
|
|
27
|
+
## Authentication
|
|
28
|
+
|
|
29
|
+
### Extract API Token from Credentials File
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
TOKEN=$(jq -r '.credentials["app.terraform.io"].token' ~/.terraform.d/credentials.tfrc.json)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Alternative: Use Environment Variable
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
export TFC_TOKEN="your-token-here"
|
|
39
|
+
TOKEN=$TFC_TOKEN
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### API Request Headers
|
|
43
|
+
|
|
44
|
+
All API requests require these headers:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
-H "Authorization: Bearer $TOKEN"
|
|
48
|
+
-H "Content-Type: application/vnd.api+json"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API Monitoring Workflow
|
|
52
|
+
|
|
53
|
+
After uploading a configuration with `terraform stacks configuration upload`, follow this sequence to monitor deployment progress:
|
|
54
|
+
|
|
55
|
+
### Step 1: Get Configuration Status
|
|
56
|
+
|
|
57
|
+
**Endpoint:** `GET /api/v2/stack-configurations/{configuration-id}`
|
|
58
|
+
|
|
59
|
+
**Purpose:** Verify configuration upload completed successfully and get the configuration details.
|
|
60
|
+
|
|
61
|
+
**Request:**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
65
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
66
|
+
"https://app.terraform.io/api/v2/stack-configurations/{configuration-id}" | jq '.'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Response Fields:**
|
|
70
|
+
- `attributes.status` - Configuration processing status (pending/completed)
|
|
71
|
+
- `attributes.sequence-number` - Version number of this configuration
|
|
72
|
+
- `attributes.components-detected` - Number of components found
|
|
73
|
+
- `attributes.deployments-detected` - Number of deployments found
|
|
74
|
+
|
|
75
|
+
**Example Response:**
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"data": {
|
|
80
|
+
"id": "stc-ABC123",
|
|
81
|
+
"type": "stack-configurations",
|
|
82
|
+
"attributes": {
|
|
83
|
+
"status": "completed",
|
|
84
|
+
"sequence-number": 5,
|
|
85
|
+
"components-detected": 3,
|
|
86
|
+
"deployments-detected": 2,
|
|
87
|
+
"created-at": "2024-01-15T10:30:00.000Z",
|
|
88
|
+
"updated-at": "2024-01-15T10:30:45.000Z"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Step 2: Get Deployment Group Summaries
|
|
95
|
+
|
|
96
|
+
**Endpoint:** `GET /api/v2/stack-configurations/{configuration-id}/stack-deployment-group-summaries`
|
|
97
|
+
|
|
98
|
+
**Purpose:** Get list of deployment groups, their IDs, and current status summary.
|
|
99
|
+
|
|
100
|
+
**Request:**
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
104
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
105
|
+
"https://app.terraform.io/api/v2/stack-configurations/{configuration-id}/stack-deployment-group-summaries" | jq '.'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Response Fields:**
|
|
109
|
+
- `id` - Deployment group ID (needed for next step)
|
|
110
|
+
- `attributes.name` - Deployment group name (e.g., `dev_default`)
|
|
111
|
+
- `attributes.status` - Overall status (running/succeeded/failed)
|
|
112
|
+
- `attributes.status-counts` - Breakdown of deployment statuses
|
|
113
|
+
|
|
114
|
+
**Example Response:**
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"data": [
|
|
119
|
+
{
|
|
120
|
+
"id": "sdg-XYZ789",
|
|
121
|
+
"type": "stack-deployment-group-summaries",
|
|
122
|
+
"attributes": {
|
|
123
|
+
"name": "dev_default",
|
|
124
|
+
"status": "running",
|
|
125
|
+
"status-counts": {
|
|
126
|
+
"pending": 0,
|
|
127
|
+
"running": 1,
|
|
128
|
+
"succeeded": 1,
|
|
129
|
+
"failed": 0
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Step 3: Get Deployment Runs
|
|
138
|
+
|
|
139
|
+
**Endpoint:** `GET /api/v2/stack-deployment-groups/{group-id}/stack-deployment-runs`
|
|
140
|
+
|
|
141
|
+
**Purpose:** Get list of deployment runs for a specific group with their current status.
|
|
142
|
+
|
|
143
|
+
**Request:**
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
147
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
148
|
+
"https://app.terraform.io/api/v2/stack-deployment-groups/{group-id}/stack-deployment-runs" | jq '.'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Response Fields:**
|
|
152
|
+
- `id` - Deployment run ID (needed for next step)
|
|
153
|
+
- `attributes.status` - Current status (planning/planned/applying/applied/failed)
|
|
154
|
+
- `attributes.created-at` - Run start time
|
|
155
|
+
- `attributes.updated-at` - Last update time
|
|
156
|
+
|
|
157
|
+
**Example Response:**
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"data": [
|
|
162
|
+
{
|
|
163
|
+
"id": "sdr-123ABC",
|
|
164
|
+
"type": "stack-deployment-runs",
|
|
165
|
+
"attributes": {
|
|
166
|
+
"status": "planning",
|
|
167
|
+
"created-at": "2024-01-15T10:31:00.000Z",
|
|
168
|
+
"updated-at": "2024-01-15T10:31:15.000Z"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Step 4: Get Deployment Steps
|
|
176
|
+
|
|
177
|
+
**Endpoint:** `GET /api/v2/stack-deployment-runs/{run-id}/stack-deployment-steps`
|
|
178
|
+
|
|
179
|
+
**Purpose:** Get detailed information about individual plan and apply steps.
|
|
180
|
+
|
|
181
|
+
**Request:**
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
185
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
186
|
+
"https://app.terraform.io/api/v2/stack-deployment-runs/{run-id}/stack-deployment-steps" | jq '.'
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Response Fields:**
|
|
190
|
+
- `id` - Step ID (needed for diagnostics and outputs)
|
|
191
|
+
- `attributes.operation-type` - Type of operation (plan/apply)
|
|
192
|
+
- `attributes.status` - Step status (running/completed/failed)
|
|
193
|
+
- `attributes.component-name` - Which component is being processed
|
|
194
|
+
|
|
195
|
+
**Example Response:**
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"data": [
|
|
200
|
+
{
|
|
201
|
+
"id": "sds-PlanStep123",
|
|
202
|
+
"type": "stack-deployment-steps",
|
|
203
|
+
"attributes": {
|
|
204
|
+
"operation-type": "plan",
|
|
205
|
+
"status": "completed",
|
|
206
|
+
"component-name": "vpc",
|
|
207
|
+
"created-at": "2024-01-15T10:31:05.000Z",
|
|
208
|
+
"completed-at": "2024-01-15T10:31:30.000Z"
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"id": "sds-ApplyStep456",
|
|
213
|
+
"type": "stack-deployment-steps",
|
|
214
|
+
"attributes": {
|
|
215
|
+
"operation-type": "apply",
|
|
216
|
+
"status": "running",
|
|
217
|
+
"component-name": "vpc",
|
|
218
|
+
"created-at": "2024-01-15T10:32:00.000Z"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Step 5: Get Error Diagnostics (When Deployment Fails)
|
|
226
|
+
|
|
227
|
+
**Endpoint:** `GET /api/v2/stack-deployment-steps/{step-id}/stack-diagnostics`
|
|
228
|
+
|
|
229
|
+
**Purpose:** Retrieve detailed error messages when a deployment step fails.
|
|
230
|
+
|
|
231
|
+
**Critical:** The `stack_deployment_step_id` query parameter is **required**. Without it, the API returns empty results.
|
|
232
|
+
|
|
233
|
+
**Request:**
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
237
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
238
|
+
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/stack-diagnostics?stack_deployment_step_id={step-id}" | jq '.'
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Response Fields:**
|
|
242
|
+
- `attributes.severity` - Diagnostic level (error/warning)
|
|
243
|
+
- `attributes.summary` - Brief error description
|
|
244
|
+
- `attributes.detail` - Detailed error message
|
|
245
|
+
- `attributes.diags` - Array of diagnostic objects with file locations and code snippets
|
|
246
|
+
|
|
247
|
+
**Example Response (Error with Details):**
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"data": [
|
|
252
|
+
{
|
|
253
|
+
"id": "stf-ErrorExampleId",
|
|
254
|
+
"type": "stack-diagnostics",
|
|
255
|
+
"attributes": {
|
|
256
|
+
"severity": "error",
|
|
257
|
+
"summary": "Diagnostics reported",
|
|
258
|
+
"detail": "2 errors",
|
|
259
|
+
"diags": [
|
|
260
|
+
{
|
|
261
|
+
"summary": "Unsupported attribute",
|
|
262
|
+
"detail": "This object does not have an attribute named \"target_id\".",
|
|
263
|
+
"range": {
|
|
264
|
+
"filename": "main.tf",
|
|
265
|
+
"start": {
|
|
266
|
+
"line": 634,
|
|
267
|
+
"column": 33
|
|
268
|
+
},
|
|
269
|
+
"end": {
|
|
270
|
+
"line": 634,
|
|
271
|
+
"column": 43
|
|
272
|
+
},
|
|
273
|
+
"source": "registry.terraform.io/terraform-aws-modules/alb/aws@9.17.0//main.tf"
|
|
274
|
+
},
|
|
275
|
+
"snippet": {
|
|
276
|
+
"code": " target_id = each.value.target_id",
|
|
277
|
+
"context": "resource \"aws_lb_target_group_attachment\" \"this\""
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"summary": "Invalid reference",
|
|
282
|
+
"detail": "A reference to a resource type must be followed by at least one attribute access.",
|
|
283
|
+
"range": {
|
|
284
|
+
"filename": "main.tf",
|
|
285
|
+
"start": {
|
|
286
|
+
"line": 142,
|
|
287
|
+
"column": 15
|
|
288
|
+
},
|
|
289
|
+
"end": {
|
|
290
|
+
"line": 142,
|
|
291
|
+
"column": 28
|
|
292
|
+
},
|
|
293
|
+
"source": "local-module//main.tf"
|
|
294
|
+
},
|
|
295
|
+
"snippet": {
|
|
296
|
+
"code": " vpc_id = aws_vpc.main",
|
|
297
|
+
"context": "resource \"aws_subnet\" \"private\""
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
],
|
|
301
|
+
"acknowledged": false,
|
|
302
|
+
"created-at": "2024-01-15T10:32:15.000Z"
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Parsing Diagnostics:**
|
|
310
|
+
|
|
311
|
+
Extract error information with jq:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# Get error summaries
|
|
315
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
316
|
+
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/stack-diagnostics?stack_deployment_step_id={step-id}" | \
|
|
317
|
+
jq -r '.data[].attributes.diags[]? | "\(.summary): \(.detail)"'
|
|
318
|
+
|
|
319
|
+
# Get file locations
|
|
320
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
321
|
+
"https://app.terraform.io/api/v2/stack-deployment-steps/{step-id}/stack-diagnostics?stack_deployment_step_id={step-id}" | \
|
|
322
|
+
jq -r '.data[].attributes.diags[]? | "\(.range.filename):\(.range.start.line)"'
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Step 6: Get Stack Outputs (After Successful Deployment)
|
|
326
|
+
|
|
327
|
+
**Endpoint:** `GET /api/v2/stack-deployment-steps/{final-apply-step-id}/artifacts?name=apply-description`
|
|
328
|
+
|
|
329
|
+
**Purpose:** Retrieve Stack outputs after a successful deployment completes.
|
|
330
|
+
|
|
331
|
+
**Important Notes:**
|
|
332
|
+
- This endpoint returns HTTP 307 redirect - use `curl -L` to follow redirects automatically
|
|
333
|
+
- This is currently the **only way** to retrieve Stack outputs programmatically
|
|
334
|
+
- This endpoint is **not documented** in public API documentation
|
|
335
|
+
- You need the final apply step ID from Step 4
|
|
336
|
+
|
|
337
|
+
**Request:**
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
curl -L -s -H "Authorization: Bearer $TOKEN" \
|
|
341
|
+
"https://app.terraform.io/api/v2/stack-deployment-steps/{final-apply-step-id}/artifacts?name=apply-description"
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Response Structure:**
|
|
345
|
+
|
|
346
|
+
The artifact response includes an `.outputs` object where each output contains a `change.after` property with the actual output value:
|
|
347
|
+
|
|
348
|
+
```json
|
|
349
|
+
{
|
|
350
|
+
"outputs": {
|
|
351
|
+
"alb_url": {
|
|
352
|
+
"change": {
|
|
353
|
+
"actions": ["no-op"],
|
|
354
|
+
"before": "http://my-alb-123456789.us-west-2.elb.amazonaws.com",
|
|
355
|
+
"after": "http://my-alb-123456789.us-west-2.elb.amazonaws.com",
|
|
356
|
+
"after_unknown": false,
|
|
357
|
+
"before_sensitive": false,
|
|
358
|
+
"after_sensitive": false
|
|
359
|
+
},
|
|
360
|
+
"type": "string"
|
|
361
|
+
},
|
|
362
|
+
"ecr_repository_url": {
|
|
363
|
+
"change": {
|
|
364
|
+
"actions": ["no-op"],
|
|
365
|
+
"before": "123456789.dkr.ecr.us-west-2.amazonaws.com/my-repo",
|
|
366
|
+
"after": "123456789.dkr.ecr.us-west-2.amazonaws.com/my-repo",
|
|
367
|
+
"after_unknown": false,
|
|
368
|
+
"before_sensitive": false,
|
|
369
|
+
"after_sensitive": false
|
|
370
|
+
},
|
|
371
|
+
"type": "string"
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**Extract Only Output Values:**
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
curl -L -s --header "Authorization: Bearer $TOKEN" \
|
|
381
|
+
"https://app.terraform.io/api/v2/stack-deployment-steps/{final-apply-step-id}/artifacts?name=apply-description" | \
|
|
382
|
+
jq -r '.outputs | to_entries | .[] | "\(.key): \(.value.change.after)"'
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Example Output:**
|
|
386
|
+
|
|
387
|
+
```
|
|
388
|
+
alb_url: http://my-alb-123456789.us-west-2.elb.amazonaws.com
|
|
389
|
+
ecr_repository_url: 123456789.dkr.ecr.us-west-2.amazonaws.com/my-repo
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Detailed Endpoint Reference
|
|
393
|
+
|
|
394
|
+
### Available Artifact Types
|
|
395
|
+
|
|
396
|
+
The artifacts endpoint accepts these `name` parameter values:
|
|
397
|
+
|
|
398
|
+
- `plan-description` - Terraform plan output in JSON format
|
|
399
|
+
- `plan-debug-log` - Detailed debug logs from plan operation
|
|
400
|
+
- `apply-description` - Terraform apply output including outputs (JSON format)
|
|
401
|
+
- `apply-debug-log` - Detailed debug logs from apply operation
|
|
402
|
+
|
|
403
|
+
### Polling Best Practices
|
|
404
|
+
|
|
405
|
+
**Recommended polling intervals:**
|
|
406
|
+
- Configuration status: Check every 5 seconds until status is "completed"
|
|
407
|
+
- Deployment runs: Check every 10 seconds during active deployment
|
|
408
|
+
- Deployment steps: Check every 10 seconds for individual step status
|
|
409
|
+
|
|
410
|
+
**Implement exponential backoff:**
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# Example polling script with backoff
|
|
414
|
+
RETRY_COUNT=0
|
|
415
|
+
MAX_RETRIES=30
|
|
416
|
+
BACKOFF=5
|
|
417
|
+
|
|
418
|
+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
|
|
419
|
+
STATUS=$(curl -s -H "Authorization: Bearer $TOKEN" \
|
|
420
|
+
"https://app.terraform.io/api/v2/stack-deployment-runs/{run-id}" | \
|
|
421
|
+
jq -r '.data.attributes.status')
|
|
422
|
+
|
|
423
|
+
if [ "$STATUS" = "applied" ] || [ "$STATUS" = "failed" ]; then
|
|
424
|
+
echo "Deployment finished with status: $STATUS"
|
|
425
|
+
break
|
|
426
|
+
fi
|
|
427
|
+
|
|
428
|
+
echo "Current status: $STATUS. Waiting ${BACKOFF}s..."
|
|
429
|
+
sleep $BACKOFF
|
|
430
|
+
RETRY_COUNT=$((RETRY_COUNT + 1))
|
|
431
|
+
done
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## Notes for AI Agents and Automation
|
|
435
|
+
|
|
436
|
+
### CLI Command Limitations
|
|
437
|
+
|
|
438
|
+
**These CLI commands DO NOT work in automation:**
|
|
439
|
+
- `terraform stacks deployment-run watch` - Streams output, blocks indefinitely
|
|
440
|
+
- `terraform stacks deployment-group watch` - Streams output, blocks indefinitely
|
|
441
|
+
- `terraform stacks configuration watch` - Streams output, blocks indefinitely
|
|
442
|
+
|
|
443
|
+
**Solution:** Use API polling instead of watch commands.
|
|
444
|
+
|
|
445
|
+
### No Direct Output Command
|
|
446
|
+
|
|
447
|
+
There is currently no CLI command to retrieve Stack outputs. You must:
|
|
448
|
+
1. Use API to get deployment steps
|
|
449
|
+
2. Find the final apply step ID
|
|
450
|
+
3. Request the `apply-description` artifact
|
|
451
|
+
4. Parse JSON to extract outputs
|
|
452
|
+
|
|
453
|
+
### Handling Redirects
|
|
454
|
+
|
|
455
|
+
The artifacts endpoint returns HTTP 307 redirect to the actual artifact location. Ensure your HTTP client follows redirects:
|
|
456
|
+
|
|
457
|
+
**curl:** Use `-L` flag
|
|
458
|
+
**Python requests:** Set `allow_redirects=True` (default)
|
|
459
|
+
**Node.js fetch:** Set `redirect: 'follow'` (default)
|
|
460
|
+
|
|
461
|
+
### Error Handling
|
|
462
|
+
|
|
463
|
+
**Common API errors:**
|
|
464
|
+
|
|
465
|
+
- **401 Unauthorized:** Invalid or expired token - refresh credentials
|
|
466
|
+
- **404 Not Found:** Invalid ID or resource doesn't exist yet - retry with backoff
|
|
467
|
+
- **429 Too Many Requests:** Rate limited - implement exponential backoff
|
|
468
|
+
- **Empty diagnostics:** Missing required `stack_deployment_step_id` query parameter
|
|
469
|
+
|
|
470
|
+
### Complete Monitoring Script Example
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
#!/bin/bash
|
|
474
|
+
|
|
475
|
+
# Configuration
|
|
476
|
+
TOKEN=$(jq -r '.credentials["app.terraform.io"].token' ~/.terraform.d/credentials.tfrc.json)
|
|
477
|
+
CONFIG_ID="stc-ABC123"
|
|
478
|
+
BASE_URL="https://app.terraform.io/api/v2"
|
|
479
|
+
|
|
480
|
+
# Helper function
|
|
481
|
+
api_get() {
|
|
482
|
+
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
483
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
484
|
+
"$1"
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
# 1. Wait for configuration to complete
|
|
488
|
+
echo "Checking configuration status..."
|
|
489
|
+
while true; do
|
|
490
|
+
STATUS=$(api_get "$BASE_URL/stack-configurations/$CONFIG_ID" | jq -r '.data.attributes.status')
|
|
491
|
+
[ "$STATUS" = "completed" ] && break
|
|
492
|
+
echo "Configuration status: $STATUS. Waiting..."
|
|
493
|
+
sleep 5
|
|
494
|
+
done
|
|
495
|
+
|
|
496
|
+
# 2. Get deployment groups
|
|
497
|
+
echo "Getting deployment groups..."
|
|
498
|
+
GROUP_ID=$(api_get "$BASE_URL/stack-configurations/$CONFIG_ID/stack-deployment-group-summaries" | \
|
|
499
|
+
jq -r '.data[0].id')
|
|
500
|
+
|
|
501
|
+
# 3. Get deployment run
|
|
502
|
+
echo "Getting deployment run..."
|
|
503
|
+
RUN_ID=$(api_get "$BASE_URL/stack-deployment-groups/$GROUP_ID/stack-deployment-runs" | \
|
|
504
|
+
jq -r '.data[0].id')
|
|
505
|
+
|
|
506
|
+
# 4. Monitor deployment run
|
|
507
|
+
echo "Monitoring deployment run: $RUN_ID"
|
|
508
|
+
while true; do
|
|
509
|
+
STATUS=$(api_get "$BASE_URL/stack-deployment-runs/$RUN_ID" | jq -r '.data.attributes.status')
|
|
510
|
+
echo "Deployment status: $STATUS"
|
|
511
|
+
|
|
512
|
+
if [ "$STATUS" = "applied" ]; then
|
|
513
|
+
echo "Deployment succeeded!"
|
|
514
|
+
|
|
515
|
+
# 5. Get outputs from final apply step
|
|
516
|
+
APPLY_STEP=$(api_get "$BASE_URL/stack-deployment-runs/$RUN_ID/stack-deployment-steps" | \
|
|
517
|
+
jq -r '.data[] | select(.attributes["operation-type"] == "apply") | .id' | tail -1)
|
|
518
|
+
|
|
519
|
+
echo "Retrieving outputs from step: $APPLY_STEP"
|
|
520
|
+
curl -L -s -H "Authorization: Bearer $TOKEN" \
|
|
521
|
+
"$BASE_URL/stack-deployment-steps/$APPLY_STEP/artifacts?name=apply-description" | \
|
|
522
|
+
jq -r '.outputs | to_entries | .[] | "\(.key): \(.value.change.after)"'
|
|
523
|
+
break
|
|
524
|
+
fi
|
|
525
|
+
|
|
526
|
+
if [ "$STATUS" = "failed" ]; then
|
|
527
|
+
echo "Deployment failed!"
|
|
528
|
+
|
|
529
|
+
# Get error diagnostics
|
|
530
|
+
FAILED_STEP=$(api_get "$BASE_URL/stack-deployment-runs/$RUN_ID/stack-deployment-steps" | \
|
|
531
|
+
jq -r '.data[] | select(.attributes.status == "failed") | .id' | head -1)
|
|
532
|
+
|
|
533
|
+
echo "Error diagnostics from step: $FAILED_STEP"
|
|
534
|
+
api_get "$BASE_URL/stack-deployment-steps/$FAILED_STEP/stack-diagnostics?stack_deployment_step_id=$FAILED_STEP" | \
|
|
535
|
+
jq -r '.data[].attributes.diags[]? | "\(.summary): \(.detail)"'
|
|
536
|
+
exit 1
|
|
537
|
+
fi
|
|
538
|
+
|
|
539
|
+
sleep 10
|
|
540
|
+
done
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
This script demonstrates a complete monitoring workflow from configuration upload to output retrieval with error handling.
|