Skip to content

Instantly share code, notes, and snippets.

@lukehoban
Last active May 19, 2023 05:31
Show Gist options
  • Save lukehoban/b5ec07deb0cbfb1b6b020500dc6d5e05 to your computer and use it in GitHub Desktop.
Save lukehoban/b5ec07deb0cbfb1b6b020500dc6d5e05 to your computer and use it in GitHub Desktop.
Pulumi without variables
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")
@lukehoban
Copy link
Author

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