Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expressions in Bicep parameters files #10248

Merged
merged 7 commits into from
Mar 31, 2023
Merged

Conversation

anthony-c-martin
Copy link
Member

@anthony-c-martin anthony-c-martin commented Mar 29, 2023

This adds support for the "sys" namespace in Bicep parameters files - function expressions can be used to generate parameter file values.

Microsoft Reviewers: Open in CodeFlow

@anthony-c-martin anthony-c-martin mentioned this pull request Mar 29, 2023
18 tasks
@anthony-c-martin anthony-c-martin changed the title [POC] Expressions in Bicep parameters files Expressions in Bicep parameters files Mar 30, 2023
@anthony-c-martin anthony-c-martin marked this pull request as ready for review March 30, 2023 23:48
@anthony-c-martin anthony-c-martin force-pushed the ant/exp/param_expressions branch 2 times, most recently from 42f9f64 to 74754a6 Compare March 31, 2023 12:49
Comment on lines +497 to +498
// We may emit duplicate errors here - type checking will also execute some ARM functions and generate errors
// This is something we should improve before the first release.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option here may be to use the type of the parameter assignment instead of re-evaluating. I'm not sure if it covers all cases, but if model.GetTypeInfo(parameter.DeclaringSyntax) returns a type for which TypeHelper.IsLiteralType returns true, it can be converted directly to a JToken.

Copy link
Member Author

@anthony-c-martin anthony-c-martin Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out with a similar approach - relying purely on type analysis to catch issues, but found that there were cases where the conversion wasn't being blocked (leading to a compilation failure). This definitely feels like a viable approach if we're able to guarantee we're always going to get either an error or a literal type.

The approach I'm taking here is definitely too heavy-handed - I'm mostly interested in trying to get some early feedback and use cases while the functionality is behind a feature flag, and plan to re-think it before an actual release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. The type system doesn't consider it a failure if a type is non-literal, but that's the behavior we want in params files. The evaluator approach is likely to give you better error messaging than just raising a diagnostic if a parameters type is non-literal.

The type system also wouldn't be able to handle the params-for-params scenarios we've discussed.

Copy link
Contributor

@jeskew jeskew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@anthony-c-martin anthony-c-martin merged commit f756a13 into main Mar 31, 2023
@anthony-c-martin anthony-c-martin deleted the ant/exp/param_expressions branch March 31, 2023 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants