Last active
May 19, 2023 05:31
-
-
Save lukehoban/b5ec07deb0cbfb1b6b020500dc6d5e05 to your computer and use it in GitHub Desktop.
Pulumi without variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pulumi | |
import pulumi_aws as aws | |
from typing import Optional, Dict, Tuple | |
import asyncio | |
all_resources: Dict[Tuple[str, str], pulumi.Resource] = {} | |
def transform(args: pulumi.ResourceTransformationArgs) -> Optional[pulumi.ResourceTransformationResult]: | |
all_resources[(args.name, args.type_)] = args.resource | |
return None # do not actually modify the resource | |
pulumi.runtime.register_stack_transformation(transform) | |
async def get_resource(type: str, name: str, prop: str): | |
while True: | |
res = all_resources.get((name, type)) | |
if res is not None: | |
return res.__dict__[prop] | |
await asyncio.sleep(1000) | |
# User code | |
# ------------------------------------------------------------------------------- | |
aws.s3.BucketObject("o", bucket=get_resource("aws:s3/bucket:Bucket", "b", "id")) | |
aws.s3.Bucket("b") |
There are docs on transformations and specifically stack transformations used here at https://www.pulumi.com/docs/concepts/options/transformations/#stack-transformations.
This is a slight abuse of that feature, since we aren’t actually using it to transform the resource. But it’s a tool that is available today that can enable intercepting all resource construction calls.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you for this! If I want to understand a bit more about what's going on under the hood there (specifically
pulumi.runtime
and what a transformation does and why we needdef transform
), where would I go?I am struggling to find documentation on
pulumi.runtime
. I was able to find https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/runtime/#registerStackTransformation ... but (a) this is a NodeJS-specific doc and (b) even the NodeJs doc is short on concepts and explanation.