From 6f291ff87888d92eefb87d911ac2105438a813a1 Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Tue, 5 Nov 2024 11:45:02 -0500 Subject: [PATCH] Fixes debug logging of CfnResource (#198) Before this change, logging could generate "not supported" errors in the stream. I1104 14:23:22.081768 66128 eventsink.go:59] CfnResource aws-native:ec2:SubnetRouteTableAssociation: {"routeTableId":"Calling [toJSON] on an [Output] is not supported.\n\nTo get the value of an Output as a JSON value or JSON string consider either:\n 1: o.apply(v => v.toJSON())\n 2: o.apply(v => JSON.stringify(v))\n\nSee https://www.pulumi.com/docs/concepts/inputs-outputs for more details.\nThis function may throw in a future version of @pulumi/pulumi.","subnetId":"Calling [toJSON] on an [Output] is not supported.\n\nTo get the value of an Output as a JSON value or JSON string consider either:\n 1: o.apply(v => v.toJSON())\n 2: o.apply(v => JSON.stringify(v))\n\nSee https://www.pulumi.com/docs/concepts/inputs-outputs for more details.\nThis function may throw in a future version of @pulumi/pulumi."}, ["awsId","routeTableId","subnetId"] After the change, debug logging should happen only after the outputs are resolved. There is a slight downside for unknowns - debug logging will not happen when some of the properties are unknown anymore, because this will make `pulumi.output(x)` unknown and will not call `debug` in `apply`. Note also that running programs under PULUMI_DEBUG_GRPC="$PWD/log.json" environment variable should also make it possible to observe how the underlying resources are constructed in terms of calls to the backing provider, including observing unknowns. --- src/interop.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/interop.ts b/src/interop.ts index 69c9913d..452e0da3 100644 --- a/src/interop.ts +++ b/src/interop.ts @@ -94,7 +94,9 @@ export class CfnResource extends pulumi.CustomResource { ) { const resourceName = typeToken(type); - debug(`CfnResource ${resourceName}: ${JSON.stringify(properties)}, ${JSON.stringify(attributes)}`); + debug(`Constructing CfnResource ${name} of type ${resourceName} with attributes=${JSON.stringify(attributes)}`); + const propertiesDebugString = pulumi.output(properties).apply(JSON.stringify); + pulumi.interpolate`CfnResource ${name} input properties: ${propertiesDebugString}`.apply(debug); // Prepare an args bag with placeholders for output attributes. const args: any = {};