什么是 Bicep(预览版)?What is Bicep (Preview)?

Bicep 是用来以声明方式部署 Azure 资源的一种语言。Bicep is a language for declaratively deploying Azure resources. 可以使用 Bicep(而不是 JSON)来开发 Azure 资源管理器模板(ARM 模板)。You can use Bicep instead of JSON for developing your Azure Resource Manager templates (ARM templates). Bicep 通过提供简洁的语法、更好的代码重用支持和改进的类型安全性来简化创作体验。Bicep simplifies the authoring experience by providing concise syntax, better support for code reuse, and improved type safety. Bicep 是一种特定于域的语言 (DSL),这意味着它是为特定方案或域设计的。Bicep is a domain-specific language (DSL), which means it's designed for a particular scenario or domain. 它并非旨在用作编写应用程序的常规编程语言。It isn't intended as a general programming language for writing applications.

用于创建模板的 JSON 语法可能比较繁琐,需要使用复杂的表达式。The JSON syntax for creating template can be verbose and require complicated expression. Bicep 改进了该体验,且没有丢失 JSON 模板的任何功能。Bicep improves that experience without losing any of the capabilities of a JSON template. 它是基于适用于 ARM 模板的 JSON 的透明抽象。It's a transparent abstraction over the JSON for ARM templates. 每个 Bicep 文件都会编译成标准的 ARM 模板。Each Bicep file compiles to a standard ARM template. 在 ARM 模板中有效的资源类型、API 版本和属性在 Bicep 文件中有效。Resource types, API versions, and properties that are valid in an ARM template are valid in a Bicep file. 当前版本有几个已知限制There are a few known limitations in the current release.

Bicep 目前为预览版。Bicep is currently in preview. 若要跟踪工作的状态,请参阅 Bicep 项目存储库To track the status of the work, see the Bicep project repository.

入门Get started

若要开始使用 Bicep,请安装工具To start with Bicep, install the tools.

安装这些工具后,请尝试 Bicep 教程After installing the tools, try the Bicep tutorial. 本教程系列将指导你完成 Bicep 的结构和功能。The tutorial series walks you through the structure and capabilities of Bicep. 你将部署 Bicep 文件,并将 ARM 模板转换为等效的 Bicep 文件。You deploy Bicep files, and convert an ARM template into the equivalent Bicep file.

若要并排查看等效的 JSON 和 Bicep 文件,请参阅 Bicep 操场To view equivalent JSON and Bicep files side by side, see the Bicep Playground.

如果要将现有 ARM 模板转换为 Bicep,请参阅在 JSON 和 Bicep 之间转换 ARM 模板If you have an existing ARM template that you would like to convert to Bicep, see Converting ARM templates between JSON and Bicep.

Bicep 相较于其他工具的优势Benefits of Bicep versus other tools

与其他选项相比,Bicep 具有以下优势:Bicep provides the following advantages over other options:

  • 支持所有资源类型和 API 版本:Bicep 直接支持 Azure 服务的所有预览版本和正式发布版本。Support for all resource types and API versions: Bicep immediately supports all preview and GA versions for Azure services. 在资源提供程序引入新的资源类型和 API 版本后,就可以立即在 Bicep 文件中使用它们。As soon as a resource provider introduces new resources types and API versions, you can use them in your Bicep file. 无需等待工具完成更新即可使用新服务。You don't have to wait for tools to be updated before using the new services.
  • 创作体验:使用 VS Code 创建 Bicep 文件时,可获得一流的创作体验。Authoring experience: When you use VS Code to create your Bicep files, you get a first-class authoring experience. 编辑器提供丰富的类型安全、智能感知和语法验证。The editor provides rich type-safety, intellisense, and syntax validation.
  • 模块化:可以使用 模块将 Bicep 代码分解为可管理的部分。Modularity: You can break your Bicep code into manageable parts by using modules. 该模块会部署一组相关资源。The module deploys a set of related resources. 通过模块,你可以重用代码和简化开发。Modules enable you to reuse code and simplify development. 需要部署这些资源时,可以随时将模块添加到 Bicep 文件。Add the module to a Bicep file anytime you need to deploy those resources.
  • 与 Azure 服务的集成:Bicep 与 Azure 服务(如 Azure Policy、模板规格和蓝图)集成。Integration with Azure services: Bicep is integrated with Azure services such as Azure Policy, template specs, and Blueprints.
  • 无需管理状态或状态文件:所有状态均存储在 Azure 中。No state or state files to manage: All state is stored in Azure. 用户可以相互协作,并确保按预期处理其更新。Users can collaborate and have confidence their updates are handled as expected. 在部署模板之前,请使用 what-if 操作来预览更改。Use the what-if operation to preview changes before deploying your template.
  • 免费和开源:Bicep 是完全免费的。No cost and open source: Bicep is completely free. 无需为高级功能付费。You don't have to pay for premium capabilities. 它也受 Azure 支持。It's also supported by Azure support.

Bicep 改进Bicep improvements

