Skip to content

Instantly share code, notes, and snippets.

@1oglop1
Last active July 12, 2021 23:37
Show Gist options
  • Save 1oglop1/c563f25b317ecd6149e5465bd9eea597 to your computer and use it in GitHub Desktop.
Save 1oglop1/c563f25b317ecd6149e5465bd9eea597 to your computer and use it in GitHub Desktop.
Pulumi component resources
import pulumi
from pulumi_aws import s3
from pulumi import Output, Input, ResourceOptions, ComponentResource, set, get
import time
import json
from pydantic import BaseModel
async def w2():
"""Awaitable simulating output"""
print("waiting")
time.sleep(2)
return "222222"
class FirstComponent(ComponentResource):
"""First component."""
def __init__(
self,
name: str,
):
super().__init__(
"custom:first",
name,
None,
opts=ResourceOptions(additional_secret_outputs=['password']),
)
# setting a property here
self.o1 = Output.from_input(w2())
self.register_outputs(
{
"w2": self.o1,
"password": self.o1.apply(lambda x: x)
}
)
class SecondComponent(ComponentResource):
"""Second component."""
def __init__(
self,
name: str,
password: Input[str]
):
super().__init__(
"custom:second",
name,
None,
opts=ResourceOptions(additional_secret_outputs=['password']),
)
self.password = password
self.register_outputs(
{
"password": self.password
}
)
first_component = FirstComponent(name='first')
print(first_component.o1)
first_component.o1.apply(print)
second_component = SecondComponent(name='second', password='Secret')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment