Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ One parser. One IR. Zero lock-in.
[![Terraform](https://img.shields.io/badge/Terraform-1.0_%E2%80%93_1.17-7B42BC?style=flat-square&logo=terraform&logoColor=white)](docs/TERRAFORM-VERSIONS.md)
[![AWS CDK](https://img.shields.io/badge/AWS_CDK-TypeScript-FF9900?style=flat-square&logo=amazonaws&logoColor=white)](https://aws.amazon.com/cdk/)
[![Pulumi](https://img.shields.io/badge/Pulumi-TypeScript-8A3391?style=flat-square&logo=pulumi&logoColor=white)](https://www.pulumi.com/)
[![Cloudflare Workers](https://img.shields.io/badge/Cloudflare-Workers-F38020?style=flat-square&logo=cloudflare&logoColor=white)](https://openiac.cwz.workers.dev)
[![Cloudflare Workers](https://img.shields.io/badge/Cloudflare-Workers-F38020?style=flat-square&logo=cloudflare&logoColor=white)](https://openiac.codewithzeal.com)
[![IR](https://img.shields.io/badge/IR-schema_0.2-818cf8?style=flat-square)](docs/IR.md)
[![Made with Go](https://img.shields.io/badge/made_with-Go-00ADD8?style=flat-square&logo=go&logoColor=white)](https://go.dev)

Expand All @@ -28,7 +28,25 @@ One parser. One IR. Zero lock-in.

<br/>

[🚀 Playground](https://openiac.cwz.workers.dev) · [📦 Quick Start](#-quick-start) · [🗺️ Roadmap](docs/ROADMAP.md) · [🧠 How It Works](#-how-it-works) · [🧱 Architecture](docs/ARCHITECTURE.md) · [📄 IR Reference](docs/IR.md) · [🧭 Version Support](docs/TERRAFORM-VERSIONS.md) · [🧪 Conformance](docs/CONFORMANCE.md) · [🤝 Contribute](CONTRIBUTING.md)
[🚀 Live demo · open beta](https://openiac.codewithzeal.com) · [📦 Quick Start](#-quick-start) · [🗺️ Roadmap](docs/ROADMAP.md) · [🧠 How It Works](#-how-it-works) · [🧱 Architecture](docs/ARCHITECTURE.md) · [📄 IR Reference](docs/IR.md) · [🧭 Version Support](docs/TERRAFORM-VERSIONS.md) · [🧪 Conformance](docs/CONFORMANCE.md) · [🤝 Contribute](CONTRIBUTING.md)

<br/>

### ⚡ Open beta — try it right now

[![Try the live playground](https://img.shields.io/badge/%E2%96%B6%20TRY%20THE%20LIVE%20PLAYGROUND-OPEN%20BETA-22d3ee?style=for-the-badge&logo=cloudflare&logoColor=0b0f17)](https://openiac.codewithzeal.com)
[![Runs in your browser](https://img.shields.io/badge/WASM-runs_in_your_browser-654FF0?style=for-the-badge&logo=webassembly&logoColor=white)](https://openiac.codewithzeal.com)
[![No install](https://img.shields.io/badge/no_install-no_signup-34d399?style=for-the-badge)](https://openiac.codewithzeal.com)

<a href="https://openiac.codewithzeal.com">
<img src="docs/assets/playground.png" alt="OpenIaC playground converting Terraform HCL to AWS CDK TypeScript in the browser" width="100%" />
</a>

<sub>No install, no account, nothing leaves your tab.</sub>

<br/><br/>

<a href="https://openiac.codewithzeal.com"><b>▶ Click here to get open beta access</b></a>

</div>

Expand Down Expand Up @@ -150,12 +168,17 @@ const mainVpc = new aws.ec2.Vpc("mainVpc", {

### 🖥️ Browser playground

Live at **[openiac.codewithzeal.com](https://openiac.codewithzeal.com)** — open
beta, no account. To run it yourself:

```bash
make wasm # builds main.wasm + wasm_exec.js
python3 -m http.server -d playground 8080 # serve it
```

Open `http://localhost:8080`, paste Terraform, get TypeScript. **No backend.**
Press **View IR** in the output pane to inspect the intermediate representation
both emitters share; **Hide IR** returns to the generated TypeScript.

---

Expand Down
2 changes: 1 addition & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ writing one package, not a new frontend.
| [`pkg/emitters/awscdk`](../pkg/emitters/awscdk/) | `aws-cdk-lib` TypeScript, L1 and L2 constructs. |
| [`pkg/emitters/pulumi`](../pkg/emitters/pulumi/) | `@pulumi/aws` TypeScript. |
| [`pkg/engine`](../pkg/engine/) | Public API: parse, convert, marshal, target parsing. |
| [`wasm`](../wasm/) + [`playground`](../playground/) | Browser build and UI. |
| [`wasm`](../wasm/) + [`playground`](../playground/) | Browser build and UI. The WebAssembly module exposes `openiacTranspile` and `openiacIR`; the UI renders either the generated TypeScript or the IR JSON from the same graph. |

## The IR contract

Expand Down
Binary file added docs/assets/playground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 99 additions & 14 deletions playground/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

const state = {
target: 'cdk',
view: 'code',
monaco: null,
input: null,
output: null,
debounce: 0,
Expand Down Expand Up @@ -53,6 +55,11 @@
if (Date.now() > deadline) throw new Error('WebAssembly runtime did not start.');
await new Promise((resolve) => setTimeout(resolve, 25));
}
// The converter and the IR toggle read separate exports, so a build with
// only the first would leave the pane showing the other view's result.
if (typeof window.openiacIR !== 'function') {
throw new Error('This WebAssembly build predates the IR view. Run `make wasm` and reload the page.');
}
}

/* ---------------- monaco setup ---------------- */
Expand Down Expand Up @@ -140,6 +147,7 @@
}

function createEditors(monaco) {
state.monaco = monaco;
const common = {
theme: 'openiac',
automaticLayout: true,
Expand Down Expand Up @@ -182,8 +190,42 @@

/* ---------------- conversion ---------------- */

function targetLabel() {
return state.target === 'cdk' ? 'AWS CDK' : 'Pulumi';
}

// Shared by both views so the numbers describe the same graph. Data sources
// only appear when the input has them, which keeps the common case short.
function statsLine(result) {
const parts = [`${result.resources || 0} resources`];
if (result.data) parts.push(`${result.data} data`);
parts.push(`${result.variables || 0} vars`, `${result.outputs || 0} outputs`, `${result.edges || 0} edges`);
return parts.join(' · ');
}

// The output pane shows either generated TypeScript or the IR, so the editor
// language, file name and download name follow the active view.
function updateOutputLanguage() {
const model = state.output && state.output.getModel();
if (!model) return;
state.monaco.editor.setModelLanguage(model, state.view === 'ir' ? 'json' : 'typescript');
}

function setView(view) {
state.view = view;
const irButton = $('ir-button');
irButton.classList.toggle('is-active', view === 'ir');
irButton.setAttribute('aria-pressed', view === 'ir' ? 'true' : 'false');
irButton.title = view === 'ir' ? 'Back to the generated TypeScript' : 'Show the universal IR (JSON) both emitters share';
$('ir-button-label').textContent = view === 'ir' ? 'Hide IR' : 'View IR';
$('output-file').textContent = view === 'ir' ? 'ir.json' : 'index.ts';
$('target-badge').textContent = view === 'ir' ? 'IR' : targetLabel();
updateOutputLanguage();
convert();
}

function convert() {
if (!state.input || typeof window.openiacTranspile !== 'function') return;
if (!state.input) return;

const source = state.input.getValue();
if (!source.trim()) {
Expand All @@ -193,6 +235,13 @@
return;
}

if (state.view === 'ir') {
convertIR(source);
return;
}

if (typeof window.openiacTranspile !== 'function') return;

let result;
try {
result = JSON.parse(window.openiacTranspile(source, state.target));
Expand All @@ -213,20 +262,50 @@
const warnings = result.warnings || [];
renderWarnings(warnings);

const stats = [
`${result.resources || 0} resources`,
`${result.variables || 0} vars`,
`${result.outputs || 0} outputs`,
`${result.edges || 0} edges`,
].join(' · ');
setStatus('ok', `Converted to ${state.target === 'cdk' ? 'AWS CDK' : 'Pulumi'}.`, `${stats} · ${warnings.length} warnings`);
const stats = statsLine(result);
setStatus('ok', `Converted to ${targetLabel()}.`, `${stats} · ${warnings.length} warnings`);
}

function convertIR(source) {
if (typeof window.openiacIR !== 'function') {
fail(new Error('This WebAssembly build has no IR export. Run `make wasm` and reload the page.'));
return;
}

let result;
try {
result = JSON.parse(window.openiacIR(source));
} catch (error) {
fail(error);
return;
}
if (!result.ok) {
fail(new Error(result.error || 'IR generation failed.'));
return;
}

let schema = '';
try {
schema = JSON.parse(result.ir).version || '';
} catch (_) {
schema = '';
}

state.output.setValue(result.ir || '');
renderWarnings([]);

const stats = statsLine(result);
setStatus('ok', 'Generated the universal IR.', schema ? `${stats} · schema ${schema}` : stats);
}

function fail(error) {
console.error(error);
state.output.setValue(`// OpenIaC could not convert this input.\n// ${String(error.message || error).replace(/\n/g, '\n// ')}`);
const message = String(error.message || error);
state.output.setValue(state.view === 'ir'
? JSON.stringify({ error: message }, null, 2)
: `// OpenIaC could not convert this input.\n// ${message.replace(/\n/g, '\n// ')}`);
renderWarnings([]);
setStatus('error', String(error.message || error), '');
setStatus('error', message, '');
}

function setStatus(kind, text, stats) {
Expand Down Expand Up @@ -262,11 +341,16 @@
document.querySelectorAll('.segment').forEach((other) => {
other.classList.toggle('is-active', other === button);
});
$('target-badge').textContent = state.target === 'cdk' ? 'AWS CDK' : 'Pulumi';
convert();
setView('code');
});
});

// The IR stays hidden until this button is pressed, then toggles back to
// the generated TypeScript.
$('ir-button').addEventListener('click', () => {
setView(state.view === 'ir' ? 'code' : 'ir');
});

$('run-button').addEventListener('click', convert);

$('copy-button').addEventListener('click', async () => {
Expand All @@ -283,11 +367,12 @@
$('download-button').addEventListener('click', () => {
const text = state.output.getValue();
if (!text) return;
const blob = new Blob([text], { type: 'text/typescript' });
const ir = state.view === 'ir';
const blob = new Blob([text], { type: ir ? 'application/json' : 'text/typescript' });
const url = URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = `openiac-${state.target}.ts`;
anchor.download = ir ? 'openiac.ir.json' : `openiac-${state.target}.ts`;
anchor.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
});
Expand Down
10 changes: 7 additions & 3 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ <h1>Escape the HCL lock-in.</h1>
<div class="pane">
<div class="pane-head">
<span class="file-dot dot-green"></span>
<span class="file-name">index.ts</span>
<span class="file-name" id="output-file">index.ts</span>
<span id="target-badge" class="lang-badge">AWS CDK</span>
<span class="spacer"></span>
<button id="copy-button" class="icon-button" type="button" title="Copy TypeScript">Copy</button>
<button id="download-button" class="icon-button" type="button" title="Download TypeScript">↓</button>
<button id="ir-button" class="ir-button" type="button" aria-pressed="false" title="Show the universal IR (JSON) both emitters share">
<span class="ir-button-icon" aria-hidden="true">{ }</span>
<span id="ir-button-label">View IR</span>
</button>
<button id="copy-button" class="icon-button" type="button" title="Copy the output">Copy</button>
<button id="download-button" class="icon-button" type="button" title="Download the output">↓</button>
</div>
<div id="output-editor" class="editor"></div>
</div>
Expand Down
59 changes: 59 additions & 0 deletions playground/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,58 @@ a { color: inherit; }
border-color: rgba(34, 211, 238, 0.45);
}

/* The IR toggle is the one thing in this bar that changes what the pane
shows, so it gets the accent treatment instead of the muted icon-button. */
.ir-button {
display: inline-flex;
align-items: center;
gap: 7px;
margin-left: 4px;
padding: 6px 13px;
border: 1px solid rgba(129, 140, 248, 0.5);
border-radius: 8px;
background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(129, 140, 248, 0.24));
color: #d6fbff;
font: 700 12px var(--sans);
letter-spacing: 0.02em;
cursor: pointer;
animation: ir-glow 2.8s ease-in-out infinite;
transition: color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.ir-button:hover {
color: #ecfeff;
border-color: rgba(34, 211, 238, 0.8);
box-shadow: 0 0 18px rgba(34, 211, 238, 0.3);
}

.ir-button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}

.ir-button.is-active {
color: #06121a;
border-color: transparent;
background: linear-gradient(135deg, var(--accent), var(--accent-2));
box-shadow: 0 2px 18px rgba(34, 211, 238, 0.4);
animation: none;
}

.ir-button-icon {
font: 700 11px var(--mono);
opacity: 0.85;
}

@keyframes ir-glow {
0%, 100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.26); }
50% { box-shadow: 0 0 16px 2px rgba(34, 211, 238, 0.26); }
}

@media (prefers-reduced-motion: reduce) {
.ir-button { animation: none; }
}

.editor {
flex: 1;
min-height: 0;
Expand Down Expand Up @@ -413,3 +465,10 @@ a { color: inherit; }
.hero { margin-top: 0; }
.status-stats { display: none; }
}

@media (max-width: 640px) {
/* Keep the pane header on one line: the glyph still marks the toggle. */
#ir-button-label { display: none; }
.ir-button { padding: 5px 9px; }
.icon-button { padding: 4px 7px; }
}
46 changes: 45 additions & 1 deletion wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,22 @@ type file struct {
Content string `json:"content"`
}

// irResponse carries the parsed graph as JSON text, so the playground can show
// the IR without importing a TypeScript emitter.
type irResponse struct {
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
IR string `json:"ir,omitempty"`
Resources int `json:"resources,omitempty"`
Data int `json:"data,omitempty"`
Variables int `json:"variables,omitempty"`
Outputs int `json:"outputs,omitempty"`
Edges int `json:"edges,omitempty"`
}

func main() {
js.Global().Set("openiacTranspile", js.FuncOf(transpile))
js.Global().Set("openiacIR", js.FuncOf(parseIR))
<-make(chan struct{})
}

Expand Down Expand Up @@ -80,7 +94,37 @@ func transpile(_ js.Value, args []js.Value) any {
return encode(out)
}

func encode(value response) string {
// parseIR(source) returns the JSON IR for source as a string field, using the
// same parser and schema version the CLI prints with `openiac ir`.
func parseIR(_ js.Value, args []js.Value) any {
if len(args) == 0 || args[0].Type() != js.TypeString {
return encode(irResponse{Error: "missing HCL source"})
}
graph, err := engine.ParseSource(args[0].String(), "playground.tf")
if err != nil {
return encode(irResponse{Error: err.Error()})
}
if graph == nil {
return encode(irResponse{Error: "no graph produced"})
}
data, err := engine.MarshalIR(graph)
if err != nil {
return encode(irResponse{Error: err.Error()})
}

resources, dataSources, variables, outputs, edges := graph.Stats()
return encode(irResponse{
OK: true,
IR: string(data),
Resources: resources,
Data: dataSources,
Variables: variables,
Outputs: outputs,
Edges: edges,
})
}

func encode(value any) string {
data, err := json.Marshal(value)
if err != nil {
return `{"ok":false,"error":"failed to encode response"}`
Expand Down
Loading