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.Validate
Runs az deployment group validate. A non-zero exit fails the step. az's JSON (which includes every parameter value) is not logged; on success the step logs Validation succeeded, and an error in the JSON fails the step with its message. Takes the same options as the deploy operations, including WithSecureParameter (but not together with a .bicepparam file). Step context is the resource group.
Bicep.ValidateSubscription
Runs az deployment sub validate --location. Subscription scope has no --mode, so WithMode(DeploymentMode.Complete) throws when the step is registered. az's JSON (which includes every parameter value) is not logged; on success the step logs Validation succeeded, and an error in the JSON fails the step with its message. Step context is the location.
Bicep.WhatIf
Runs az deployment group what-if --no-pretty-print and returns a BicepWhatIfResult that the step fills when it runs. Read it inside execution-time lambdas (Ando.Require, Ando.Confirm(Func), Ando.When); reading it earlier throws. Members: Changes (each with ResourceId, ChangeType as az reports it, PropertyChanges count), Summary (for example 2 Create, 1 Modify, 30 NoChange), HasChanges(params string[] types) (no types: anything except NoChange and Ignore), OfType(type) and Json. The step logs the summary and one line per change that is not NoChange or Ignore. A what-if with status Failed or an error fails the step with az's message. az's raw JSON is not logged (it can echo parameter values). HasChanges and OfType look at changes only, not at az's potentialChanges. Scripts that ignore the return value still work. Step context is the resource group.
Bicep.WhatIfSubscription
Runs az deployment sub what-if --location and returns a BicepWhatIfResult; see Bicep.WhatIf. Step context is the location.
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.DeployToResourceGroup("my-rg", "./main.bicep", o => o
  .WithParameterFile("./params.json")
  .WithParameterFile("./params.prod.json") // later .json files override earlier ones; a .bicepparam must be the only file
  .WithSecureParameter("edgeKey", key)); // temp 0600 file in the container, never on a command line

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.Validate source

Runs az deployment group validate. A non-zero exit fails the step. az's JSON (which includes every parameter value) is not logged; on success the step logs Validation succeeded, and an error in the JSON fails the step with its message. Takes the same options as the deploy operations, including WithSecureParameter (but not together with a .bicepparam file). Step context is the resource group.

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

Bicep.ValidateSubscription source

Runs az deployment sub validate --location. Subscription scope has no --mode, so WithMode(DeploymentMode.Complete) throws when the step is registered. az's JSON (which includes every parameter value) is not logged; on success the step logs Validation succeeded, and an error in the JSON fails the step with its message. Step context is the location.

Bicep.ValidateSubscription("westeurope", "./infra/sub.bicep");

Bicep.WhatIf source

Runs az deployment group what-if --no-pretty-print and returns a BicepWhatIfResult that the step fills when it runs. Read it inside execution-time lambdas (Ando.Require, Ando.Confirm(Func), Ando.When); reading it earlier throws. Members: Changes (each with ResourceId, ChangeType as az reports it, PropertyChanges count), Summary (for example 2 Create, 1 Modify, 30 NoChange), HasChanges(params string[] types) (no types: anything except NoChange and Ignore), OfType(type) and Json. The step logs the summary and one line per change that is not NoChange or Ignore. A what-if with status Failed or an error fails the step with az's message. az's raw JSON is not logged (it can echo parameter values). HasChanges and OfType look at changes only, not at az's potentialChanges. Scripts that ignore the return value still work. Step context is the resource group.

Bicep.WhatIf("my-rg", "./infra/main.bicep");
var plan = Bicep.WhatIf("my-rg", "./infra/main.bicep", o => o.WithParameterFile("./params.json"));
Ando.Require(() => !plan.HasChanges("Delete"), "The plan deletes resources.");
Ando.Confirm(() => $"Deploy ({plan.Summary})?");
Bicep.DeployToResourceGroup("my-rg", "./infra/main.bicep", o => o.WithParameterFile("./params.json"));

Bicep.WhatIfSubscription source

Runs az deployment sub what-if --location and returns a BicepWhatIfResult; see Bicep.WhatIf. Step context is the location.

var plan = Bicep.WhatIfSubscription("westeurope", "./infra/sub.bicep");
Ando.Require(() => !plan.HasChanges("Delete"), "The plan deletes resources.");

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.

