AzureFunBytes Reminder - Intro to @BicepLang with @adotfrank - 7/8/2021
Tags: iac, azure, cloud, beginners
Published: 2021-07-07 14:50:57

AzureFunBytes is a weekly opportunity to learn more about the fundamentals and foundations that make up Azure. It's a chance for me to understand more about what people across the Azure organization do and how they do it. Every week we get together at 11 AM Pacific on [Microsoft LearnTV](https://cda.ms/226) and learn more about Azure.

When: July 8, 2021 11 AM Pacific / 2 PM Eastern
Where: [Microsoft LearnTV](https://cda.ms/226)

![AzureFunBytes animation](https://res.cloudinary.com/practicaldev/image/fetch/s--Z7BxBMz1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2xzw2g664tj31jij13t.gif)

This week on AzureFunBytes we flex some Azure muscle with [Bicep](https://cda.ms/2dv).  Bicep is a language that allows you to use a declarative syntax to codify your Azure infrastructure deployments.  Bicep is an Azure native [Domain-Specific Language (DSL)](https://cda.ms/2dm) that promotes a cleaner syntax, improved type safety, and better support for modularity and re-use of code.  Bicep is a transparent abstraction over [Azure Resource Manager (ARM) templates](https://cda.ms/2dt) that gives you the ability to create nearly any required resource within Azure.  [Bicep has a playground](https://bicepdemo.z22.web.core.windows.net/) that allows you to start using existing ARM Template Quickstarts right away.  Or if you choose to build them from scratch, the snippets with the [VS Code Bicep extension](https://cda.ms/2df) will be a huge help. 

![Bicep to JSON](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/987m8ma7xxtofjt533aj.png)

I was lucky enough to get one of the experts on Bicep to join us this week!  We'll welcome [Microsoft Program Manager Alex Frankel](https://twitter.com/adotfrank) to the show to give us greater insight into how to use Bicep to create our infrastructure.  I'll ask Alex your questions, we'll look at some Bicep basics, discuss best practices, and even kick off some deployments.  Don't miss this incredible opportunity to learn about building your [Infrastructure as Code (IAC)](https://cda.ms/2dg) with Bicep!

{% youtube zIz23oeLzdA %}

Our Agenda:

- Why we are investing in bicep in the first place
  - ARM Templates are by far the most popular declarative tool for deploying to Azure, want to improve experience for those customers
  - Clarify that Bicep is just one of many great options
- Key differences between Bicep and ARM templates
  - Modules, richer intellisense, auto DependsOn, richer type safety
- How the language is designed and the importance of tooling
  - In terms of language design (not complexity), Bicep shares more DNA with C# and TypeScript than traditional “scripting” languages like HCL or Chef
  - Tooling is built alongside the language, so our syntax decisions are always driven by our ability to build tooling to go with it
- Benefits of being “Azure native”
  - Day zero support for all resource types
  - No state management without losing the ability to perform what-if (“tf plan” equivalent) and manage lifecycle (“tf destroy” equivalent)
  - Works with other platform capabilities like Template Specs, Azure Marketplace, etc.

Full details of how the Bicep language works can be found in the [Bicep documentation] and there is a rich library of examples to help you get a jumpstart.

[*From the Bicep GitHub repository docs, how to get started:*](https://github.com/Azure/bicep) 

To get going with Bicep:

1. **Start by [installing the tooling](https://github.com/Azure/bicep/blob/main/docs/installing.md).**
2. **Complete the [Bicep tutorial](https://github.com/Azure/bicep/blob/main/docs/tutorial/01-simple-template.md)**

Alternatively, you can try the [Bicep Playground](https://aka.ms/bicepdemo) or use the [VS Code Devcontainer/Codespaces](https://github.com/Azure/vscode-remote-try-bicep) repo to get a preconfigured environment.

If you have an existing ARM Template or set of resources that you would like to convert to `.bicep` format, see [Decompiling an ARM Template](https://github.com/Azure/bicep/blob/main/docs/decompiling.md).

Full details of how the bicep language works can be found in the [Bicep documentation](https://github.com/Azure/bicep/tree/main/docs) and there is a rich library of [examples](https://github.com/Azure/bicep/tree/main/docs/examples) to help you get a jumpstart.

## How does Bicep work?

First, author your Bicep code using the Bicep language service as part of the [Bicep VS Code extension](https://github.com/Azure/bicep/blob/main/docs/installing.md#bicep-vs-code-extension)

Both [Az CLI](https://cda.ms/2d9) (2.20.0+) and the [PowerShell Az module](https://cda.ms/2d8) (v5.6.0+) have Bicep support built-in. This means you can use the standard deployment commands with your `*.bicep` files and the tooling will transpile the code and send it to ARM on your behalf. For example, to deploy `main.bicep` to a resource group `my-rg`, we can use the CLI command we are already used to:

```
az deployment group create -f ./main.bicep -g my-rg
```

For more detail on taking advantage of new Bicep constructs that replace an equivalent from ARM Templates, you can read the [moving from ARM => Bicep](https://github.com/Azure/bicep/blob/main/docs/arm2bicep.md) doc.

Here's an example of a Bicep template to create a two subnet Azure VNET:

```json
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
  name: 'name'
  location: resourceGroup().location
  properties: {
    addressSpace: {
      addressPrefixes: [
        '10.0.0.0/16'
      ]
    }
    subnets: [
      {
        name: 'Subnet-1'
        properties: {
          addressPrefix: '10.0.0.0/24'
        }
      }
      {
        name: 'Subnet-2'
        properties: {
          addressPrefix: '10.0.1.0/24'
        }
      }
    ]
  }
}
```
You can add [parameters](https://cda.ms/2dp), [use modules](https://cda.ms/2dr), [link templates](https://cda.ms/2ds), [set variables](https://cda.ms/2dq), and set [outputs](https://cda.ms/2dn) within your template.  You can deploy your Bicep templates using [Azure CLI](https://cda.ms/2dh), [PowerShell](https://cda.ms/2dj), and even the [Azure Portal](https://cda.ms/2dk).

[The Bicep 0.4 community call from June 2, 2021:](https://www.youtube.com/watch?v=3xLLFuWhmdQ)

{% youtube 3xLLFuWhmdQ %}

------

Learn about Azure fundamentals with me!

Live stream is normally found on Twitch, YouTube, and LearnTV at 11 AM PT / 2 PM ET Thursday. You can also find the recordings here as well:

[AzureFunBytes on Twitch](https://twitch.tv/azurefunbytes)
[AzureFunBytes on YouTube](https://aka.ms/jaygordononyoutube)
[Azure DevOps YouTube Channel](https://www.youtube.com/channel/UC-ikyViYMM69joIAv7dlMsA)
[Follow AzureFunBytes on Twitter](https://twitter.com/azurefunbytes)

Useful Docs:

[Get $200 in free Azure Credit](https://cda.ms/219)
[Microsoft Learn: Introduction to Azure fundamentals](https://cda.ms/243)
[Microsoft Learn: Deploy and manage resources in Azure by using Bicep](https://cda.ms/2dc)
[Bicep Documentation](https://cda.ms/2db) 
[Quickstart: Create Bicep files with Visual Studio Code](https://cda.ms/2df)
[Bicep Playground](https://bicepdemo.z22.web.core.windows.net/)
[ARM template documentation](https://cda.ms/2dt)
[Bicep on Twitter](https://twitter.com/BicepLang)
[Install the Azure CLI](https://cda.ms/2d9)
[Best practices for Bicep](https://cda.ms/2dd)
[What is Infrastructure as Code?](https://cda.ms/2dg)
[About Domain-Specific Languages](https://cda.ms/2dm)

{% youtube sc1kJfcRQgY %}