Reputation: 10468
I'm trying to use OpenAPI because it looks like a standard and it's less cumbersome than terraform resources. I've converted json to what terraform might take but I get the error:
module.aws_api_gateway.aws_api_gateway_rest_api.CICDAPI: body must be a single value, not a list
Bellow is my code:
resource "aws_api_gateway_rest_api" "CICDAPI" {
name = "cicdapi"
description = "cicd build pipeline"
binary_media_types = [
"application/json"
]
body = {
swagger = 2
info {
title = "AwsServerlessExpressApi"
}
basePath = "/prod"
schemes = [
"https"
]
....
I've yet to find an example on how we can assign OpenAPI to aws gateway api resource. Can I just make body a json string??? It's not said anywhere in the documentation.
Upvotes: 1
Views: 2326
Reputation: 56859
As you can see by the error it needs to be a string rather than a hashmap like you have in your code.
You should be able to simply wrap the body value in a heredoc.
So you want something like:
resource "aws_api_gateway_rest_api" "CICDAPI" {
name = "cicdapi"
description = "cicd build pipeline"
binary_media_types = [
"application/json"
]
body = <<EOF
{
swagger = 2
info {
title = "AwsServerlessExpressApi"
}
basePath = "/prod"
schemes = [
"https"
]
....
}
EOF
}
The docs are lacking for explaining this but you can also see how it's implemented in the acceptance test.
I'd also need to check this but I think you can probably load your OpenAPI spec from a file by using body = "${file("path/to/file")}"
Upvotes: 2