Hello all, I am looking for a solution to wait unt...
# automation-api
c
Hello all, I am looking for a solution to wait until a resource is created to run an additional script. (python, azure-native)
g
Can’t say if this is a good fit without knowing what sort of resource, but we do something possibly similar when we create databases. There were inject a secret with the connection string into k8s, which we can then depend on. When the secret is created, the db is sure to be ready.
c
in my case i need to wait for a disk encryption set. how did you solve it?
g
I’m not sure how I would block on something like that, I’m afraid.
c
i can build try/catch around it and retry until it is successful, but this seems like a “dirty” solution to me
what is your approach with your database?
g
We create the database, and some users for it, and inject credentials for those users into a k8s secret. The application that depends on the database can then wait for the secret to be created.
c
sounds similar to what i am trying to achive. how do you wait until the database is created?
g
Do you mean how to wait for the database being created, before creating the secret? Since the secret, which is created by pulumi as well, depends on output variables from the database creation, that is handled implicitly.
Any time you use an output variable from one resource as an input variable in the creation of another resource, pulumi is aware of the dependency between those resources
In that sense, you could also use pulumi to create a k8s job, and express the dependency between the resource you’re creating and the job. You might have to do that manually, using
DependsOn
, unless there’s an actual output variable you would use as input. Any other way of running a script, such as creating a VM, should also work for this. https://www.pulumi.com/docs/intro/concepts/resources/options/dependson/
c
ah, okay. in your case depends on is the way to go.
g
c
yes, exactly
g
I would think that some other resource can depend on this using DependsOn just as well as any other resource in pulumi
c
my root issue is, that i have to grant this encryption set access on an key vault that is unfortunately not managed by pulumi and the automation api does not yet support importing resources, only the pulumi cli
b
@clever-hair-26722 anything that happens inside an
apply
block happens after the outputs for that resource have resolved. So if you want to do something when a resource is created:
Copy code
myresource.output..apply(
           lambda variable: // do somehting here
        )
👍 1
c
nice.. i will try that. thank you for the hint! 🙂