lively-controller-39972
02/12/2023, 8:30 AMimport * as aws from "@pulumi/aws";
const cachingOptimizedPolicy = aws.cloudfront.getCachePolicyOutput({
name: "Managed-CachingOptimized",
});
const distribution = new aws.cloudfront.Distribution("distribution", {
orderedCacheBehaviors: [
{
cachePolicyId: cachingOptimizedPolicy.id,
...
}
],
...
});
This code has a type error. cachingOptimizedPolicy.id
is of type Output<string | undefined>
but cachePolicyId
expects something of type string
. I had a similar code with Terraform but didn't have any issue.echoing-dinner-19531
02/13/2023, 11:51 AMid
value in the result, and if it doesn't then it coming back as string | undefined
is accurate and you should handle that (maybe by just casing to string
if you know that in your case it does always get set).
If it always sets id then we should fix up the type for that.
If you just want to cast it you can do cachingOptimizedPolicy.id.apply(id => id!)
to tell TS to ignore the undefined part.
Might be worth raising an issue at https://github.com/pulumi/pulumi-aws about this, the team that work on this will know better than me if id
is actually optional or not.lively-controller-39972
02/13/2023, 12:14 PM.apply(id => id!)
that seems a good workaround.