Bicep

Deploy Azure infrastructure using Bicep templates.

Operations

Operation Description
Bicep.DeployToResourceGroup
Deploy a Bicep template to a resource group. Returns a BicepDeployment with typed access to outputs via deployment.Output("name").
Bicep.DeployToSubscription
Deploy a Bicep template at subscription scope. Returns a BicepDeployment with typed access to outputs via deployment.Output("name").
Bicep.WhatIf
Preview what would be deployed (what-if analysis).
Bicep.Build
Compile a Bicep file to ARM JSON template.

Operation Details

Bicep.DeployToResourceGroup source

Deploy a Bicep template to a resource group. Returns a BicepDeployment with typed access to outputs via deployment.Output("name").

var deployment = Bicep.DeployToResourceGroup("my-rg", "./infra/main.bicep");
var deployment = Bicep.DeployToResourceGroup("my-rg", "./main.bicep", o => o
  .WithParameterFile("./params.json")
  .WithDeploymentSlot("staging"));
Ef.DatabaseUpdate(db, deployment.Output("sqlConnectionString"));

Bicep.DeployToSubscription source

Deploy a Bicep template at subscription scope. Returns a BicepDeployment with typed access to outputs via deployment.Output("name").

var deployment = Bicep.DeployToSubscription("eastus", "./infra/sub.bicep");
var deployment = Bicep.DeployToSubscription("eastus", "./sub.bicep", o => o
  .WithParameter("environment", "prod"));
var resourceGroup = deployment.Output("resourceGroupName");

Bicep.WhatIf source

Preview what would be deployed (what-if analysis).

Bicep.WhatIf("my-rg", "./infra/main.bicep");
Bicep.WhatIf("my-rg", "./main.bicep", o => o.WithParameterFile("./params.json"));

Bicep.Build source

Compile a Bicep file to ARM JSON template.

Bicep.Build("./infra/main.bicep");
Bicep.Build("./main.bicep", "./output/main.json");

Example

Deploy infrastructure and use outputs in subsequent steps.

// Preview changes first
Bicep.WhatIf("my-app-rg", "./infra/main.bicep", o => o
  .WithParameterFile("./infra/params.prod.json"));

// Deploy - returns BicepDeployment with typed output access
var deployment = Bicep.DeployToResourceGroup("my-app-rg", "./infra/main.bicep", o => o
  .WithParameterFile("./infra/params.prod.json"));

// Pass deployment outputs to other operations
Ef.DatabaseUpdate(DbContext, deployment.Output("sqlConnectionString"));

// Build Bicep to ARM for validation
Bicep.Build("./infra/main.bicep", "./artifacts/main.json");

Options Reference

Bicep.DeployToResourceGroup / DeployToSubscription / WhatIf Options

OptionDescription
WithName(string)Custom deployment name. Defaults to the template filename. Useful for tracking deployments in Azure Portal activity log.
WithParameterFile(string)Path to parameters file. Supports both JSON parameter files (.json) and Bicep parameter files (.bicepparam).
WithParameter(name, value)Add an inline parameter value. Overrides values from parameter files. Can be called multiple times for multiple parameters.
WithMode(DeploymentMode)Deployment mode: DeploymentMode.Incremental (default) adds/updates resources but doesn’t delete missing ones. DeploymentMode.Complete deletes resources not in the template (use with caution).
WithDeploymentSlot(string)Deployment slot for App Service resources. Used when deploying to a specific slot (e.g., “staging”) rather than production.