> For the complete documentation index, see [llms.txt](https://docs.infraglide.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.infraglide.com/terraform-iac-engine/code-generation.md).

# Real-Time HCL Code Generation

## Real-Time Terraform Code Generation

> **Overview:** InfraGlide automatically generates standard, structured **Terraform JSON** directly from visual canvas configurations. HCL format is fully supported on import and conversion flows.

***

![alt text](/files/7x9Fest0hUWOStdQxEWZ)

When you Preview, Deploy, or open the **Config** tab, InfraGlide generates code directly from the saved pipeline:

1. Read canvas components and connections.
2. Run provider-specific Terraform code generation.
3. Produce standard **Terraform JSON** configuration.
4. Prepare provider dependencies for execution.

The JSON document includes structured sections such as provider settings, variables, cloud resources, data sources, and modules.

Resource relationships and values are wired cleanly as dynamic references.

***

### When Generation Runs

| Trigger                                | Behavior                                                                                       |
| -------------------------------------- | ---------------------------------------------------------------------------------------------- |
| **Config tab open**                    | Auto-updates the generated Terraform preview as you edit canvas components                     |
| **Switch to Config tab**               | Renders the live generated Terraform JSON configuration                                        |
| **Preview** / **Deploy** / **Destroy** | Compiles saved canvas nodes and connections into Terraform configuration before Terraform runs |
| **Save & Sync**                        | Persists canvas state and updates generated Terraform configuration                            |

> **Important:** Unsaved UI edits are not included in deployment runs. Always **Save** before Preview or Deploy.

***

### Code Generation Engine Pipeline

The Terraform engine processes each component through a series of steps:

1. **Normalize inputs** — sanitize and coerce field values to expected types.
2. **Evaluate conditionals** — show or hide fields based on configuration state.
3. **Resolve references** — wire cross-resource references and dynamic field dependencies.
4. **Apply connections** — merge connection-inheritance rules from edges and nesting.
5. **Generate nested blocks** — build provider-specific nested block structures (such as network security rules).
6. **Apply meta-arguments** — attach dependency ordering, resource counts, and lifecycle rules.
7. **Build resource config** — assemble the final resource and data blocks.
8. **Prune hidden fields** — drop fields that are UI-only or schema-hidden.

***

### Multi-Cloud Generators

| Provider | Notes                                                                                                                                       |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| AWS      | Provider requirements and multi-region aliases when needed; credentials passed securely at execution time — never embedded in configuration |
| Azure    | Azure provider plugin pins and feature blocks; credentials passed securely at execution time                                                |
| GCP      | Google Cloud provider configuration                                                                                                         |

Unknown config keys are dropped server-side during prepare steps so arbitrary configuration cannot create undeclared infrastructure.

***

### Import vs Generate

![alt text](/files/KeHQGDUUnLSQQE1BsgVX)

| Path                   | Description                                                           |
| ---------------------- | --------------------------------------------------------------------- |
| **Generate**           | Canvas → Terraform JSON configuration                                 |
| **Import**             | HCL and Terraform JSON → canvas components (designer Import modal)    |
| **Template Converter** | HCL, Terraform JSON, CloudFormation, ARM, GDM → Terraform JSON format |

Imported pipelines retain original configuration metadata so passthrough resources survive regeneration.

***

### Idempotence & Safety

* Same saved config + version produces stable generator output.
* Credentials are **never** written into the generated configuration.
* Image IDs come from data sources and lookups where generators follow platform rules.

***

### See also

* [Code Panel & File Splitting](/terraform-iac-engine/code-panel.md)
* [Provider & Plugin Management](/terraform-iac-engine/provider-versions.md)
* [Platform Architecture](/getting-started/architecture.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.infraglide.com/terraform-iac-engine/code-generation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
