https://pulumi.com logo
Title
a

ambitious-father-68746

06/30/2021, 2:38 PM
Hi, I currently need to create a set of resources conditionally based on some Outputs. Using
if
doesn't work because an Output is not a boolean. I've found a solution where I can shove the creation of the resource inside an
apply()
, but then I can't refer to that resource from outside the
apply().
Any ideas?
b

billowy-army-68599

06/30/2021, 2:41 PM
we generally don't recommend this approach, can you expand on why you're doing conditional resource creation inside
apply()
?
a

ambitious-father-68746

06/30/2021, 2:43 PM
Going into a bit more detail, I need to create a DNS record, but it might either be in Azure or in AWS, depending on the result of a set of Outputs.
The
apply()
solution was more of a PoC, I don't think it will work in the long term.
But I just don't see a way of doing these conditional checks without it.
b

billowy-army-68599

06/30/2021, 2:48 PM
generally we recommend setting a config value for stuff like this
if azure {
 // create
}
a

ambitious-father-68746

06/30/2021, 2:48 PM
Unfortunately it's dynamic, so that's not an option.
The solution for this was: group the resources inside a
def
, this way they can reference each other. The
apply()
calls the function with all the necessary arguments. This works for my particular problem and actually makes it a bit more readable as well, since everything inside the function is a string.