Terraform module to convert routes to structured resources and methods with predecessors where required. This is primarily designed for opinionated use with terraform-aws-apigateway-proxy, but it can be useful otherwise. The concept is to provide an abstraction around a list of route objects that yields resources and methods that can be provided to for_each meta arguments when constructing api's.
module "route_builder" {
source = "theherk/apigateway-route-builder/aws"
routes = [
{
path = "/v1/{proxy+}"
methods = ["ANY"]
config = { uri = "example.com/v1/{proxy}" }
},
]
}
This would yield:
resources = {
"0|v1" = {
depth = 0
parent_key = null
path_part = "v1"
}
"1|v1/{proxy+}" = {
depth = 1
parent_key = "0|v1"
path_part = "{proxy+}"
}
}
methods = {
"0|v1|ANY" = {
config = {
uri = "example.com/v1"
}
depth = 0
key = "0|v1|ANY"
method = "ANY"
resource_key = "0|v1"
root = false
}
"1|v1/{proxy+}|ANY" = {
config = {
"uri" = "example.com/v1/{proxy}"
}
depth = 1
key = "1|v1/{proxy+}|ANY"
method = "ANY"
resource_key = "1|v1/{proxy+}"
root = false
}
}
To work on this repository, you need to install the pre-commit hooks, and dependencies from pre-commit-terraform.
make pre-commit
That should be the easy way, but if you use another package manager than apt
, brew
, or yum
or want to configure these differently on your system, you can do so by following the guidance here. For instance, you can set this up to use docker for running checks rather than installing directly to your filesystem.
After doing this, several checks will be run when attempting commits.
note: The following is generated by terraform docs
.
Name | Version |
---|---|
terraform | >= 0.15 |
No providers.
No modules.
No resources.
Name | Description | Type | Default | Required |
---|---|---|---|---|
expand_any | Boolean indicating if "ANY" methods should be expanded to the full list of http methods. The value of this is in the case custom authorizers. The method that reaches the lambda is "ANY" in those cases. However, your policy may want to match the actual http method verb used. This will optionally expand this for you. | bool |
false |
no |
generate_base_proxies | For any routes given with path ending in {proxy+} and url ending in {proxy} , generate another route for proxying the base route.For example, if a route given is: {and no other routes are given with path "/v1" and url "example.com", then a default base proxy path should be created, such as: {If the preceding statement is not true, then this assumes your explicit configuration is correct. |
bool |
true |
no |
routes | Configuration of routes to proxy. If ["ANY"] is given and expand_any is given, the module will expand these to all HTTP methods. |
list(object({ |
n/a | yes |
Name | Description |
---|---|
default_config | Until default optional atributes are implemented using terraform 1.3, this is provided as a glue toward terraform-aws-api-proxy since its method configurations require a specified format. Ideally this module would know nothing about that, but for now this utility is provided. |
methods | Methods with resource associations and integration configuration. |
resources | Resources keyed by the route's depth and path, and containing: depth, parent_key, path_part. |