与等效的 JSON 相比,Bicep 提供了更简单且更简洁的语法。Bicep offers an easier and more concise syntax when compared to the equivalent JSON. 你不需要使用 [...] 表达式,You don't use [...] expressions. 而是可以直接调用函数,并从参数和变量获取值。Instead, you directly call functions, and get values from parameters and variables. 你将为每个已部署的资源指定一个符号名称,这样就可以轻松地在模板中引用该资源。You give each deployed resource a symbolic name, which makes it easy to reference that resource in your template.

例如,以下 JSON 从某个资源属性返回输出值。For example, the following JSON returns an output value from a resource property.

"outputs": {
  "hostname": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))).dnsSettings.fqdn]"

Bicep 中等效的输出表达式更容易编写。The equivalent output expression in Bicep is easier to write. 下面的示例使用模板中定义的资源的符号名称 publicIP 返回相同的属性:The following example returns the same property by using the symbolic name publicIP for a resource that is defined within the template:

output hostname string = publicIP.properties.dnsSettings.fqdn

有关语法的完整比较,请参阅比较模板的 JSON 和 BicepFor a full comparison of the syntax, see Comparing JSON and Bicep for templates.

Bicep 自动管理资源之间的依赖关系。Bicep automatically manages dependencies between resources. 当在其他资源声明中使用了某个资源的符号名称时,你不需要设置 dependsOnYou can avoid setting dependsOn when the symbolic name of a resource is used in another resource declaration.

Bicep 文件的结构比 JSON 模板更灵活。The structure of the Bicep file is more flexible than the JSON template. 可以在文件中的任意位置声明参数、变量和输出。You can declare parameters, variables, and outputs anywhere in the file. 在 JSON 中,你必须在模板的相应部分声明所有参数、变量和输出。In JSON, you have to declare all parameters, variables, and outputs within the corresponding sections of the template.

已知的限制Known limitations

当前存在以下限制:The following limits currently exist:

  • 无法在复制循环上设置模式或批大小。Can't set mode or batch size on copy loops.
  • 无法合并循环和条件。Can't combine loops and conditions.
  • 不支持单行对象和数组(如 ['a', 'b', 'c'])。Single-line object and arrays, like ['a', 'b', 'c'], aren't supported.


为什么要创建一种新语言而不是使用现有语言?Why create a new language instead of using an existing one?

你可以将 Bicep 视为现有 ARM 模板语言的修订版本,而不是一种新语言。You can think of Bicep as a revision to the existing ARM template language rather than a new language. 语法已更改,但核心功能和运行时保持不变。The syntax has changed, but the core functionality and runtime remain the same.

开发 Bicep 之前,我们考虑过使用现有的编程语言。Before developing Bicep, we considered using an existing programming language. 我们确信,目标受众会发现学习 Bicep 比开始使用另一种语言更容易。We decided our target audience would find it easier to learn Bicep rather than getting started with another language.

为什么不将精力集中在 Terraform 或其他第三方基础结构即代码产品/服务上?Why not focus your energy on Terraform or other third-party Infrastructure as Code offerings?

不同的用户喜欢使用不同的配置语言和工具。Different users prefer different configuration languages and tools. 我们想要确保所有这些工具在 Azure 上都能提供很棒的体验。We want to make sure all of these tools provide a great experience on Azure. Bicep 是此工作的一部分。Bicep is part of that effort.

如果你喜欢使用 Terraform,则无需进行切换。If you're happy using Terraform, there's no reason to switch. Microsoft 致力于确保 Azure 上的 Terraform 实现最佳效果。Microsoft is committed to making sure Terraform on Azure is the best it can be.

对于选择了 ARM 模板的客户,我们相信 Bicep 能够改进创作体验。For customers who have selected ARM templates, we believe Bicep improves the authoring experience. Bicep 还可帮助尚未采用基础结构即代码的客户进行过渡。Bicep also helps with the transition for customers who haven't adopted infrastructure as code.

Bicep 是否仅适用于 Azure?Is Bicep only for Azure?

Bicep 是一种 DSL,专用于将完整的解决方案部署到 Azure。Bicep is a DSL focused on deploying complete solutions to Azure. 要满足该目标,需要使用 Azure 外部的某些 API。Meeting that goal requires working with some APIs that are outside of Azure. 我们希望为这些方案提供扩展点。We expect to provide extensibility points for those scenarios.

现有 ARM 模板会发生什么情况?What happens to my existing ARM templates?

它们继续像往常一样正常运行。They continue to function exactly as they always have. 你不需要进行任何更改。You don't need to make any changes. 我们会继续支持基础 ARM 模板 JSON 语言。We'll continue to support the underlying ARM template JSON language. Bicep 文件将编译为 JSON,JSON 将发送到 Azure 进行部署。Bicep files compile to JSON, and that JSON is sent to Azure for deployment.

准备就绪后,你可以将 JSON 文件转换为 BicepWhen you're ready, you can convert the JSON files to Bicep.

后续步骤Next steps

开始使用 Bicep 教程Get started with the Bicep tutorial.