Skip to content

Conversation

@andyleejordan
Copy link
Member

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 resources as either an array or an object and produce what the existing implementation expects: a Vec<Resource> such that after the initial deserialization, nothing else needs to change. This means that later ordering should work (though when I tested dependsOn in 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:

extension dsc
targetScope = 'desiredStateConfiguration'

resource myEcho 'Microsoft.DSC.Debug/[email protected]' = {output: 'Hello world!'}

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!"
      }
    }
  }
}

Perhaps 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 with deny_unknown_fields. Perhaps we should revisit that serde flag, possibly using the linked workaround with IgnoredAny and warnings instead of failures.

I have to admit that the additional tests were generated by Claude, though it was pretty good at it!

#[test]
fn test_deserialize_resources_array() {
let config_json = r#"{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the schema be: https://aka.ms/dsc/schemas/v3/bundled/config/document.json?

#[test]
fn test_deserialize_resources_object() {
let config_json = r#"{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here?

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.

2 participants