complete (but untested) create_plan_export function

This commit is contained in:
worm 2023-01-02 14:24:21 -08:00
parent dddeebd133
commit 320e5e9519
2 changed files with 35 additions and 1 deletions

View file

@ -3,6 +3,7 @@ import { get_run_details } from "./tfc-api-functions.mjs";
const my_config = await normalized_config; const my_config = await normalized_config;
// TODO: Split all this run verification clutter out into a separate module
// verify that a run_id was provided to the program // verify that a run_id was provided to the program
const runid_provided = run_id => { const runid_provided = run_id => {
return (run_id ? true : false); return (run_id ? true : false);

View file

@ -11,3 +11,36 @@ export const get_run_details = async (base_url, run_id, token) => {
); );
return response; 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"
}
}
}
}
},
}
)
}