https://pulumi.com logo
#dotnet
Title
# dotnet
p

powerful-football-81694

01/15/2020, 6:26 PM
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

fast-dinner-32080

01/15/2020, 7:20 PM
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

powerful-football-81694

01/15/2020, 7:22 PM
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

fast-dinner-32080

01/15/2020, 7:23 PM
Ah this is prior
p

powerful-football-81694

01/15/2020, 7:23 PM
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

tall-librarian-49374

01/15/2020, 7:31 PM
p

powerful-football-81694

01/15/2020, 7:33 PM
@tall-librarian-49374 🙂 almost identical to what I did. Is it a correct assumption that this won’t preview correctly?
t

tall-librarian-49374

01/15/2020, 7:35 PM
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

powerful-football-81694

01/15/2020, 7:39 PM
The bastards didn’t model their clouds with Pulumi in mind. 😉
😀 1