in BenchPress/Generators/AzureDeploymentImporter.cs [150:214]
private static Dictionary<string, string> GetExtraProperties(
JsonNode resource,
JsonObject armTemplateObject
)
{
var extraProperties = new Dictionary<string, string>();
var dependencies = (JsonArray?)resource[s_dependsOnKey];
if (dependencies != null)
{
foreach (var dependency in dependencies)
{
if (dependency != null)
{
// There is only one Capture value for the Group, which is the entire list of parameters that are
// passed to "[resourceId()]" as a single string. After the split, the first parameter in
// resourceIdParameters will be the path (e.g., "'Microsoft.xxx/yyy/zzz'"), and all further entries
// will be values for the path (e.g., "parameters('yyy')", "variables('zzz')").
var resourceIdParameters = s_resourceIdParametersRegex
.Match(dependency.ToString())
.Groups[s_resourceIdParametersKey].Captures[0].Value.Split(
',',
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries
);
// The number of entries in resourceIdParameters must be 2 or more, otherwise it's not valid.
if (resourceIdParameters.Length > 1)
{
// The first element is the path, so remove the leading/trailing single quotes from
// "'Microsft.xxx/yyy/zzz'", then split on the path separator: ["Microsoft.xxx", "yyy", "zzz"],
// and finally, remove the leading "Microsoft.xxx" by skipping (1).
var pathParts = resourceIdParameters[0]
.Trim('\'')
.Split('/')
.Skip(1)
.ToList();
// There should be one more Resource ID Parameter than path parts, otherwise it is not valid.
if (pathParts.Count() == (resourceIdParameters.Count() - 1))
{
// Skip the path parameter, counts and indexes match now.
var values = resourceIdParameters.Skip(1).ToList();
for (int index = 0; index < pathParts.Count(); index++)
{
// If the value is a "parameter" or "variable", then resolve it to the correct value
// of the parameter or variable. If the value is a hard coded value, then the
// value will be "'value'" so trim any single quotes.
var value = ResolveParamsAndVariables(
values[index],
armTemplateObject
)
.Trim('\'');
extraProperties.Add(pathParts[index], value);
}
}
}
}
}
}
extraProperties.Add("resourceGroup", "FAKE-RESOURCE-GROUP");
return extraProperties;
}