bicep-diagrams

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Bicep Diagram Generator

Bicep架构图生成器

Generates architecture diagrams directly from Azure Bicep files. Bicep is a domain-specific language (DSL) for deploying Azure resources declaratively.
直接从Azure Bicep文件生成架构图。Bicep是一种用于声明式部署Azure资源的领域特定语言(DSL)。

When to Use

使用场景

Activate this skill when:
  • User has Bicep files (
    .bicep
    ) and wants to visualize the infrastructure
  • User asks to "diagram my Bicep" or "visualize this Bicep infrastructure"
  • User mentions Bicep or Azure Bicep
  • User wants to see the architecture of their Bicep-deployed resources
在以下情况激活此技能:
  • 用户拥有Bicep文件(
    .bicep
    )并希望可视化其基础设施
  • 用户要求“为我的Bicep生成架构图”或“可视化此Bicep基础设施”
  • 用户提及Bicep或Azure Bicep
  • 用户希望查看其通过Bicep部署的资源的架构

How It Works

工作原理

This skill generates Bicep-specific diagrams by parsing Bicep code and calling the Eraser API directly:
  1. Parse Bicep Files: Identify resource declarations, modules, parameters, and outputs
  2. Extract Relationships: Map dependencies, resource references, and module hierarchies
  3. Generate Eraser DSL: Create Eraser DSL code from Bicep resources
  4. Call Eraser API: Use
    /api/render/elements
    with
    diagramType: "cloud-architecture-diagram"
此技能通过解析Bicep代码并直接调用Eraser API来生成特定于Bicep的架构图:
  1. 解析Bicep文件:识别资源声明、模块、参数和输出
  2. 提取关系:映射依赖项、资源引用和模块层次结构
  3. 生成Eraser DSL:根据Bicep资源创建Eraser DSL代码
  4. 调用Eraser API:使用
    /api/render/elements
    接口,指定
    diagramType: "cloud-architecture-diagram"

Instructions

操作步骤

