fancy-eve-82724
12/02/2025, 11:35 AMnumerous-book-75463
12/02/2025, 1:35 PM// Convert a pulumi.Output to a promise of the same type.
export function promiseOf<T>(output: pulumi.Output<T>): Promise<T> {
return new Promise((resolve) => output.apply(resolve));
}
const ec2Instance = new aws.ec2.Instance('instance');
const beforeHook = new pulumi.ResourceHook('before', async (_args) => {
const id = await promiseOf(ec2Instance.id);
console.log(`Instance ID: ${id}`);
});
const cmd = new command.local.Command(
'curl',
{
create: 'echo "hello"',
update: 'echo "hello again"',
triggers: [new Date()],
},
{
hooks: {
beforeCreate: [beforeHook],
beforeUpdate: [beforeHook],
},
dependsOn: [ec2Instance],
},
);echoing-dinner-19531
12/02/2025, 4:46 PMexport interface ResourceHookArgs {
/**
* The URN of the resource that triggered the hook.
*/
urn: URN;
/**
* The ID of the resource that triggered the hook.
*/
id: ID;
/**
* The name of the resource that triggered the hook.
*/
name: string;
/**
* The type of the resource that triggered the hook.
*/
type: string;
/**
* The new inputs of the resource that triggered the hook.
*/
newInputs?: Record<string, any>;
/**
* The old inputs of the resource that triggered the hook.
*/
oldInputs?: Record<string, any>;
/**
* The new outputs of the resource that triggered the hook.
*/
newOutputs?: Record<string, any>;
/**
* The old outputs of the resource that triggered the hook.
*/
oldOutputs?: Record<string, any>;
}echoing-dinner-19531
12/02/2025, 4:46 PMfancy-eve-82724
12/02/2025, 8:33 PMfancy-eve-82724
12/02/2025, 8:34 PMdef start_instance( iid_input: pulumi.Output[str], region:str, args ):
def do_start_instance( iid:str, region:str ):
ec2 = boto3.client("ec2', region_name=region)
ec2.start_instances( InstanceIds=[iid] )
iid_input.apply( lambda value, r=region: do_start_instance( value, r ) )echoing-dinner-19531
12/02/2025, 8:37 PMechoing-dinner-19531
12/02/2025, 8:38 PMdef promise_of(output: pulumi.Output):
fut = Future()
output.apply(fut.set_result)
return futfancy-eve-82724
12/02/2025, 8:39 PMechoing-dinner-19531
12/02/2025, 8:40 PMfancy-eve-82724
12/02/2025, 8:41 PMechoing-dinner-19531
12/02/2025, 8:41 PMResourceHookFunction = Callable[
[ResourceHookArgs],
Union[None, Awaitable[None]],
]echoing-dinner-19531
12/02/2025, 8:41 PMfancy-eve-82724
12/03/2025, 2:46 PM