DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Support for "FriendlyName" in existing resources

Open mgreenegit opened this issue 2 years ago • 5 comments

Summary of the new feature / enhancement

Since it is common practice to use the friendly name in most configuration files, we could support it as an alternative to "type". That would require caching friendly names and accepting the match as a second option, in locations such as here. https://github.com/PowerShell/DSC/blob/6652dc3847df2ec4b1f9a35a7c9877780b2726f2/powershellgroup/powershellgroup.resource.ps1#L122

This would not mean that we should support friendly name without module name. That is technically possible but might be risky, so we should wait for feedback. However, we could safely support friendly name as long as module name is also required.

Proposed technical implementation details (optional)

No response

mgreenegit avatar Oct 18 '23 15:10 mgreenegit

@mgreenegit Can you show a comparison of using the friendly name vs the type name in a configuration document?

michaeltlombardi avatar Oct 18 '23 18:10 michaeltlombardi

type name:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: PowerShell resources
  type: DSC/PowerShellGroup
  properties:
    resources:
    - name: BITS service
      type: PSDscResources/MSFT_ServiceResource
      properties:
        Name: bits
        State: Running

friendly name:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: PowerShell resources
  type: DSC/PowerShellGroup
  properties:
    resources:
    - name: BITS service
      type: PSDscResources/Service
      properties:
        Name: bits
        State: Running

mgreenegit avatar Oct 18 '23 20:10 mgreenegit

This is specific to MOF-based resources, I think? I wonder if that can be more automatically handled by the provider (DSC/PowerShellGroup) since dsc itself doesn't process the resource list inside the provider:

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
resources:
- name: PowerShell resources
  type: DSC/PowerShellGroup
  properties:
    # The provider is responsible for everything in this object
    resources:
    - name: BITS service
      type: PSDscResources/Service
      properties:
        Name: bits
        State: Running

michaeltlombardi avatar Oct 19 '23 19:10 michaeltlombardi

That is right. We could just return the friendly name instead of the type, for script based resources, if user find that easier.

mgreenegit avatar Oct 19 '23 20:10 mgreenegit

Agree that it may be better to have that behavior in PowerShellGroup resource where it can take either the friendly name or type name. The only question is the risk of collision. Seems like if there's two PS resources that have the same friendly name, it should error to make it more predictable.

SteveL-MSFT avatar Oct 23 '23 15:10 SteveL-MSFT