5anhpv
1
It seems that there are missing information from the docs here [https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_api#cors_configuration].
I don’t see any example for the cors_configuration
param.
Here is the code of this module
https://github.com/terraform-providers/terraform-provider-aws/blob/7ce1660fd27d4de99793b7c01a56ec98226d0a34/aws/resource_aws_apigatewayv2_api.go#L43
I read about Schema Attributes and Types but still cannot deal with it https://www.terraform.io/docs/extend/schemas/schema-types.html.
Here is my configuration:
resource "aws_apigatewayv2_api" "_" {
name = "staging API"
protocol_type = "HTTP"
cors_configuration = [
"allow_origins" = ["api.test.com"],
"allow_methods" = ["POST", "GET"],
"allow_headers" = ["content-type"],
"max_age" = 300
]
}
True, there is no example of this but maybe we can piece it together
Have you tried this:
resource "aws_apigatewayv2_api" "_" {
name = "staging API"
protocol_type = "HTTP"
cors_configuration {
"allow_origins" = ["api.test.com"],
"allow_methods" = ["POST", "GET"],
"allow_headers" = ["content-type"],
"max_age" = 300
}
}
That seems more in line with how things are usually done
If that fails, you can also try using a map:
resource "aws_apigatewayv2_api" "_" {
name = "staging API"
protocol_type = "HTTP"
cors_configuration = {
"allow_origins" = ["api.test.com"],
"allow_methods" = ["POST", "GET"],
"allow_headers" = ["content-type"],
"max_age" = 300
}
}
But it should not be a list
1 Like
5anhpv
3
Thank you so much @bentterp,
I’ve just tried
resource "aws_apigatewayv2_api" "_" {
name = "staging API"
protocol_type = "HTTP"
cors_configuration {
allow_origins = ["https://api.test.com"]
allow_methods = ["POST", "GET"]
allow_headers = ["content-type"]
max_age = 300
}
}
and it worked like a charm!