sparse-intern-71089
02/11/2021, 3:59 PMbored-oyster-3147
02/11/2021, 4:31 PMshared-files-bucket
. If that bucket is a child resource of a ComponentResource
that I implemented than I prefix it with the name provided to that component resource. So then it would be {name}-shared-files-bucket
. This would remain unique as long as the name of the component resource is unique, which is already a constraint.
If you are creating servers, presumably each server has a purpose. Presumably each security group is created for a reason. Presumably each rule has a specific function. I don't think you should be "generating" names because you know what you are using the resource for at the time that you are writing the IaCincalculable-dream-27508
02/11/2021, 5:33 PMlb-{1..5}
and 20 app servers app-{1..20}
. You create security groups, to allow access to say port 80 on each of app
servers. Then you create security rules, one per each IP of loadbalancer. And each of those rules needs to have a unique name.incalculable-dream-27508
02/11/2021, 5:34 PMincalculable-dream-27508
02/11/2021, 5:36 PMbored-oyster-3147
02/11/2021, 5:36 PMbored-oyster-3147
02/11/2021, 5:37 PMapp-1
and app-1-sec-grp
and app-1-sec-grp-rule-lb-1
etcincalculable-dream-27508
02/11/2021, 5:37 PMbored-oyster-3147
02/11/2021, 5:37 PMbored-oyster-3147
02/11/2021, 5:38 PMincalculable-dream-27508
02/11/2021, 5:39 PMincalculable-dream-27508
02/11/2021, 5:42 PMapi
, clientA
and clientB
, in two regions, and I need all 6 IPs to be able to reach the API port on both api.region1
and api.region2
bored-oyster-3147
02/11/2021, 5:47 PMapi.region1
needs to know the IP address for api.region2
but api.region2
hasn't been deployed yet so you don't know the IP?bored-oyster-3147
02/11/2021, 5:48 PMambitious-father-68746
02/11/2021, 6:02 PMbored-oyster-3147
02/11/2021, 6:07 PMbored-oyster-3147
02/11/2021, 6:13 PMAnd I don't think lovingly handcrafting a name for each SecurityGroupRule in every SecurityGroup for each of the source IPs is the way to go. Especially since you'll need to lovingly handcraft them again when you change the number of sources.I missed this bit but you wouldn't need to change the names if you are declaring your resources in a loop. You would just need to change how many times the loop should iterate Like your component resource doesn't need 5 load balancer IP inputs, it could iterate on a list of them and when the number of sources changes the pulumi resources (and their names) will reflect that
incalculable-dream-27508
02/11/2021, 6:29 PM.apply
does manage to get the IPs out at execution time, so that part is working. But it requires unique names for each of the SecurityGroupRules, and for those you cannot use properties of defined objects (since using names was the obvious thing to try)incalculable-dream-27508
02/11/2021, 6:30 PMincalculable-dream-27508
02/11/2021, 6:31 PMbored-oyster-3147
02/11/2021, 6:42 PMfor (int i =0; i < 6; i++) // the number of IPs
{
var ipAddress = ipAddresses.GetAt(i);
var securityGroup = new SecurityGroup("{name}-sec-grp-{i}", {...});
var securityGroupRule = new Rule("{name}-sec-grp-rule-{i}", {...});
}
now obviously it sucks that you can't do ipAddresses.Length
in order to limit the loop to how many IP addresses you have programmatically, since OutputList<T>.Length()
can't be used there - but when the number of IP addresses you have changes it is still better to have to simply change that number than to mess with large blocks of duplicate code.incalculable-dream-27508
02/11/2021, 6:52 PMCOUNTER=0
before I create everything, increment it after creating each resource, and use it in the names. But then when more machines appear, suddenly the numbers in names don't match, and pulumi is convinced it needs to change the IPs in the rules for stuff to match. And for example OpenStack really doesn't like you trying to create two exactly same rules as it adjusts things, throwing an error and thus erroring out pulumi run.bored-oyster-3147
02/11/2021, 6:54 PMbored-oyster-3147
02/11/2021, 6:55 PMincalculable-dream-27508
02/11/2021, 6:59 PMapi
and clientA
, but now turned out I also need clientB
in each region.bored-oyster-3147
02/11/2021, 7:01 PMincalculable-dream-27508
02/11/2021, 7:02 PMbored-oyster-3147
02/11/2021, 7:03 PMvar sortedIpAddresses = ipAddresses.Apply(x => x.Sort());
that way ordering was preserved?bored-oyster-3147
02/11/2021, 7:03 PMincalculable-dream-27508
02/11/2021, 7:03 PMbored-oyster-3147
02/11/2021, 7:11 PMincalculable-dream-27508
02/11/2021, 7:14 PMincalculable-dream-27508
02/11/2021, 7:17 PMbored-oyster-3147
02/11/2021, 7:19 PMDeleteBeforeReplace
help with that?incalculable-dream-27508
02/11/2021, 7:20 PMbored-oyster-3147
02/11/2021, 7:22 PMbored-oyster-3147
02/11/2021, 7:24 PM{name}-{number-of-ips}
and then when the number of IPs changes, That component can be destroyed in it's entirety (all rules) before it is created againbored-oyster-3147
02/11/2021, 7:29 PMincalculable-dream-27508
02/11/2021, 7:44 PM