$npx -y skills add miiitch/d2-gen --skill d2-gen-azureGenerate D2 architecture diagrams from Azure infrastructure code (Terraform/Terragrunt and Bicep). USE FOR: Terraform diagram, Terragrunt diagram, Bicep diagram, Azure architecture diagram, infrastructure visualization, generate .d2 file, D2 diagram code, connections and link sty
| 1 | # D2 Diagram Generator |
| 2 | |
| 3 | ## When to Use |
| 4 | - Generate architecture diagrams from Terraform or Terragrunt code |
| 5 | - Visualize Azure infrastructure with proper icons, connections, and grouping |
| 6 | - Create `.d2` files rendered to SVG/PNG via the `d2` CLI |
| 7 | - Represent resource dependencies, network topology, RBAC, monitoring, and data flows |
| 8 | |
| 9 | ## Goal |
| 10 | Create readable architecture diagrams using D2 language for Azure/Terraform infrastructure. |
| 11 | Output is `.d2` text files, rendered to SVG or PNG via the `d2` CLI. |
| 12 | |
| 13 | ## Tools |
| 14 | - **d2 CLI**: Render `.d2` files to SVG/PNG: `d2 input.d2 output.svg` |
| 15 | - **d2 CLI with layout engine**: `d2 --layout=elk input.d2 output.svg` |
| 16 | - **d2 fmt**: Format D2 files: `d2 fmt input.d2` |
| 17 | - No MCP server is used — the skill generates D2 source code as text. |
| 18 | |
| 19 | ## Icon Source Requirement |
| 20 | |
| 21 | Use this Terraform icon mapping as the source of truth: |
| 22 | |
| 23 | - Mapping index: `https://raw.githubusercontent.com/miiitch/d2-gen/refs/heads/main/icon-index-terraform-png.json` |
| 24 | - Base path for icon files: `https://raw.githubusercontent.com/miiitch/d2-gen/refs/heads/main` |
| 25 | |
| 26 | Resolution rule: |
| 27 | |
| 28 | - Look up the Terraform resource type key (e.g. `azurerm_linux_function_app`) in the mapping JSON. |
| 29 | - The mapped value is a relative path (e.g. `png/Icons/iot/10029-icon-service-Function-Apps.png`). |
| 30 | - Build the final icon URL: base path + `/` + relative path. |
| 31 | - In generated `.d2` files, reference the full URL directly in `icon:`. |
| 32 | |
| 33 | Fallback: if no mapping entry exists, use `shape: rectangle` with a clear text label. |
| 34 | |
| 35 | ## Recommended Workflow |
| 36 | 1. Read Terraform/Terragrunt files and list all resources + dependencies. |
| 37 | 2. Analyze sub-resources for each parent and classify as hidden (from [registry](./references/hidden-sub-resources-registry.md)) or explicit. |
| 38 | 3. Ask the mandatory Yes/No questionnaire before generating connections or containers (must be asked every time). |
| 39 | 4. Determine the resource hierarchy before placing nodes. |
| 40 | 5. Build workload-centric clusters first (workload at center, required resources around it). |
| 41 | 6. Apply the **Hidden Sub-Resources Registry**: hide listed sub-resources and represent them as styled connections to the parent resource. |
| 42 | 7. Resolve icon URLs from the mapping index, then generate the `.d2` file with containers, nodes, connections, icons, and styles. |
| 43 | 8. Validate D2 syntax with `d2 fmt` before sharing. |
| 44 | 9. Render with `d2 --layout=elk input.d2 output.svg` and verify output. |
| 45 | 10. If the user wants an autonomous SVG, download mapped icons locally and render a bundled SVG. |
| 46 | 11. When regenerating an existing diagram, re-resolve icon URLs from the mapping file (and re-download only used icons for autonomous output if needed). |
| 47 | |
| 48 | ## Mandatory Questions Before Diagram Generation |
| 49 | |
| 50 | These questions **must** be asked for every new diagram and every regeneration. Ask all at once using the ask-questions tool if available. |
| 51 | |
| 52 | 1. `Display network links? (Yes/No)` |
| 53 | 2. `Display RBAC/IAM links? (Yes/No)` |
| 54 | 3. `Display monitoring links? (Yes/No)` |
| 55 | 4. `Display data flow links? (Yes/No)` |
| 56 | 5. `Display secrets links (Key Vault references/reads)? (Yes/No)` |
| 57 | 6. `Display hosting links (App/Function -> Service Plan)? (Yes/No)` |
| 58 | 7. `Display DNS/custom-domain links? (Yes/No)` |
| 59 | 8. `Display Internet node with inbound/outbound links? (Yes/No)` |
| 60 | 9. `Display data source objects? (Yes/No)` |
| 61 | 10. `Which grouping mode? (resource-group/vnet-centric/flat)` |
| 62 | 11. `Which layout engine? (dagre/elk/tala)` |
| 63 | 12. `Which D2 theme? (0/1/200/300)` |
| 64 | 13. `Which output format? (svg/png)` |
| 65 | |
| 66 | For full question descriptions and default values, see [questions reference](./references/questions.md). |
| 67 | |
| 68 | --- |
| 69 | |
| 70 | ## Reference Documents |
| 71 | |
| 72 | Load these on-demand when needed during diagram generation: |
| 73 | |
| 74 | | Reference | When to load | |
| 75 | |-----------|-------------| |
| 76 | | [D2 Language Reference](./references/d2-language-reference.md) | D2 syntax for nodes, connections, containers, icons, layouts, themes | |
| 77 | | [Hidden Sub-Resources Registry](./references/hidden-sub-resources-registry.md) | Lookup sub-resource styles and parent theme colors | |
| 78 | | [Grouping Modes](./references/grouping-modes.md) | Detailed rules for resource-group, vnet-centric, flat modes | |
| 79 | | [Style Classes](./references/style-classes.md) | Reusable D2 style class definitions for connections | |
| 80 | | [Internet Exposure Detection](./references/internet-exposure-detection.md) | Per-resource-type HCL attri |