early-plastic-49211
11/11/2022, 1:37 PMx.Apply(x => $"https://{x}")
). Right now, to do this, I do something like the following, but it feels wrong. Is there a better way to do that?
Input<string> variableToResolve; // Just to show you the type, let's assume there's a value
_ = variableToResolve.Apply(x =>
{
methodRequiringValueAsString(x);
return true; // This feels hacky
});
Also, let's say I wanted to verify what the value of x
is, would it be valid to throw an exception inside the Apply block?echoing-dinner-19531
11/11/2022, 4:07 PMoutputX = outputX.Apply(x => validateX(x); return x)
Such that anything using this value will only see it if it's been validated.early-plastic-49211
11/11/2022, 4:19 PM_ = args.Tags.Apply(t =>
{
if (t["tier"] == "prod")
{
Common.ValidateTags(t);
}
return true;
});
Where an exception is thrown if the validation fails.
Another use case that feels hacky is if I have to wait for a resource to be created, I literally discard the value:
_ = privateZone.Id.Apply(_ =>
{
CreatePrivateEndpoint();
return true;
});
Inside CreatePrivateEndpoint, I use "GetPrivateZone" which uses parameters from another part of the code (which doesn't use Inputs). This is to make the method more flexible (it supports private zones created from Pulumi and from the web console).echoing-dinner-19531
11/11/2022, 4:32 PMargs.Tags = args.Tags.Apply(t =>
{
if (t["tier"] == "prod")
{
Common.ValidateTags(t);
}
return t;
});
?
The second one, you might want to look at the dependsOn resource option. Lets you delay the creation of other resources until one has resolved.early-plastic-49211
11/11/2022, 4:34 PM