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 const create_plan_export_axios = axios.create({ }); const create_plan_export_config = { } export const create_plan_export = async (base_url, plan_id, token) => { // This variable name is bad and implies action, but I'm keeping it const create_plan_export_data = { "data": { "type": "plan-exports", "attributes": { "data-type": "sentinel-mock-bundle-v0" }, "relationships": { "plan": { "data": { "id": `${plan_id}`, "type": "plans" } } } } } const config = { headers: { 'Authorization' :`Bearer ${token}`, 'Content-Type' : "application/vnd.api+json" } } const response = await axios.post( `${base_url}/api/v2/plan-exports`, create_plan_export_data, config ) } // This will check the API response for an error. // If one is detected, it will display the code and detail, then throw a node error. export const check_for_error = (response_object, api_call_type) => { if(response_object.data.errors) { } }