Support for Bicep Parameters for Types other than string

Open
#21,787 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
devtools

Research direction

Start by tracing the C# implementation of Bicep template parameters and how it writes .bicepparam files; the issue does not name the relevant files or tests. Reproduce the boolean and object examples, then check how parameter values are serialized and whether strings containing single quotes are escaped. Done means non-string values produce valid Bicep parameter syntax and the examples pass focused tests.

Written by the indexing model from the issue text.

Description

area-app-model
Is there an existing issue for this?
  • I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Problem or scenario

I wish to be able to provide parameter values for Bicep Templates like this:

param myString string = 'hello-world'

param myBool bool = true

type myType = {
  a: string
  b: string
}

@description('All VCS variables')
param myParam myType = {
  a: '1'
  b: '2'
}

Uncommenting either of the below lines results in

builder.AddBicepTemplate("HelloWorld", "HelloWorld.bicep")
 .WithParameter("myString", "5")
// .WithParameter("myBool", false)
// .WithParameter("myParam", "{'a':'1', 'b':'2'}")
    ;

myBool uncommented fails to even get as far as writing the bicepparam file.

Unsupported value type: 
System.Text.Json.Nodes.JsonValuePrimitive`1[System.Boolean]

myParam uncommented produces the following HelloWorld.parameters.biceparam file:

using './HelloWorld.bicep'

param myString = '5'
param myParam = '{'a':'1', 'b':'2'}'

Note: this reveals an additional bug: Aspire, or Aspire-1p, is failing to escape the single quotes.
and error message:

Error BCP033: Expected a value of type "{ a: string, b: string }" but the provided value is of type 
"'{'". [https://aka.ms/bicep/core-diagnostics#BCP033]

Also note: Aspire is not escaping ' when it should be

Describe the solution you'd like

Parameter support for Bicep types. Bicep's data model is json-centric, so continuing to treat them as strings, but if the bicep parameter is of a non-string type, converting it to Bicep's representation of the same, might be one option

Additional context

No response

Dominant language
C#
Stars
6.4k
Forks
1k
Avg merge
3d 3h
Merged PRs (30d)
406

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/aspire

All issues in microsoft/aspire

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.