Support for yaml api body
It would be nice if we could also support yaml format API body. Currently doing the jsonencode(..) here restricts us to only providing a OpenAPI map:
https://github.com/cloudposse/terraform-aws-api-gateway/blob/d11aabaf9358626ea51a98a9a9854a9595da1339/main.tf#L13
But aws_api_gateway_rest_api actually accepts a yaml string just as well. I.e. the following works:
data "template_file" "swagger_api" {
template = file("./swagger.yaml")
vars = {
...
}
}
resource "aws_api_gateway_rest_api" "this" {
count = local.enabled ? 1 : 0
name = module.this.id
body = data.template_file.swagger_api.rendered
tags = module.this.tags
endpoint_configuration {
types = [var.endpoint_type]
}
}
The easiest solution would probably be to just remove the jsonencode() part and let the caller do that if needed. Optionally we could add another variable instead for backwards compatibility.
Another upside to getting rid of the jsonencode is supporting the case where the caller already has the body as json, for example when reading a json file.
I'm able to do...
openapi_config = yamldecode(file("${get_terragrunt_dir()}/vars/infra1-io.yaml"))
I export from aws as a yaml formatted file.
Not your request, but could help in the meantime?
I'm able to do...
openapi_config = yamldecode(file("${get_terragrunt_dir()}/vars/infra1-io.yaml"))I export from aws as a yaml formatted file.Not your request, but could help in the meantime?
If I do this:
resource "aws_api_gateway_rest_api" "api" {
name = var.product
description = var.description
put_rest_api_mode = "merge"
endpoint_configuration {
types = ["PRIVATE"]
vpc_endpoint_ids = [aws_vpc_endpoint.stg.id]
}
body = yamldecode(file("./openapi_resources.yaml"))
}
I get this TF error:
Error: Incorrect attribute value type
on main.tf line 12, in resource "aws_api_gateway_rest_api" "api":
body = yamldecode(file("./openapi_resources.yaml"))
Inappropriate value for attribute "body": string required.
@susie-idw is that different from what you do? Do you anything wrong with my code please? Thx