Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Jan 27, 2026

PR Summary

To support the scenario where the config installs resources that will get used later, this change introduces new metadata under the Microsoft.DSC namespace to enable re-discovery of resources during deployment:

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/manifest.json
  metadata:
    Microsoft.DSC:
      resourceDiscovery: duringDeployment
      resources:
        ...

The new resourceDiscovery property accepts preDeployment (the default) or duringDeployment. preDeployment means that all resources (except within a group) are discovered and validated before deployment. So if any resource is missing, no resources are executed (this PR fixes that regression).

For testing, this PR creates a new test resource where you can specify a manifest file to copy and rename the type name to simulate the installation of a new resource (the new resource still needs to adhere to current discovery rules).

One side effect here is that to support dynamically installed resources, before EVERY resource invocation, a discovery is performed. We can optimize this in the future later based on other ideas in the issue below.

This change required storing the mode in Discovery and also CommandDiscovery to force rediscovery since both previously optimized where if it had results cached, it skipped discovery every time.

Also fixed an issue in the Install-Protobuf helper function as winget returns a non-zero exit code if the package is already installed. Fix is to use --force to force an install.

PR Context

Fix #1170

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new resourceDiscovery metadata option under the Microsoft.DSC namespace to support discovering resources during deployment, enabling scenarios where configurations install resources that are then used later in the same run.

Changes:

  • Introduces a new ResourceDiscoveryMode (preDeployment / duringDeployment) metadata option and wires it into configuration validation and the discovery pipeline, including dynamic re-discovery via Discovery.refresh_cache and CommandDiscovery’s discovery mode.
  • Adds a new test-only resource Test/CopyResource (implemented via the dsctest tool) that can copy an existing resource manifest and retarget its type, plus a manifest entry and schema support for this resource.
  • Extends PowerShell tests to cover the new resourceDiscovery behavior, verifying both failure in pre-deployment mode and success when discovery happens during deployment.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tools/dsctest/src/main.rs Wires a new copy-resource subcommand into dsctest, handling JSON input, invoking the copy helper, and exposing a schema for the new CopyResource input.
tools/dsctest/src/copy_resource.rs Defines the CopyResource schema and implements copy_the_resource, which rewrites the type in a source manifest and emits a new .dsc.resource.json file for the desired type.
tools/dsctest/src/args.rs Adds CopyResource to the Schemas enum and defines the copy-resource CLI subcommand used by the test resource manifest.
tools/dsctest/dsctest.dsc.manifests.json Registers Test/CopyResource as a test resource backed by the dsctest binary, including schema wiring via the schema subcommand.
lib/dsc-lib/src/discovery/mod.rs Extends the Discovery struct with a refresh_cache flag and updates find_resource/find_resources to support forced rediscovery using the new discovery mode.
lib/dsc-lib/src/discovery/discovery_trait.rs Updates the ResourceDiscovery trait to be aware of ResourceDiscoveryMode and adds a set_discovery_mode method implemented by discovery backends.
lib/dsc-lib/src/discovery/command_discovery.rs Tracks a discovery_mode in CommandDiscovery and adjusts its caching and discovery behavior so that DuringDeployment forces re-discovery while allowing pre-deployment caching when appropriate.
lib/dsc-lib/src/configure/mod.rs Reads the new metadata.Microsoft.DSC.resourceDiscovery value, skips pre-deployment resource validation when set to duringDeployment, and sets Discovery.refresh_cache for runtime rediscovery.
lib/dsc-lib/src/configure/config_doc.rs Defines the ResourceDiscoveryMode enum, adds it to MicrosoftDscMetadata, and updates serde metadata so resourceDiscovery is available in the config schema under the Microsoft.DSC namespace.
lib/dsc-lib/locales/en-us.toml Adds a localized message indicating that resource discovery is being skipped due to resourceDiscovery: duringDeployment.
dsc/tests/dsc_discovery.tests.ps1 Adds Pester tests covering resourceDiscovery modes, including a scenario that uses Test/CopyResource to install a resource during deployment and then invoke it in the same configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

SteveL-MSFT and others added 2 commits January 26, 2026 17:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Jan 28, 2026
Merged via the queue into PowerShell:main with commit 3780743 Jan 28, 2026
19 checks passed
@SteveL-MSFT SteveL-MSFT deleted the config-resource-discovery branch January 28, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Have metadata in config to have dsc engine ignore missing resources

2 participants