@@ -66,10 +66,35 @@ pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf
6666 }
6767 } else {
6868 for ( i, instance) in export_result. actual_state . iter ( ) . enumerate ( ) {
69- let mut r = config_doc:: Resource :: new ( ) ;
69+ let mut r: Resource = config_doc:: Resource :: new ( ) ;
7070 r. resource_type . clone_from ( & resource. type_name ) ;
71- r. name = format ! ( "{}-{i}" , r. resource_type) ;
72- let props: Map < String , Value > = serde_json:: from_value ( instance. clone ( ) ) ?;
71+ let mut props: Map < String , Value > = serde_json:: from_value ( instance. clone ( ) ) ?;
72+ if let Some ( kind) = props. remove ( "_kind" ) {
73+ if !kind. is_string ( ) {
74+ return Err ( DscError :: Parser ( t ! ( "configure.mod.propertyNotString" , name = "_kind" , value = kind) . to_string ( ) ) ) ;
75+ }
76+ r. kind = kind. as_str ( ) . map ( std:: string:: ToString :: to_string) ;
77+ }
78+ if let Some ( security_context) = props. remove ( "_securityContext" ) {
79+ let context: SecurityContextKind = serde_json:: from_value ( security_context) ?;
80+ let metadata = Metadata {
81+ microsoft : Some (
82+ MicrosoftDscMetadata {
83+ security_context : Some ( context) ,
84+ ..Default :: default ( )
85+ }
86+ ) ,
87+ other : Map :: new ( ) ,
88+ } ;
89+ r. metadata = Some ( metadata) ;
90+ }
91+ r. name = if let Some ( name) = props. remove ( "_name" ) {
92+ name. as_str ( )
93+ . map ( std:: string:: ToString :: to_string)
94+ . ok_or_else ( || DscError :: Parser ( t ! ( "configure.mod.propertyNotString" , name = "_name" , value = name) . to_string ( ) ) ) ?
95+ } else {
96+ format ! ( "{}-{i}" , r. resource_type)
97+ } ;
7398 r. properties = escape_property_values ( & props) ?;
7499
75100 conf. resources . push ( r) ;
0 commit comments