-
Notifications
You must be signed in to change notification settings - Fork 173
Open
Description
I didn't find documentation about this:
What is the best practice to work with conditional values in Farmer custom builders?
For example, the VM IP ARM (PublicIpId) is an Option type:
let deployment = arm {
location Location.UKSouth
// more resources here
add_resource myVm
output "vmIP" myVm.PublicIpId.Value.ArmExpression
}The code fails if PublicIpId is None.
When the deployments and resources are compex, I wouldn't want to create multiple copies of the same builders.
I'd like to do something like:
let deployment = arm {
location Location.UKSouth
// more resources here
add_resource myVm
match myVm.PublicIpId with
| Some ip -> output "vmIP" ip.ArmExpression
| None -> ()
}
// or
let deployment = arm {
location Location.UKSouth
// more resources here
add_resource myVm
if myVm.PublicIpId.IsSome then
output "vmIP" myVm.PublicIpId.Value.ArmExpression
}This control construct may only be used if the computation expression builder defines a 'For' method.
Or could I use composition and still take the advantage of the builder?
Currently I've only find a solution to jump out of the builder and start to build manually the state, losing the convenience of builder with proper type-conversions in overloaded methods:
let composition =
match myVm.PublicIpId with
| None -> deployment
| Some ip -> { deployment with Outputs = deployment.Outputs.Add("vmIP", ip.ArmExpression.Eval()) }
davidglassborowCopilot
Metadata
Metadata
Assignees
Labels
No labels