I thought I'd come up with something really clever...
# typescript
l
I thought I'd come up with something really clever to help type props when doing transforms:
Copy code
export function isTransformType<T extends new (...args: any[]) => CustomResource>(args: ResourceTransformArgs, resource: T): args is TypedResourceTransformArgs<ConstructorParameters<T>[2]> {
  return '__pulumiType' in resource && args.type === resource.__pulumiType
}
but of course,
__pulumiType
is marked as
@internal
so it doesn't work. Is there a way to get the actual pulumi type from an arbitrary resource class, or do I have to pass the type string myself like a scrub?
e
Yeh we should just expose type (and name for that matter) on the base resource type. I think we could then ensure it's also filled in for remote resource references (for example transforms running on resources defined by a remote component)
l
Would love to see that.
transforms
doesn't even pass the resource instance either so you can't do anything clever with the
.is()
sad panda (Went to upvote the issue - apparently I already had heh)
tranaformations
my beloved
e
l
It does, but you have to hardcode the comparison it to the type you want - you can't check if it matches the
__pulumiType
of a class (well you can, it works at runtime, but doesn't work for type-checking)
e
Ah right yeh, yeh we should just expose type tokens on resources. And static type tokens for the known resource types.
l
Yeah, that's what I was lamenting 😁
Side note, is there a better way to figure out what type token a resource has so you can write that comparison? afaik it's not listed on the docs pages, so you either need to go schema-diving or breakpoint in the transform and step through all of the resources
e
If you look at the import section in the docs it happens to have the type token: https://www.pulumi.com/registry/packages/aws/api-docs/acm/certificate/#import
Copy code
pulumi import aws:acm/certificate:Certificate cert arn:aws:acm:eu-central-1:123456789012:certificate/7e7a28d2-163f-4b8f-b9cd-822f96c08d6a
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
l
ooh that works, nice one, thanks