46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
import axios from 'axios';
|
|
|
|
// This will use the TFC get run details API, and return the response
|
|
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run#get-run-details
|
|
export const get_run_details = async (base_url, run_id, token) => {
|
|
const response = await axios.get(
|
|
`${base_url}/api/v2/runs/${run_id}`,
|
|
{
|
|
headers: {Authorization :`Bearer ${token}`},
|
|
}
|
|
);
|
|
return response;
|
|
};
|
|
|
|
// This will use the TFC API to create a plan export
|
|
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/plan-exports#create-a-plan-export
|
|
// at present, the only type supported in the request body is "plan-exports". The only supported export format is "sentinel-mock-bundle-v0".
|
|
// As such, I'm going to hard code those portions of the payload
|
|
export const create_plan_export = async (base_url, plan_id, token) => {
|
|
const response = await axios.post(
|
|
`${base_url}/api/v2/plan-exports`,
|
|
{
|
|
headers: {
|
|
Authorization :`Bearer ${token}`,
|
|
'Content-Type' : "application/vnd.api+json"
|
|
},
|
|
data: {
|
|
|
|
"data": {
|
|
"type": "plan-exports",
|
|
"attributes": {
|
|
"data-type": "sentinel-mock-bundle-v0"
|
|
},
|
|
"relationships": {
|
|
"plan": {
|
|
"data": {
|
|
"id": `${plan_id}`,
|
|
"type": "plans"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
}
|
|
)
|
|
} |