// Validate, then preview the changes and gate the deployment on the plan
Bicep.Validate("my-app-rg", "./infra/main.bicep", o => o
  .WithParameterFile("./infra/params.prod.json"));
var plan = Bicep.WhatIf("my-app-rg", "./infra/main.bicep", o => o
  .WithParameterFile("./infra/params.prod.json"));
Ando.Require(() => !plan.HasChanges("Delete"), "The plan deletes resources.");
Ando.Confirm(() => $"Deploy ({plan.Summary})?");

// 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

Options (deploy, validate and what-if, both scopes)

OptionDescription
WithName(string)Custom deployment name. Defaults to the template filename. Useful for tracking deployments in Azure Portal activity log.
WithParameterFile(string)Adds a parameters file. Call it repeatedly for .json files: each file becomes --parameters @file, in call order, and az lets later files override earlier values. A .bicepparam file must be the only parameter file: az allows only inline KEY=VALUE parameters next to it, so combining it with another file or with WithSecureParameter throws when the step is registered.
WithParameter(name, value)Adds an inline parameter value. It goes on the az command line, so it shows in process listings: use it for non-secret values only. Can be called multiple times.
WithSecureParameter(name, value)Adds a secret parameter. The value is registered for redaction at the call. When the step runs, ANDO writes all secure parameters to one temporary parameters file in the build container (/tmp/ando-bicep-<guid>.json, mode 0600), passes it as the last --parameters @file, and deletes it afterwards, also when az fails. The value never appears on a command line or in logs. Values shorter than 6 characters are not redacted from logs. The JSON-escaped form of the value is redacted too. Not usable with a .bicepparam file.
WithParameter(name, Func<string>)Like WithParameter(name, value), but the value is resolved when the step runs, so it can read a StepOutput: o.WithParameter("key", () => sshKey.Value). Non-secret values only: it goes on the az command line.
WithSecureParameter(name, Func<string>)Like WithSecureParameter(name, value), resolved when the step runs, for example () => key.Value with var key = Azure.Cli("vm", "show", ...).Quiet();. The value is registered for redaction (with its JSON-escaped forms) when it is resolved, before any command runs, then goes into the 0600 parameters file. Redaction starts only when the Bicep step resolves the value, so the step that produced it may already have logged it: keep that step quiet (Azure.Cli(...).Quiet() does; Azure.Vm.RunCommand logs every stdout line and cannot be quieted). Not allowed next to a .bicepparam file.
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). Complete works at resource group scope only: az has no --mode at subscription scope, so DeployToSubscription, ValidateSubscription and WhatIfSubscription throw when the step is registered.
WithDeploymentSlot(string)Deployment slot for App Service resources. Used when deploying to a specific slot (e.g., “staging”) rather than production.

Validate

Bicep.Validate(resourceGroup, template, options?) runs az deployment group validate; Bicep.ValidateSubscription(location, template, options?) runs az deployment sub validate --location. A non-zero exit fails the step. az’s JSON output, which includes every parameter value, is not logged; the step logs Validation succeeded instead, and an error in the JSON fails the step with its message.

What-if

Bicep.WhatIf(resourceGroup, template, options?) runs az deployment group what-if --no-pretty-print and Bicep.WhatIfSubscription(location, template, options?) runs az deployment sub what-if --location. Both return a BicepWhatIfResult that the step fills when it runs. Read it inside execution-time lambdas such as Ando.Require, Ando.Confirm(Func) and Ando.When; reading it earlier throws. Scripts that ignore the return value keep working.

MemberDescription
ChangesThe changes, each with ResourceId, ChangeType (as az reports it: Create, Delete, Modify, NoChange, Ignore, Deploy, Unsupported) and PropertyChanges (number of property changes).
SummaryCounts by type, for example 2 Create, 1 Modify, 30 NoChange.
HasChanges(params string[] types)Whether any change has one of the types. With no types: whether anything except NoChange and Ignore would change. Looks at az’s changes only, not at potentialChanges.
OfType(type)The changes of one type.
JsonThe raw az output.

The step logs the summary and one line per change that is not NoChange or Ignore. az’s raw what-if JSON is not written to the log (it can echo parameter values); stderr is still logged. HasChanges and OfType look at changes only, not at az’s potentialChanges. A what-if with status Failed, or with an error, fails the step with az’s message.