Terraform gives us possibility to write these ressources for our api_gateway :
aws_api_gateway_account
aws_api_gateway_api_key
aws_api_gateway_authorizer
aws_api_gateway_base_path_mapping
aws_api_gateway_client_certificate
aws_api_gateway_deployment
aws_api_gateway_documentation_part
aws_api_gateway_documentation_version
aws_api_gateway_domain_name
aws_api_gateway_gateway_response
aws_api_gateway_integration ==> to specify proxy or not , wich lambda mock endpoint..
aws_api_gateway_integration_response ====>to specify proxy or not , wich lambda mock endpoint..
aws_api_gateway_method : POST GET
aws_api_gateway_method_response ====>
aws_api_gateway_method_settings
aws_api_gateway_model
aws_api_gateway_resource =====> to create ressource Person Ticket ….
aws_api_gateway_rest_api
aws_api_gateway_stage
aws_api_gateway_usage_plan
aws_api_gateway_usage_plan_key
aws_api_gateway_vpc_link
when we write scripts with terraform for an api gateway the first important ressource that we should create is aws_api_gateway_rest_api
like PetStore api or demoApi
We have 2 way to write the whole api_gateway script ( ressources , methods , proxy , models stage…..) where ressource will have it’s own script methods it’s own script with aws_api_gateway_method and so on …. :
- write a script for each ressource from aws_api_gateway_account to aws_api_gateway_vpc_link with the depends_on argument in the end of each script that he can wait the creation of other ressources (fucking headaches approach)
Or the second easy methods
- a. use the plateform console to construct your api , deploy it , enter stage section , export it as swagger + extensions API Gateway Exporter en tant que Swagger + extensions API Gateway
b.copy the json in file as myApiSpec.json from example
- write a ressource api rest as terraform script
resource "aws_api_gateway_rest_api" "MyDemoAPI" { name = "MyDemoAPI" description = "This is my API for demonstration purposes" body= "here you can put the myApiSpec.json content it contains all ressource the other ressources that u need " }
body
– (Optional) An OpenAPI specification that defines the set of routes and integrations to create as part of the REST API.- run terraform apply
Note: If the body
argument is provided, the OpenAPI specification will be used to configure the resources, methods and integrations for the Rest API. If this argument is provided, the following resources should not be managed as separate ones, as updates may cause manual resource updates to be overwritten:
aws_api_gateway_resource
aws_api_gateway_method
aws_api_gateway_method_response
aws_api_gateway_method_settings
aws_api_gateway_integration
aws_api_gateway_integration_response
aws_api_gateway_gateway_response
aws_api_gateway_model
Ps: when passing a json body to terraform script’s don’t forget to use the <
<<EOF
Put Here your api contract in swagger format or only in json
EOF
More informations from here :
https://www.terraform.io/docs/providers/aws/r/api_gateway_rest_api.html
Do you have a full working example?