@@ -113,6 +113,7 @@ internal static class Functions
113
113
new FunctionDescriptor ( "pickZones" , PickZones ) ,
114
114
new FunctionDescriptor ( "providers" , Providers ) ,
115
115
new FunctionDescriptor ( "reference" , Reference ) ,
116
+ new FunctionDescriptor ( "references" , References ) ,
116
117
new FunctionDescriptor ( "resourceId" , ResourceId ) ,
117
118
new FunctionDescriptor ( "subscriptionResourceId" , SubscriptionResourceId ) ,
118
119
new FunctionDescriptor ( "tenantResourceId" , TenantResourceId ) ,
@@ -1013,6 +1014,37 @@ internal static object Reference(ITemplateContext context, object[] args)
1013
1014
: full ? new Mock . MockResource ( resourceId ) : new Mock . MockResource ( resourceId ) [ "properties" ] ;
1014
1015
}
1015
1016
1017
+ /// <summary>
1018
+ /// references(symbolic name of a resource collection, ['Full', 'Properties'])
1019
+ /// </summary>
1020
+ /// <remarks>
1021
+ /// See <seealso href="https://learn.microsoft.com/azure/azure-resource-manager/templates/template-functions-resource#references"/>.
1022
+ /// </remarks>
1023
+ internal static object References ( ITemplateContext context , object [ ] args )
1024
+ {
1025
+ var argCount = CountArgs ( args ) ;
1026
+ if ( argCount is < 1 or > 2 )
1027
+ throw ArgumentsOutOfRange ( nameof ( References ) , args ) ;
1028
+
1029
+ string fullValue = null ;
1030
+ var full = argCount == 2 && ExpressionHelpers . TryString ( args [ 1 ] , out fullValue ) && string . Equals ( fullValue , PROPERTY_FULL , StringComparison . OrdinalIgnoreCase ) ;
1031
+ if ( argCount == 2 && ! full && ! string . Equals ( fullValue , PROPERTY_PROPERTIES , StringComparison . OrdinalIgnoreCase ) )
1032
+ throw ArgumentFormatInvalid ( nameof ( References ) ) ;
1033
+
1034
+ // Get symbolic name
1035
+ if ( ! ExpressionHelpers . TryString ( args [ 0 ] , out var symbolicName ) )
1036
+ throw ArgumentFormatInvalid ( nameof ( References ) ) ;
1037
+
1038
+ if ( ! context . TryGetResourceCollection ( symbolicName , out var resources ) )
1039
+ throw ArgumentInvalidResourceCollection ( nameof ( References ) , symbolicName ) ;
1040
+
1041
+ var result = new object [ resources . Length ] ;
1042
+ for ( var i = 0 ; i < resources . Length ; i ++ )
1043
+ result [ i ] = GetReferenceResult ( resources [ i ] , full ) ;
1044
+
1045
+ return result ;
1046
+ }
1047
+
1016
1048
private static object GetReferenceResult ( IResourceValue resource , bool full )
1017
1049
{
1018
1050
if ( resource is DeploymentValue deployment )
@@ -2481,6 +2513,11 @@ private static ExpressionArgumentException ArgumentNullNotExpected(string expres
2481
2513
) ;
2482
2514
}
2483
2515
2516
+ private static Exception ArgumentInvalidResourceCollection ( string v , string symbolicName )
2517
+ {
2518
+ throw new NotImplementedException ( ) ;
2519
+ }
2520
+
2484
2521
#endregion Exceptions
2485
2522
}
2486
2523
}
0 commit comments