diff --git a/log b/log index 1e6764e..e69de29 100644 --- a/log +++ b/log @@ -1 +0,0 @@ -plan-TienGBHfydZB6str diff --git a/main.js b/main.js index 9eb6928..12bfe2b 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,5 @@ import { normalized_config } from "./normalize-config.js"; -import { get_run_details } from "./tfc-api-functions.mjs"; +import { get_run_details, create_plan_export } from "./tfc-api-functions.mjs"; const my_config = await normalized_config; @@ -28,4 +28,4 @@ const run_details = await get_run_details(my_config.base_url, process.argv.slice const plan_id = run_details.data.data.relationships.plan.data.id; -console.log(plan_id); \ No newline at end of file +console.log(await create_plan_export(my_config.base_url, plan_id, my_config.token)); \ No newline at end of file diff --git a/tfc-api-functions.mjs b/tfc-api-functions.mjs index dfebbd8..045a70d 100644 --- a/tfc-api-functions.mjs +++ b/tfc-api-functions.mjs @@ -16,31 +16,42 @@ export const get_run_details = async (base_url, run_id, token) => { // 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`, - { - 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" - } - } - } - } - }, - } + create_plan_export_data, + config ) } \ No newline at end of file