Hi, I currently need to create a set of resources ...
# python
a
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
we generally don't recommend this approach, can you expand on why you're doing conditional resource creation inside
apply()
?
a
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
generally we recommend setting a config value for stuff like this
Copy code
if azure {
 // create
}
a
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.