https://pulumi.com logo
#general
Title
# general
w

white-cat-90296

08/25/2021, 4:49 PM
Hi there! Is there a way of passing a callback to the Pulumi script to execute after it creates the resources? For example
Copy code
// Create an Azure resource (Storage Account)
const storageAccount = new storage.StorageAccount('sa', {
  resourceGroupName: resourceGroup.name,
  sku: {
    name: storage.SkuName.Standard_LRS,
  },
  kind: storage.Kind.StorageV2,
});

// Export the primary key of the Storage Account
const storageAccountKeys = pulumi
  .all([resourceGroup.name, storageAccount.name])
  .apply(([resourceGroupName, accountName]) =>
    storage.listStorageAccountKeys({ resourceGroupName, accountName })
  );
export const primaryStorageKey = storageAccountKeys.keys[0].value;

// MAYBE A FUNCTION HERE TO BE EXECUTED AFTER SA IS CREATED/MODIFIED
const callback = () => { axios.get(`<http://mycustomserver.com/blabla/${> primaryStorageKey }`) }
c

cool-egg-852

08/25/2021, 4:50 PM
What’s the problem with the code as it is? Pulumi should be waiting for the sa to be created because you are referencing it in
pulumi.all
.
w

white-cat-90296

08/25/2021, 4:52 PM
Hey @cool-egg-852 thanks for the quick reply. I pressed enter too soon - edited the post now. So
pulumi.all
is the callback I am looking for then?
c

cool-egg-852

08/25/2021, 4:53 PM
With your edit I can see what you are looking for, and I think there is a very hacky way to do it, but nothing native if I recall.
đź‘€ 1
I think https://github.com/pulumi/examples/tree/master/aws-ts-ec2-provisioners may be what you are looking for, but someone else may have a much better answer.
w

white-cat-90296

08/25/2021, 4:56 PM
Thanks for the input, I appreciate it
b

bored-oyster-3147

08/25/2021, 5:10 PM
With automation api you can subscribe to engine events and check for actions against specific resources and take action.
If you just want to do it in your Pulumi program, you can do in your code within an apply on an output from the storage account (which tells it to wait for the SA to be finished) and you’ll want to check for IsDryRun on the current deployment so that you aren’t taking your action during Pulumi preview
w

white-cat-90296

08/25/2021, 6:03 PM
Hey @bored-oyster-3147, that is exactly the problem I was currently facing. Also when you use
pulumi up
locally you have the option to cancel the update. The
apply
function executes regardless. Can you elaborate on checking for IsDryRun on the current deployment? Where is that value value be listened to?
b

bored-oyster-3147

08/25/2021, 6:06 PM
I'm assuming you're using typescript? This is the
IsDryRun
function: https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/runtime/#isDryRun It's in the
pulumi.runtime
module
w

white-cat-90296

08/25/2021, 6:07 PM
ah gotcha, so I can just use
pulumi.runtime.isDryRun()
to decide
thanks a lot Joshua! I appreciate the help
3 Views