PowerShell / PowerShell/DSC

Synthetic export should re-export `name`

Open
#1,122 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Enhancement Needs Triage
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Summary of the new feature / enhancement

As a user exporting a resource that relies on the synthetic export feature,
I want the exported resource instance to keep the same name as the input resource instance from my configuration document,
so that the meaningful name from the input instance is kept in the export configuration.

Edit: Currently, any instances of a resource exported synthetically share the same name across the exported instances, which is invalid. For example, given the following input configuration:

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
  - name: NoExportTwo
    type: Test/Get
    properties:
      name: two
  - name: NoExportThree
    type: Test/Get
    properties:
      name: three

DSC returns the following (invalid) exported configuration document:

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json                                                                                           
contentVersion: 1.0.0
resources:
- type: Test/Get
  name: Get-0
  properties:
    name: two
    id: 2
- type: Test/Get
  name: Get-0
  properties:
    name: three
    id: 3
metadata:
  Microsoft.DSC:
    version: 3.2.0-preview.5
    operation: export
    executionType: actual
    startDatetime: 2025-09-18T15:46:53.555975200-05:00
    endDatetime: 2025-09-18T15:47:03.531802400-05:00
    duration: PT9.9758272S
    securityContext: restricted
Proposed technical implementation details (optional)

The current implementation of the add_resource_export_results_to_configuration() function doesn't have a way to pass the name of the input instance. The function currently handles either hoisting the _name property or creating a default generatedf name:

https://github.com/PowerShell/DSC/blob/3f98ff71a5bcfc4fabc801a25b7f3c8e22bc8c1e/dsc_lib/src/configure/mod.rs#L79-L90

If the add_resource_export_results_to_configuration() function included another parameter as an option, like:

pub fn add_resource_export_results_to_configuration(
    resource: &DscResource,
    conf: &mut Configuration,
    input: &str,
    instance_name: Option<&str>,
) -> Result<ExportResult, DscError> {

We could then update the code to check for instance_name and whether the resource is using synthetic export:

r.name = if let Some(name) = props.remove("_name") {
    name.as_str()
        .map(std::string::ToString::to_string)
        .ok_or_else(|| DscError::Parser(t!("configure.mod.propertyNotString", name = "_name", value = name).to_string()))?
} else if instance_name.is_some() && &resource.manifest.export.is_none() {
    instance_name.unwrap().to_string()
} else {
    let resource_type_short = if let Some(pos) = resource.type_name.find('/') {
        &resource.type_name[pos + 1..]
    } else {
        &resource.type_name
    };
    format!("{resource_type_short}-{i}")
};

This would require plumbing the change through wherever add_resource_export_results_to_configuration() is called. Otherwise, it should have minimal impact.

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 in dsc_lib/src/configure/mod.rs at add_resource_export_results_to_configuration(), then inspect its callers to trace the input instance name through synthetic exports. Confirm completion by exporting multiple instances and verifying that each output resource retains its corresponding input name instead of sharing a generated name.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.