sparse-intern-71089
10/29/2019, 7:06 PMwhite-balloon-205
nsg.rules
here?white-balloon-205
function getRuleByName(name: string) {
return pulumi.all(nsg.rules.map(r => r.rule.name)).apply(ruleNames => {
return ruleNames.find(ruleName => name === ruleName);
});
}
rapid-ram-37207
10/30/2019, 9:48 AMnsg.rules
is of type NetworkSecurityRule[]
, NetworkSecurityRule
being a custom ComponentResource and has a rule
property of type azure.network.NetworkSecurityRule
.rapid-ram-37207
10/30/2019, 10:20 AMrapid-ram-37207
11/01/2019, 9:40 AMtall-librarian-49374
11/01/2019, 2:34 PMtall-librarian-49374
11/01/2019, 2:35 PMapply
and all
tall-librarian-49374
11/01/2019, 2:37 PMrapid-ram-37207
11/02/2019, 11:24 AMPromise()
is just to unwrap the underlying object from the output, as explained in this article :
https://www.pulumi.com/blog/unit-testing-infrastructure-in-nodejs-and-mocha/
As per your suggestion, i modified getRuleByName
like so :
function getRuleByName(name: string) {
return pulumi.all(nsg.rules.apply(r => {
return r.find(r => r.rule.name === name)
})
}
But then I get the error :
Property 'apply' does not exist on type 'NetworkSecurityRule[]'.
NetworkSecurityRule
is a custom ComponentResource which contains an azure.network.NetworkSecurityRule.
tall-librarian-49374
11/02/2019, 11:35 AMreturn pulumi.all(nsg.rules).apply(r => ...
rapid-ram-37207
11/02/2019, 12:43 PMfunction getRuleByName(name: string) {
return pulumi.all(nsg.rules).apply(r => {
return r.find(r => r.rule.name === name)
})
}
Results in the following error for the test in the find method:
This condition will always return 'false' since the types 'Output<string>' and 'string' have no overlap
rapid-ram-37207
11/02/2019, 12:58 PMfunction getRuleByName(name: string) {
return pulumi.all(nsg.rules).apply(r => {
return r.find(r => r.rule.name.get() === name)
})
}
But it result in the following error :
Error: Cannot call '.get' during update or preview.
To manipulate the value of this Output, use '.apply' instead.
tall-librarian-49374
11/02/2019, 9:10 PMfunction getRuleByName(name: string) {
return pulumi.all(nsg.rules.map(r => r.name)).apply(names => {
const index = names.indexOf(name);
return index >= 0 ? nsg.rules[index] : undefined;
});
}
rapid-ram-37207
11/03/2019, 2:13 PMtall-librarian-49374
11/03/2019, 2:24 PM