amazon-web-servicesterraformaws-api-gateway

How to activate a documentation on AWS API Gateway using Terraform?


I am publishing an API Gateway documentation using aws_api_gateway_documentation_version as follows:

resource "aws_api_gateway_documentation_version" "docs_version" {
  version     = "v1.0.0-${var.env}"
  rest_api_id = aws_api_gateway_rest_api.my_api.id
  description = "Documentation for my API"
  depends_on  = [
    aws_api_gateway_documentation_part.method_docs
  ]
}

Even though it appears in the documentation history on the AWS console it appears with status "-" instead of "Active". For this reason when I export the Swagger file it does not contain the latest version of my documentation. How can I activate a documentation using Terraform?


Solution

  • Not very elegant but I managed by using an AWS CLI command inside the Terraform file:

    resource "null_resource" "update_api_gateway_stage" {
      provisioner "local-exec" {
        command = "aws apigateway update-stage --rest-api-id ${aws_api_gateway_rest_api.my_api.id} --stage-name ${aws_api_gateway_stage.my_api_stage.stage_name} --patch-operations op=replace,path=/documentationVersion,value=${local.api_version_stage}"
      }
      depends_on = [aws_api_gateway_stage.my_api_stage]
      triggers = { redeployment = timestamp() }
    }