ensure apigatewayv2 cors configuration is not set when input is 'false'#6749
ensure apigatewayv2 cors configuration is not set when input is 'false'#6749Probotect0r wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
@vimtor thoughts? |
|
|
||
| function normalizeCors() { | ||
| return output(args.cors).apply((cors) => { | ||
| if (cors === false) return {}; |
There was a problem hiding this comment.
wouldn't just returning undefined here do the trick?
There was a problem hiding this comment.
if you did this because typescript complains about pulumi, we can either do @ts-ignore or unwrap cors from Input in the type definition
i lean towards the latter
There was a problem hiding this comment.
Simply returning undefined doesn't work, because it needs to be returned from inside the .apply(), since the input argument type is Input<boolean | Apiv2args...>. But returning undefined from inside the apply() results in a return type of Output<Apiv2CorsConfiguration | undefined>, which is not assignable to Input<Apiv2CorsConfiguration> | undefined.
What are the consequences of changing the cors argument type to boolean | Prettify<ApiGatewayV2CorsArgs>? The individual fields on ApiGatewayV2CorsArgs are still Input, so I am guessing it's fine? Still allows someone to pass in an Input for the specific fields?
There was a problem hiding this comment.
it would break on the very very unlikely scenario that someone is passing an output to cors
we should do the // @ts-ignore instead to be safe
Fixes #6748
Background
Specifying
cors: falseon the ApiGatewayv2 construct results in the cors configuration being set to{}which actually sets a barebones default configuration instead of completely clearing it. The barebones default config results in all requests to the Api failing cors because the allowed origins and headers list is empty.Notes
Because the corsConfiguration parameter on the pulumi api construct is
Output<ApiArgs> | undefined, I had to wrap the whole creation of the apigateway inside a.apply().I tested this code change by deploying it and verifying the cors config value using
aws apigatewayv2 get-api --api-id <my id> --query "CorsConfiguration" --region us-east-2