Hi everyone! How can I map an `Output<T>`, w...
# dotnet
p
Hi everyone! How can I map an
Output<T>
, where T is a string containing a comma-separated list of IP addresses, into multiple resources where each resource takes one of those IP addresses as an input? Case in point:
AppService
exposes
PossibleOutboundIpAddresses
as such an output property, and I need to transform that and create one
Sql.FirewallRule
for each IP address in that string. Of course I want to keep the chain of inputs-to-outputs intact to not break the dependency tracking etc. Anyone know how to do this?
f
I think you can convert that output string using the youtString.Split(',').ToList() So maybe like var myIpList = resource.PossibleOutboundIpAddresses.Apply(x=>x.Split(',').ToList()) Then you can loop over that ip list to add firewall rules.
p
Don’t think that works @fast-dinner-32080. The Apply() function creates an Output, its values will be unknown at the time the Pulumi program is executed.
f
Ah this is prior
p
Besides that, Yes, Pulumi would have no notion of the dependency between the output property and the resources I created in the loop…
But I think I have come up with something, maybe.
Here’s what I came up with now:
Copy code
appService.PossibleOutboundIpAddresses.Apply(x =>
{
	var ipAddresses = x.Split(',').ToList();

	foreach (var ipAddress in ipAddresses)
	{
		var index = ipAddresses.IndexOf(ipAddress);
		var sqlFirewallRule = new FirewallRule(
			$"idl-licensing-{stackName}-sqlFirewallRule{index:D2}",
			new FirewallRuleArgs()
			{
				Name = Output.Format($"{appService.Name}-{index:D2}"),
				ResourceGroupName = resourceGroup.Name,
				ServerName = sqlServer.Name,
				StartIpAddress = ipAddress,
				EndIpAddress = ipAddress
			});
	}

	return Output.Create(false); // Not used for anything...
});
It does work, but I think it won’t work for preview.
t
p
@tall-librarian-49374 🙂 almost identical to what I did. Is it a correct assumption that this won’t preview correctly?
t
I haven’t tried this in anywhere recent CLI versions, but it might not indeed. Overall, this solution is not ideal, but seems required in this case, as the quantity of resources isn’t known in advance.
Ideally, it could be a single resource accepting a list of IPs (modelling issue again)
p
The bastards didn’t model their clouds with Pulumi in mind. 😉
😀 1