sparse-intern-71089
10/14/2022, 4:22 PMminiature-musician-31262
10/14/2022, 9:30 PMexport outside of the apply: https://github.com/pulumi/templates/blob/master/serverless-azure-python/__main__.py#L139-L144echoing-dinner-19531
10/16/2022, 9:54 AMexport method no need for applypolite-ocean-13631
10/16/2022, 3:40 PMpulumi_awsx rather than pulumi_aws. With the latter I would get a non-Output object like TaskDefinition which would have exportable attributes such as its ARN. With pulumi_awsx I would get e.g. a FargateTaskDefinition that has a Output wrapped task_definition attribute, which has the ARN and other exportable attributes. So exporting task_definition.task_definition.arn works. The problem occurred because the code I was using was trying to automatically export several common attributes, such as arn, name, id, etc. When the attribute didn't exist for a given object (e.g. TaskDefinition has no url), it would suppress the AttributeError and continue, but because the Output wrapped objects are evaluated within callbacks the error suppression did not work.
To work around that I moved the error suppression into a callback that I would then apply to the Output object:
def _get_exportable(
obj: Any, # noqa: ANN401
) -> Iterable[tuple[str, None | str | pulumi.Output[str]]]:
is_output = isinstance(obj, pulumi.Output)
for key in STANDARD_EXPORT_KEYS:
def _get_attr(
x: Any, # noqa: ANN401
k: str = key,
) -> None | str | pulumi.Output[str]:
with suppress(AttributeError):
return getattr(x, k) # type: ignore
return None
yield key, obj.apply(_get_attr) if is_output else _get_attr(obj)
The results from this would then be exported like so:
for key, value in _get_exportable(obj):
pulumi.export(name=f"{prefix}{key}", value=value)