-
Notifications
You must be signed in to change notification settings - Fork 55
Add support for resources to be represented as hash map as part of ARM Language 2.0 #1210
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
Conversation
resources as an object4781e15 to
30816bb
Compare
|
@SteveL-MSFT Pester test added for the latest ARM generated by Bicep. Note that Azure/bicep#18365 will be required to use "just" the |
|
Just a heads up that as noted in the PR, Bicep has and will likely continue to add new fields (especially when using experimental features) and since we're setting |
|
@andyleejordan I'm in agreement that we should relax the strict validation, but then we'd need to warn about unknown new properties. That can be a separate PR, can you open an issue for this? |
30816bb to
3ab8b95
Compare
This is metadata from Bicep.
Which is necessary to support ARMv2's new "symbolic names" structure. Many alternatives were tried, including updating the type to be an `enum` and then either implementing the used `Vec`-like interfaces or pattern matching on the type everywhere `resources` used. Neither of these were great and resulted in a lot of unnecessary code churn. The `serde_with` library was also briefly tried with the `PickAs` trait, but the only thing that gained was eliminating the need to define the (very easy) deserialization of `Array`, at the cost of multiple additional libraries. This seems to be the best way forward as it results in the least possible potential problems and eliminates changes throughout the codebase. What it lacks it the ability serialize to ARMv2, but that's not (yet) desired. It also has not fixed `dependsOn` but that would need to be done regardless.
This verifies that the errors from the Serde library are the same as before the custom deserializer was implemented.
3ab8b95 to
bdab48f
Compare
|
CI is failing because the PowerShell Gallery is down due to the Azure Front Door outage. |
Resolves #1193 (at least what we know is required experimentally).
Okay so I tried a bunch of different ways and settled on this being the simplest approach. In short, a custom serde deserializer function let's us take
resourcesas either an array or an object and produce what the existing implementation expects: aVec<Resource>such that after the initial deserialization, nothing else needs to change. This means that later ordering should work (though when I testeddependsOnin Bicep, I got a different error).I can at least now pass through this Bicep directly to DSC and it gets to the point that it attempts to execute the resource:
which produces this ARM/JSON:
{ "$schema": "https://aka.ms/dsc/schemas/v3/bundled/config/document.json", "languageVersion": "2.0", "contentVersion": "1.0.0.0", "metadata": { "_generator": { "name": "bicep", "version": "0.38.33.27573", "templateHash": "9007474339958309780" } }, "imports": { "dsc": { "provider": "DesiredStateConfiguration", "version": "0.1.0" } }, "resources": { "myEcho": { "import": "dsc", "type": "Microsoft.DSC.Debug/[email protected]", "properties": { "output": "Hello world!" } } } }Note that there is also a slightly different variation which uses
extension(s)instead ofimport(s)with a particular experimental feature flag that, as of right now, is necessary for the end-to-end demo to work. Those are also added and ignored. See Azure/bicep#18365Perhaps we should gate this behind a feature-flag, but between this and publishing a basic version of the Bicep extension to an MCR, we can resume demos but with fancy IntelliSense and working versions!
For the fields noted as irrelevant, I sure would like to use
#[serde(skip)]but it is incompatible withdeny_unknown_fields. Perhaps we should revisit that Serde flag, possibly using the linked workaround withIgnoredAnyand warnings instead of failures.