sparse-intern-71089
07/29/2021, 7:28 AMenough-garden-22763
07/29/2021, 2:28 PMenough-garden-22763
07/29/2021, 2:28 PMcert: acm.Certificate
cert.domain_validation_options: Output[Sequence[CertificateDomainValidationOption]]
cert.domain_validation_options.apply(lambda x: x[0]): Output[CertificateDomainValidationOption]
domain_name = cert.domain_validation_options.apply(lambda x: x[0]).apply(lambda x: x.domain_name)
domain_name: Output[str]
enough-garden-22763
07/29/2021, 2:29 PMInput[str]
you can now pass domain_name: Output[str]
into it as Input arguments accept Output.enough-garden-22763
07/29/2021, 2:30 PMgreat-sunset-355
07/29/2021, 3:01 PMlambda x: x[0]).apply(lambda x: x.domain_name)
that my IDEs are not able to suggest the attributes of x
which is ultimately what I'm trying to achieve.
It's the lost information that bothers meenough-garden-22763
07/29/2021, 3:05 PMenough-garden-22763
07/29/2021, 3:05 PMenough-garden-22763
07/29/2021, 3:06 PMgreat-sunset-355
07/29/2021, 3:06 PMenough-garden-22763
07/29/2021, 3:08 PMenough-garden-22763
07/29/2021, 3:09 PMgreat-sunset-355
07/29/2021, 3:09 PMgreat-sunset-355
07/29/2021, 3:11 PMpulumi.Output
because they can also return a dict but it is not a dict but Output[dict]
enough-garden-22763
07/29/2021, 3:15 PMgreat-sunset-355
07/29/2021, 3:15 PMOutput.future()
and await
inside an async function then scheduling the function with loop.create_task
However due to my limited experience with python async I'm not able to tell if there are any potential side effects.
It seems to be a similar case to Output.apply()
- where documentation recommends to avoid creating resources inside apply()
import pulumi
from pydantic import BaseModel
class MyZone(BaseModel):
zone_id: str
force_destroy: bool
async def fun():
ref_zone = pulumi.StackReference(stack_name)
print('lol')
result = await ref_zone.outputs.future()
print(result)
my_zone = MyZone.parse_obj(result['my_zone'])
print(my_zone)
ec2.SecurityGroup(
f"mhh{my_zone.zone_id}"
)
loop = asyncio.get_running_loop()
loop.create_task(fun())
enough-garden-22763
07/29/2021, 3:18 PMenough-garden-22763
07/29/2021, 3:18 PMOutput[MyZone]
in the code above I think?enough-garden-22763
07/29/2021, 3:19 PMref_zone.outputs.apply(lambda result: MyZone.parse_obj(result['my_zone'])): Output[MyZone]
enough-garden-22763
07/29/2021, 3:27 PMname
parameter of SecurityGroup though, that’s true. I’ll need to ask what is the recommended practice around this.enough-garden-22763
07/29/2021, 3:27 PMasync def main():
print('Hello ...')
await asyncio.sleep(1)
print('... World!')
# Python 3.7+
asyncio.run(main())
enough-garden-22763
07/29/2021, 3:28 PMenough-garden-22763
07/29/2021, 3:29 PMenough-garden-22763
07/29/2021, 3:34 PMenough-garden-22763
07/29/2021, 3:34 PM# ec2
class SecurityGroup(pulumi.CustomResource):
@overload
def __init__(__self__,
resource_name: str,
...
name: Optional[pulumi.Input[str]] = None,
...
__props__=None):
"""
# BUILT BY genResourceInitDocstring()
:param str resource_name: The name of the resource. ### this is the name as Pulumi sees it
...
:param pulumi.Input[str] name: Name of the security group. If omitted, this provider will assign a random, unique name. ### this is actual name in AWS
"""
...
great-sunset-355
07/29/2021, 3:36 PMasyncio.run
gave me error about multiple loops but will have to revisit the test later ongreat-sunset-355
07/29/2021, 3:36 PMenough-garden-22763
07/29/2021, 3:37 PMenough-garden-22763
07/29/2021, 3:37 PMmy_zone: Output[MyZone] = ref_zone.outputs.apply(lambda result: MyZone.parse_obj(result['my_zone']))
sg = SecurityGroup(
"mhh", # pulumi name does not depend on my_zone
resource_name=my_zone.apply(lambda z: f"mhh{z.zone_id}") # but AWS name does
)
enough-garden-22763
07/29/2021, 3:38 PMgreat-sunset-355
07/29/2021, 4:38 PMz.
has the attribute of z.zone_id
I'll try the similar example in C# to see if the IDE experience is somewhat different there then I'll think if there is something like that of python typhintinggreat-sunset-355
07/29/2021, 4:40 PMList[str]
you get hinted methods from that list_items[0].join()
if we could get the same experience for Output in python that would be amazing