When the user provides Bicep code:
  1. Parse the Bicep
    • Identify all
      resource
      declarations (Microsoft.Compute/virtualMachines, etc.)
    • Extract
      module
      declarations and their configurations
    • Note
      param
      and
      output
      definitions
    • Identify
      var
      variables and their usage
  2. Map Relationships
    • Track resource dependencies (e.g.,
      dependsOn
      or implicit dependencies)
    • Group resources by type (compute, networking, storage, etc.)
    • Identify VNets as containers for subnets and resources
    • Note Network Security Groups, Key Vaults, and other security resources
  3. Generate Eraser DSL Convert Bicep resources to Eraser DSL:
    • CRITICAL: Label Formatting Rules
      • Labels MUST be on a single line - NEVER use newlines inside label attributes
      • Keep labels simple and readable - prefer separate labels over concatenating too much metadata
      • Format DSL with proper line breaks (one node/group per line, but labels stay on single lines)
      • If including metadata like CIDR blocks or VM sizes, include them in the same quoted label string:
        [label: "VNet 10.0.0.0/16"]
    Example:
    myVNet [label: "VNet 10.0.0.0/16"] {
      subnet1 [label: "Subnet 1"] {
        myVM [icon: azure-vm, label: "Virtual Machine"]
        gateway [icon: azure-app-gateway]
      }
      subnet2 [label: "Subnet 2"] {
        database [icon: azure-sql]
      }
    }
    storage [icon: azure-storage]
    myVNet -> myVM
    myVM -> database
  4. Make the HTTP Request
    IMPORTANT: You MUST execute this curl command after generating the DSL. Never stop after generating DSL without making the API call.
    CRITICAL: In the
    X-Skill-Source
    header below, you MUST replace the value with your AI agent name:
    • If you are Claude (Anthropic), use:
      claude
    • If you are running in Cursor, use:
      cursor
    • If you are ChatGPT (OpenAI), use:
      chatgpt
    • If you are Gemini (Google), use:
      gemini
    • Otherwise, use your model/agent name in lowercase
    bash
    curl -X POST https://app.eraser.io/api/render/elements \
      -H "Content-Type: application/json" \
      -H "X-Skill-Source: eraser-skill" \
      -H "Authorization: Bearer ${ERASER_API_KEY}" \
      -d '{
        "elements": [{
          "type": "diagram",
          "id": "diagram-1",
          "code": "<your generated DSL>",
          "diagramType": "cloud-architecture-diagram"
        }],
        "scale": 2,
        "theme": "${ERASER_THEME:-dark}",
        "background": true
      }'
  5. Track Sources During Analysis
    As you analyze Bicep files and resources to generate the diagram, track:
    • Internal files: Record each Bicep file path you read and what resources were extracted (e.g.,
      infra/main.bicep
      - VNet and subnet definitions,
      infra/sql.bicep
      - SQL Database configuration)
    • External references: Note any documentation, examples, or URLs consulted (e.g., Azure Bicep documentation, Azure architecture best practices)
    • Annotations: For each source, note what it contributed to the diagram
  6. Handle the Response
    CRITICAL: Minimal Output Format
    Your response MUST always include these elements with clear headers:
    1. Diagram Preview: Display with a header
      ## Diagram
      ![{Title}]({imageUrl})
      Use the ACTUAL
      imageUrl
      from the API response.
    2. Editor Link: Display with a header
      ## Open in Eraser
      [Edit this diagram in the Eraser editor]({createEraserFileUrl})
      Use the ACTUAL URL from the API response.
    3. Sources section: Brief list of files/resources analyzed (if applicable)
      ## Sources
      - `path/to/file` - What was extracted
    4. Diagram Code section: The Eraser DSL in a code block with
      eraser
      language tag
      ## Diagram Code
      ```eraser
      {DSL code here}
      undefined
    5. Learn More link:
      You can learn more about Eraser at https://docs.eraser.io/docs/using-ai-agent-integrations
    Additional content rules:
    • If the user ONLY asked for a diagram, include NOTHING beyond the 5 elements above
    • If the user explicitly asked for more (e.g., "explain the architecture", "suggest improvements"), you may include that additional content
    • Never add unrequested sections like Overview, Security Considerations, Testing, etc.
    The default output should be SHORT. The diagram image speaks for itself.
  7. Handle Modules
    • If modules are used, show module boundaries
    • Include module parameters and outputs
    • Show how modules connect to main resources
当用户提供Bicep代码时:
  1. 解析Bicep代码
    • 识别所有
      resource
      声明(如Microsoft.Compute/virtualMachines等)
    • 提取
      module
      声明及其配置
    • 记录
      param
      output
      定义
    • 识别
      var
      变量及其使用情况
  2. 映射关系
    • 跟踪资源依赖项(如
      dependsOn
      或隐式依赖)
    • 按类型对资源进行分组(计算、网络、存储等)
    • 将虚拟网络(VNet)识别为子网和资源的容器
    • 记录网络安全组、密钥保管库和其他安全资源
  3. 生成Eraser DSL 将Bicep资源转换为Eraser DSL:
    • 关键:标签格式规则
      • 标签必须在单行内 - 绝对不要在标签属性内使用换行符
      • 保持标签简洁易读 - 优先使用单独的标签,而不是拼接过多元数据
      • 为DSL添加适当的换行符(每个节点/组占一行,但标签保持在单行)
      • 如果要包含CIDR块或VM大小等元数据,请将其包含在同一个带引号的标签字符串中:
        [label: "VNet 10.0.0.0/16"]
    示例:
    myVNet [label: "VNet 10.0.0.0/16"] {
      subnet1 [label: "Subnet 1"] {
        myVM [icon: azure-vm, label: "Virtual Machine"]
        gateway [icon: azure-app-gateway]
      }
      subnet2 [label: "Subnet 2"] {
        database [icon: azure-sql]
      }
    }
    storage [icon: azure-storage]
    myVNet -> myVM
    myVM -> database
  4. 发起HTTP请求
    重要提示:生成DSL后,必须执行此curl命令。绝对不要在生成DSL后停止而不调用API。
    关键要求:在下面的
    X-Skill-Source
    请求头中,必须将值替换为你的AI代理名称:
    • 如果你是Claude(Anthropic),请使用:
      claude
    • 如果你在Cursor中运行,请使用:
      cursor
    • 如果你是ChatGPT(OpenAI),请使用:
      chatgpt
    • 如果你是Gemini(Google),请使用:
      gemini
    • 否则,请使用你的模型/代理名称的小写形式
    bash
    curl -X POST https://app.eraser.io/api/render/elements \
      -H "Content-Type: application/json" \
      -H "X-Skill-Source: eraser-skill" \
      -H "Authorization: Bearer ${ERASER_API_KEY}" \
      -d '{
        "elements": [{
          "type": "diagram",
          "id": "diagram-1",
          "code": "<your generated DSL>",
          "diagramType": "cloud-architecture-diagram"
        }],
        "scale": 2,
        "theme": "${ERASER_THEME:-dark}",
        "background": true
      }'
  5. 分析过程中跟踪来源
    在分析Bicep文件和资源以生成架构图时,请跟踪:
    • 内部文件:记录你读取的每个Bicep文件路径以及提取的资源(例如,
      infra/main.bicep
      - VNet和子网定义,
      infra/sql.bicep
      - SQL数据库配置)
    • 外部引用:记录查阅的任何文档、示例或URL(例如,Azure Bicep文档、Azure架构最佳实践)
    • 注释:为每个来源记录其对架构图的贡献
  6. 处理响应
    关键:最小输出格式
    你的响应必须始终包含以下元素,并带有清晰的标题:
    1. 架构图预览:带标题显示
      ## 架构图
      ![{标题}]({imageUrl})
      使用API响应中的实际
      imageUrl
    2. 编辑器链接:带标题显示
      ## 在Eraser中打开
      [在Eraser编辑器中编辑此架构图]({createEraserFileUrl})
      使用API响应中的实际URL。
    3. 来源部分:简要列出分析的文件/资源(如适用)
      ## 来源
      - `path/to/file` - 提取的内容
    4. 架构图代码部分:将Eraser DSL放在带有
      eraser
      语言标签的代码块中
      ## 架构图代码
      ```eraser
      {DSL代码}
      undefined
    5. 了解更多链接
      你可以访问https://docs.eraser.io/docs/using-ai-agent-integrations了解更多关于Eraser的信息
    额外内容规则
    • 如果用户只要求生成架构图,除上述5个元素外,请勿添加任何其他内容
    • 如果用户明确要求更多内容(例如,“解释架构”、“建议改进”),你可以添加额外内容
    • 绝对不要添加未请求的部分,如概述、安全注意事项、测试等
    默认输出应简洁。架构图图片本身即可说明问题。
  7. 处理模块
    • 如果使用了模块,请显示模块边界
    • 包含模块参数和输出
    • 显示模块如何与主资源连接

Bicep-Specific Tips

Bicep特定提示

  • Show Resource Groups: Bicep deployments target resource groups
  • VNets as Containers: Show VNets containing subnets and resources
  • Include Dependencies: Show
    dependsOn
    relationships
  • Module Structure: If modules are used, show their boundaries
  • Parameters: Note key parameters that affect resource configuration
  • Use Azure Icons: Request Azure-specific styling
  • 显示资源组:Bicep部署以资源组为目标
  • 将VNet作为容器:显示VNet包含子网和资源
  • 包含依赖项:显示
    dependsOn
    关系
  • 模块结构:如果使用了模块,请显示其边界
  • 参数:记录影响资源配置的关键参数
  • 使用Azure图标:请求使用Azure特定样式

Example: Bicep with Parameters and Modules

示例:带参数和模块的Bicep代码

User Input

用户输入

bicep
@description('The name of the Virtual Network')
param vnetName string = 'myVNet'
@description('The address prefix for the VNet')
param vnetAddressPrefix string = '10.0.0.0/16'
@description('The address prefix for the subnet')
param subnetAddressPrefix string = '10.0.1.0/24'
@description('VM size')
param vmSize string = 'Standard_B1s'

// Main VNet resource
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
  name: vnetName
  location: resourceGroup().location
  properties: {
    addressSpace: {
      addressPrefixes: [vnetAddressPrefix]
    }
    subnets: [
      {
        name: 'subnet1'
        properties: {
          addressPrefix: subnetAddressPrefix
        }
      }
    ]
  }
}

