Introduction
HCP Terraform users can view the assessment result from a workspace by making an API call targeting specific assessment result ID. Before making such API calls, users will need to get the assessment result ID. This tutorial will guide users on how to retrieve the current Assessment Result ID from a workspace.
Expected Outcome
Users can retrieve the current Assessment Result ID from a workspace.
Prerequisites
- Retrieve workspace ID either viewing directly in the UI or making this API call using workspace (replace {ORG_NAME} with the user's organization name and {WORKSPACE_NAME} with the name of the targeting workspace),
curl \
An example output will be like this,
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
https://app.terraform.io/api/v2/organizations/{ORG_NAME}/workspaces/{WORKSPACE_NAME} | \
jq '.data.id'"ws-NYt9pvHvQP5cQmxP"
Procedure
-
Retrieving the assessment result ID by making the API call as below,
curl \
A sample output that contains the assessment result ID will be like this,
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
https://app.terraform.io/api/v2/workspaces/ws-NYt9pvHvQP5cQmxP/current-assessment-result
{
"id": "asmtres-UG5rE9M1371hMpMk",
"type": "assessment-results",
"data": {
"attributes": {
"succeeded": true,
"all-checks-succeeded": true,
"checks-errored": 0,
"checks-failed": 0,
"checks-passed": 0,
"checks-unknown": 0,
"created-at": "2024-07-08T20:54:45.090Z",
"drifted": true,
"error-message": null,
"resources-drifted": 1,
"resources-undrifted": 2
},
"relationships": {
"workspace": {
"data": {
"id": "ws-NYt9pvHvQP5cQmxP",
"type": "workspaces"
}
}
},
"links": {
"self": "/api/v2/assessment-results/asmtres-UG5rE9M1371hMpMk/"
"json-output": "/api/v2/assessment-results/asmtres-UG5rE9M1371hMpMk/json-output"
"json-schema": "/api/v2/assessment-results/asmtres-UG5rE9M1371hMpMk/json-schema"
"log-output": "/api/v2/assessment-results/asmtres-UG5rE9M1371hMpMk/log-output"
"health-json-redacted": "/api/v2/assessment-results/asmtres-UG5rE9M1371hMpMk/health-json-redacted"
}
}
}
- The same output will be shown if users make an API call using the path containing the assessment result ID, i.e.,
https://app.terraform.io/api/v2/assessment-results/asmtres-UG5rE9M1371hMpMk
.