Skip to content

Conversation

anmenaga
Copy link

@anmenaga anmenaga commented Feb 6, 2024

PR Summary

Fix #183

2 updates:

  1. Adds Export support for provider-based resources.
    It is done using export node in *.dsc.resource.json file similar to get/set/test.
  2. Adds Export support to class-based PS resources.
    To support this a DscResource class has to implement a static Export function like so:
using namespace System.Collections.Generic

[DscResource()]
class TestClassResource
{
# omitting properties and Get,Set,Test methods here

    static [TestClassResource[]] Export()
    {
        $resultList = [List[TestClassResource]]::new()
        1..5 | %{
            $obj = New-Object TestClassResource
            $obj.Name = "Object$_"
            $obj.Prop1 = "Property of object$_"
            $resultList.Add($obj)
        }
        
        return $resultList.ToArray()
    }
}

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

Fix build issues. This design will allow class based resources implementing export to still work with DSC v2, right? v2 should just ignore the new export method? Ideally we should have a test to ensure we aren't breaking compat.

@anmenaga
Copy link
Author

anmenaga commented Feb 6, 2024

This design will allow class based resources implementing export to still work with DSC v2, right?

Yes.

v2 should just ignore the new export method?

Correct.

Ideally we should have a test to ensure we aren't breaking compat.

We already test that implicitly. We are using v2 throughout PowerShellGroup resource tests.

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.

Export support for provider-based resources

2 participants