exports are created successfully

This commit is contained in:
worm 2023-01-02 14:54:45 -08:00
parent 320e5e9519
commit 1d8db59738
3 changed files with 36 additions and 26 deletions

1
log
View file

@ -1 +0,0 @@
plan-TienGBHfydZB6str

View file

@ -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);
console.log(await create_plan_export(my_config.base_url, plan_id, my_config.token));

View file

@ -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
)
}