creamy-whale-55909
06/12/2022, 5:55 PMpulumi.Output.all()
or apply()
. My observed behavior is sometimes, instead of getting access to the output value in it's expected form (ie str
), I am given the output object address memory (ie <pulumi.output.Output object at 0x7f02baf74b80>
).
I've seen a few folks in the channel struggling with the same problem. I think I understand why this is happening. Sharing my understanding below so folks can a)
confirm (or correct) my understanding and b)
benefit from the explanation (assuming it's correct ๐
).
Here's the context... ๐งตiam policy
that gets attached to a role
that my lambda
will assume in order to write logs to cloudwatch.
Here, I am trying to interpolate the lambda's physical name in the policy to help construct the log-group
arn:
lambda_physical_name = my_lambda.name.apply(lambda name: name)
lambda_policy = aws.iam.RolePolicy(
"lambdaPolicy",
role=iam_for_lambda.name,
policy=json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:us-east-1:826697897825:*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
f"arn:aws:logs:us-east-1:826697897825:log-group:/aws/lambda/{lambda_physical_name}*"
]
},
]
}
),
)
But the provisioned policy ends up reading:
...
"Resource": ["arn:aws:logs:us-east-1:826697897825:log-group:/aws/lambda/<pulumi.output.Output object at 0x7f02baf74b80>*"]
lambda_policy = aws.iam.RolePolicy(
"lambdaPolicy",
role=iam_for_lambda.name,
policy=my_lambda.name.apply(
lambda physical_name : json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:us-east-1:826697897825:*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
f"arn:aws:logs:us-east-1:826697897825:log-group:/aws/lambda/{physical_name}:*"
]
}
]
}
)
),
)
policy
input property as type str
(a stringed json policy doc) and as a result, resolved lambda_physical_name
as the str representation of the Output<T>
object.
Whereas my refactor initialized the policy
input as type Output<T>
, which is why my call to apply
resolved as expected.
Am I understanding this correctly?echoing-dinner-19531
06/13/2022, 12:12 PMToString
it returns the string:
Calling [ToString] on an [Output<T>] is not supported.
To get the value of an Output<T> as an Output<string> consider:
1. o.Apply(v => $\"prefix{v}suffix\")
2. Output.Format($\"prefix{hostname}suffix\");
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of Pulumi.
We should probably do this for the python SDK as well, to help with users stumbling over it like this.creamy-whale-55909
06/13/2022, 12:28 PM