great-sunset-355
08/03/2021, 4:56 PMoai = cloudfront.OriginAccessIdentity(
f"{PREFIX}-oai"
)
pulumi.export('origin_access_identity', oai)
stack B
ref_oai = StackReference(name="stackA").require_output('origin_access_identity')
The reference gives me the Output[dict]
with the exactly same parameters as created object in stack A
Is it possible to create an object OriginAccessIdentity
from this, without calling AWS API with OriginAccessIdentity.get()
?billowy-army-68599
08/03/2021, 5:01 PMgreat-sunset-355
08/03/2021, 5:04 PMget
does call the AWS API right?
CDK has both options to construct resource from properties or from lookup.
Did I notice correctly that awsx
may offer the same thing?billowy-army-68599
08/03/2021, 5:18 PM.get()
is what you're looking for
awsx
doesn't have any .get
objects because you'd just use the native aws providerred-match-15116
08/03/2021, 5:23 PM.get()
actually adds the resource to your stack state. So then this resource would be tracked in two different stacks? Not sure that’s what you want. get[Resource]
just does a read - which maybe is what you want?great-sunset-355
08/03/2021, 5:24 PMget_some_resource()
methodsget[Resource]
you refer to eg. this?
https://www.pulumi.com/docs/reference/pkg/aws/ec2/getsecuritygroup/
That won't work because it is not implemented for OAIred-match-15116
08/03/2021, 5:29 PM.get()
method which is on each resource. It has nothing to do with “looking up another stack”, it will find the resource and add it to your stack to start tracking it within your pulumi stack (regardless of whether it was originally deployed as part of a pulumi stack or directly in the console or any other way) https://www.pulumi.com/docs/reference/pkg/aws/cloudfront/originaccessidentity/#look-up
This is the get[Resource]
function which is only available for certain resources. It is used to look up information about a resource without adding it to your stack.
https://www.pulumi.com/docs/reference/pkg/aws/cloudfront/getdistribution/
Is it possible to create an objectI don’t really understand the premise of your question, why do you need to create the object when you have all of its outputs available to you? What good is the object to you apart from its properties which you already have available in the stackreference?from this, without calling AWS API withOriginAccessIdentity
?OriginAccessIdentity.get()
great-sunset-355
08/03/2021, 5:38 PMit will find the resource
- here my question is how and where does it look
My point here is that I do not want to pass around a StackReference
because that's not clear what it is,
I want to be able to pass OriginAccessIdentity
object.
And since this particular StackReference
contains all data about my oai I do not think it is necessary to search or look up.red-match-15116
08/03/2021, 5:52 PMMy point here is that I do not want to pass around abecause that’s not clear what it is,StackReference
I want to be able to passGot it. Unfortunately that would require deserializing your stack reference into anobject.OriginAccessIdentity
OriginAccessIdentity
resource but not tracking it as a resource in stack B. We can’t do that at this time. You can do this with the get[Resource]
functions that are available for some resources, but since this is a bridged terraform provider we do not control which resources have a get[Resource]
function.
And since this particularRight, the benefit of pulumi is that you are just writing code. So if this is something that you want and you believe it is entirely straightforward to do so, you should be able to do so within your code. You could create ancontains all data about my oai I do not think it is necessary to search or look up.StackReference
OriginAccessIdentityOutputs
data class and rehydrate it with the properties of your stack reference, or whatever else you need to do to get the end state you would like.stackB
in a way that it only requires certain properties of OriginAccessIdentity
as inputs, and I would only output those specific properties from stackA
and reference them in stackB
. But I understand it is a matter of personal preference, and if my personal preference defers from the provided constructs then I write the code to enable my preferences.great-sunset-355
08/03/2021, 6:02 PMit only requires certain properties of
- this is what I do but I'm balancing on thin ice with this feature.
mainly due to comfort
pulumi.export('reource', resource)
vs: pulumi.export('resource_property', resource.property
in case I need more than 2 properties it becomes too repetitive.
but it's pretty much dependent on the resource, so to take a shortcut I simply wanted to expose an entire resource so I do not have to maintain make so many code changes in case I need another property
Deserialising StackReference
into a dataclass is exactly what I'm doing, but Output
are what makes it difficult (you may remember our previous conversations about it)
I wonder if there is a pattern that would allow simple dictionary unpacking on Outputsred-match-15116
08/03/2021, 6:17 PMI wonder if there is a pattern that would allow simple dictionary unpacking on OutputsHmm interesting. So you basically need to have your data class accept an output[dict] and have it resolve the properties to individual outputs. Something like:
class OriginAccessIdentityOutputs:
def __init__(self, props: Output[dict]) -> None:
self.prop1 = props.apply(lambda args: args["prop1"])
self.prop2 = props.apply(lambda args: args["prop2"])
great-sunset-355
08/03/2021, 6:25 PMimport pulumi
from pydantic import BaseModel
class OriginAccessIdentity(BaseModel):
cloudfront_access_identity_path: Union[str, pulumi.Output]
iam_arn: Union[str, pulumi.Output]
I can instantiate this class like a so:
resource = StackReference.get_output('resource')
OriginAccessIdentity(prop1=resource.apply(lambda x: x['prop1']
but it is possible to instantiate a dataclass or pydantic model from dict
OriginAccessIdentity(**{"prop1":resource.apply(lambda x: x['prop1']}
on top of that pydantic offers OriginAccessIdentity.parse_obj(dict_with_props)
pain point is repetion of resource.apply(lambda x: x['prop1']
- which kills the productivityOriginAccessIdentityOutputs.parse_obj(pulumi.Output)
- would be amazing
or OriginAccessIdentityOutputs(**pulumi.Output)
billowy-army-68599
08/03/2021, 6:33 PMred-match-15116
08/03/2021, 6:36 PMprops = ["prop1", "prop2", "blah"]
OriginAccessIdentityOutputs(**{p: resource.apply(lambda x: x[p]) for p in props})
But honestly is it really worth it?gorgeous-minister-41131
08/04/2021, 12:05 AMgreat-sunset-355
08/04/2021, 4:54 AMapply