// VM resource with dependsOn
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-11-01' = {
  name: 'myVM'
  location: resourceGroup().location
  properties: {
    hardwareProfile: {
      vmSize: vmSize
    }
  }
  dependsOn: [virtualNetwork]
}

// Module usage
module storageModule './modules/storage.bicep' = {
  name: 'storage'
  params: {
    location: resourceGroup().location
  }
}
bicep
@description('The name of the Virtual Network')
param vnetName string = 'myVNet'
@description('The address prefix for the VNet')
param vnetAddressPrefix string = '10.0.0.0/16'
@description('The address prefix for the subnet')
param subnetAddressPrefix string = '10.0.1.0/24'
@description('VM size')
param vmSize string = 'Standard_B1s'

// Main VNet resource
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
  name: vnetName
  location: resourceGroup().location
  properties: {
    addressSpace: {
      addressPrefixes: [vnetAddressPrefix]
    }
    subnets: [
      {
        name: 'subnet1'
        properties: {
          addressPrefix: subnetAddressPrefix
        }
      }
    ]
  }
}

// VM resource with dependsOn
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-11-01' = {
  name: 'myVM'
  location: resourceGroup().location
  properties: {
    hardwareProfile: {
      vmSize: vmSize
    }
  }
  dependsOn: [virtualNetwork]
}

// Module usage
module storageModule './modules/storage.bicep' = {
  name: 'storage'
  params: {
    location: resourceGroup().location
  }
}

Expected Behavior

预期行为

  1. Parses Bicep:
    • Parameters: vnetName, vnetAddressPrefix, subnetAddressPrefix, vmSize
    • Resources: VNet with subnet, VM with dependsOn relationship
    • Module: Storage module with parameters
  2. Generates DSL showing Bicep-specific features:
    myVNet [label: "VNet 10.0.0.0/16"] {
      subnet1 [label: "Subnet 1 10.0.1.0/24"] {
        myVM [icon: azure-vm, label: "VM Standard_B1s"]
      }
    }
    
    storage-module [label: "Storage Module"] {
      storage-account [icon: azure-storage]
    }
    
    myVNet -> myVM
    Important: All label text must be on a single line within quotes. Bicep-specific: Show modules as containers, include
    dependsOn
    relationships, note parameter usage in resource configuration.
  3. Calls
    /api/render/elements
    with
    diagramType: "cloud-architecture-diagram"
  4. Calls
    /api/render/elements
    with
    diagramType: "cloud-architecture-diagram"
  1. 解析Bicep代码:
    • 参数:vnetName、vnetAddressPrefix、subnetAddressPrefix、vmSize
    • 资源:带子网的VNet、带有dependsOn关系的VM
    • 模块:带参数的存储模块
  2. 生成显示Bicep特定功能的DSL:
    myVNet [label: "VNet 10.0.0.0/16"] {
      subnet1 [label: "Subnet 1 10.0.1.0/24"] {
        myVM [icon: azure-vm, label: "VM Standard_B1s"]
      }
    }
    
    storage-module [label: "Storage Module"] {
      storage-account [icon: azure-storage]
    }
    
    myVNet -> myVM
    重要提示:所有标签文本必须在引号内的单行中。Bicep特定要求:将模块显示为容器,包含
    dependsOn
    关系,在资源配置中记录参数使用情况。
  3. 调用
    /api/render/elements
    接口,指定
    diagramType: "cloud-architecture-diagram"
  4. 调用
    /api/render/elements
    接口,指定
    diagramType: "cloud-architecture-diagram"

Result

结果

User receives a diagram showing:
  • VNet as a container
  • Subnet nested inside VNet
  • VM in the subnet
  • Dependency relationship shown
  • Proper Azure styling
用户将收到显示以下内容的架构图:
  • VNet作为容器
  • 子网嵌套在VNet内
  • VM位于子网中
  • 显示依赖关系
  • 使用正确的Azure样式