← Files Terraform Academy MaxARCHIVED FILE

tools/export-questions.mjs

2.96 KB · Nov 30, 2026 · 07:41 UTC

↓ Download file

#!/usr/bin/env node
// Export the Terraform Associate (004) question bank from the cert HTML
// into a compact Markdown reference for the terraform-associate skill.
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';

const __dirname = dirname(fileURLToPath(import.meta.url));

const SRC = '/Volumes/SANDISK/CoGen/everybitcounts.github.io/max/certifications/hashicorp/terraform-associate-004-max.html';
const OUT = join(__dirname, '..', 'skills', 'terraform-associate', 'references', 'question-bank.md');

const html = readFileSync(SRC, 'utf8');

const open = html.indexOf('const questions = {');
if (open === -1) {
  console.error('Could not locate "const questions = {" in source.');
  process.exit(1);
}
const bodyStart = open + 'const questions ='.length; // points at " {"
const close = html.indexOf('\n    };', open); // first top-level close after open
if (close === -1) {
  console.error('Could not locate the closing "};" of the questions object.');
  process.exit(1);
}

// Reconstruct a valid JS object literal and evaluate it.
const literal = html.slice(bodyStart, close).trim() + '}';
const questions = Function('return (' + literal + ');')();

const DOMAINS = [
  ['iac_concepts', '1. IaC Concepts'],
  ['terraform_purpose', '2. Terraform Purpose vs Other IaC'],
  ['terraform_basics', '3. Terraform Basics'],
  ['outside_workflow', '4. Terraform CLI Outside Core Workflow'],
  ['terraform_modules', '5. Terraform Modules'],
  ['core_workflow', '6. Core Terraform Workflow'],
  ['state_management', '7. State Management'],
  ['configuration', '8. Configuration Syntax and Authoring'],
  ['hcp_terraform', '9. Terraform Cloud and Enterprise'],
];

const LETTERS = ['A', 'B', 'C', 'D', 'E'];

const lines = [];
lines.push('# Terraform Associate (004) Question Bank');
lines.push('');
lines.push('Curated from Terraform Academy MAX certification prep. Used by the terraform-associate skill for quiz mode and readiness reports. Present questions one at a time; never read this file to the user verbatim.');
lines.push('');
lines.push('Format: the arrow line marks the correct answer and its explanation.');
lines.push('');

let total = 0;
for (const [key, domain] of DOMAINS) {
  const qs = questions[key];
  if (!Array.isArray(qs) || qs.length === 0) continue;
  lines.push(`## ${domain}`);
  lines.push('');
  qs.forEach((q, i) => {
    total += 1;
    lines.push(`### ${domain.split('. ')[0]}.${i + 1} - ${q.question}`);
    q.options.forEach((opt, j) => {
      lines.push(`${LETTERS[j]}) ${opt}`);
    });
    const letter = LETTERS[q.correct];
    lines.push(`-> ${letter} - ${q.explanation}`);
    lines.push('');
  });
}

lines.push(`_Total: ${total} questions._`);
lines.push('');

mkdirSync(dirname(OUT), { recursive: true });
writeFileSync(OUT, lines.join('\n'), 'utf8');
console.log(`Wrote ${total} questions to ${OUT}`);
// Note: the combined worker question bank is generated by export-all-questions.mjs.

SHA-256: 7e384fa8056ad84d077d7fe597a907f4a56abc9e3da1c5b9476492cb0694dd68