PowerShell / PowerShell/DSC

DSC Resource declared in `yaml` not discovered if `schema:` is present and not working if `schema:` is absent.

Open
#366 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Need-Review
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Steps to reproduce

In PR #311 support for definitions of resources in YAML was added. However, this does not appear to be working as expected for the schema portion of the definition.

Using a working json schema for a resource (see below), I run y2j to convert it to yaml (also seen below), but the resource is not discovered when dsc resource list is executed. If I remove the schema: section at the end of the yaml file (as this example suggests is not necessary) the resource is discovered but does not execute as the schema is missing from the resource. As I am using the yaml language server validation, any modification to the schema section to support a YAML tag does not appear valid.

working Json resource definition

{
  "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.json",
  "type": "joshcorr/test",
  "version": "0.1.0",
  "description": "Synopsis for the resource's purpose",
  "get": {
    "executable": "powershell",
    "args": [
      "-NoLogo",
      "-NonInteractive",
      "-NoProfile",
      "-Command",
      "$value = ($Input | ConvertFrom-Json).text;",
      "@{\"text\"=\"$value\"} | Convertto-json -Compress"
    ],
    "input": "stdin"
  },
  "set": {
    "executable": "powershell",
    "args": [
      "-NoLogo",
      "-NonInteractive",
      "-NoProfile",
      "-Command",
      "$value = ($Input | ConvertFrom-Json).text;",
      "@{\"text\"=\"$value set\"} | Convertto-json -Compress"
    ],
    "input": "stdin",
    "implementsPretest": false,
    "return": "state"
  },
  "schema": {
    "embedded": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "properties": {
        "name": {
          "title": "text",
          "description": "Defines the text you want to output",
          "type": "string"
        }
      }
    }
  }
}

non discoverable yaml resource definition

# yaml-language-server: $schema=https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.vscode.json
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.json
type: joshcorr/test
version: 0.1.0
description: Synopsis for the resource's purpose
get:
  executable: powershell
  args:
  - -NoLogo
  - -NonInteractive
  - -NoProfile
  - -Command
  - $value = ($Input | ConvertFrom-Json).text;
  - '@{"text"="$value"} | Convertto-json -Compress'
  input: stdin
set:
  executable: powershell
  args:
  - -NoLogo
  - -NonInteractive
  - -NoProfile
  - -Command
  - $value = ($Input | ConvertFrom-Json).text;
  - '@{"text"="$value set"} | Convertto-json -Compress'
  input: stdin
  implementsPretest: false
  return: state
schema:
  embedded:
    $schema: http://json-schema.org/draft-07/schema#
    type: object
    properties:
      name:
        title: text
        description: Defines the text you want to output
        type: string

discoverable but non-working yaml resource definition

# yaml-language-server: $schema=https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.vscode.json
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.json
type: joshcorr/test
version: 0.1.0
description: Synopsis for the resource's purpose
get:
  executable: powershell
  args:
  - -NoLogo
  - -NonInteractive
  - -NoProfile
  - -Command
  - $value = ($Input | ConvertFrom-Json).text;
  - '@{"text"="$value"} | Convertto-json -Compress'
  input: stdin
set:
  executable: powershell
  args:
  - -NoLogo
  - -NonInteractive
  - -NoProfile
  - -Command
  - $value = ($Input | ConvertFrom-Json).text;
  - '@{"text"="$value set"} | Convertto-json -Compress'
  input: stdin
  implementsPretest: false
  return: state
Expected behavior
dsc resource list joshcorr/test

Type           Version  Methods   Requires  Description
-------------------------------------------------------------------------------
joshcorr/test  0.1.0    get, set            Synopsis for the resource's purpose

when executing the resource (that may be discovered)

(@{"text" = "something2" }  | ConvertTo-Json) | dsc resource set -r joshcorr/test
beforeState:
  text: something2
afterState:
  text: something2 set
changedProperties:
- text
Actual behavior
dsc resource list joshcorr/test
2024-03-17T21:56:25.513921Z  WARN dsc_lib::discovery::command_discovery: 64: Manifest: C:\Users\User\.dsc\resources\test.dsc.resource.yaml
YAML: schema: invalid type: map, expected a YAML tag starting with '!' at line 28 column 3

Type  Version  Methods  Requires  Description
---------------------------------------------

when executing the resource (that may be discovered)

(@{"text" = "something2" }  | ConvertTo-Json) | dsc resource set -r joshcorr/test
2024-03-17T22:08:17.123920Z ERROR dsc::resource_command: 139: Error: Validation: Schema not available
Error details

No response

Environment data
Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Version

dsc 3.0.0-alpha.5

Visuals

No response

Contributor guide

Open the contributing guide

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.

Research direction

Start with the resource discovery path used by dsc resource list and the YAML manifest behavior introduced in PR #311. Compare the YAML example in schemas/examples/foo.dsc.resource.yaml with the reproduced manifest, then trace how schema.embedded is handled when dsc resource set validates a resource. Done means the YAML resource is discovered with its embedded schema and executes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, yaml
Domain
devops, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.