Really hacky... in the stack performing the outpu...
# azure
w
Really hacky... in the stack performing the output...
Copy code
protected readonly ImmutableDictionary<string, object>.Builder OutputBuilder = ImmutableDictionary.CreateBuilder<string, object>();

    OutputBuilder.Add(location, Output.Create(ImmutableDictionary.CreateBuilder<string, object>()
       .Append(new KeyValuePair<string, object>("GatewayUrl", apim.GatewayUrl))
       .Append(new KeyValuePair<string, object>("ResourceGroup", resourceGroup.Name))
       .Append(new KeyValuePair<string, object>("ServiceName", apim.Name))
       .ToImmutableDictionary()));
then to consume it...
Copy code
public static class OutputExtensions
    {
        public static Output<string> RequireSubDictionaryOutput(this StackReference stackReference, string outputName, string mainKey, string subKey)
        {
            return stackReference.RequireOutput(outputName).Apply<string>(_ => {
                var mainArray = (ImmutableDictionary<string, object>)((ImmutableDictionary<string, object>)_)[mainKey];
                return mainArray[subKey]?.ToString() ?? "";
            });
        }
    }
Then used:
Copy code
var apimResourceGroup = sharedStack.RequireSubDictionaryOutput("Gateways", location, "ResourceGroup");
                var apimServiceName = sharedStack.RequireSubDictionaryOutput("Gateways", location, "ServiceName");
Like I said... very hacky... The usecase is that the "shared" stack outputs multiple API-Management services, one for each region, then the service stacks need to add themselves to each of the regions. That requires them to know the RG and ServiceName of them.