Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/theherk/terraform-aws-apigateway-route-builder

Terraform module to convert routes to structured resources and methods with predecessors where required.
https://github.com/theherk/terraform-aws-apigateway-route-builder

api-gateway aws terraform terraform-aws terraform-module

Last synced: 16 days ago
JSON representation

Terraform module to convert routes to structured resources and methods with predecessors where required.

Awesome Lists containing this project

README

        

# terraform aws apigateway route builder

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](https://github.com/theherk/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](https://www.terraform.io/language/meta-arguments/for_each) when constructing api's.

## Usage

``` hcl
module "route_builder" {
source = "theherk/apigateway-route-builder/aws"

routes = [
{
path = "/v1/{proxy+}"
methods = ["ANY"]
config = { uri = "example.com/v1/{proxy}" }
},
]
}
```

This would yield:

``` hcl
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
}
}
```

### Examples

- [Simple](examples/simple)
- [Complete](examples/complete)

## Contributing

To work on this repository, you need to install the [pre-commit](https://github.com/pre-commit/pre-commit) hooks, and dependencies from [pre-commit-terraform](https://github.com/antonbabenko/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](https://github.com/antonbabenko/pre-commit-terraform#1-install-dependencies). 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`.

## Requirements

| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 0.15 |

## Providers

No providers.

## Modules

No modules.

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [expand\_any](#input\_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](#input\_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:

{
path = "/v1/{proxy+}"
methods = ["ANY"]
config = { uri = "example.com/v1/{proxy}"
},
and no other routes are given with path "/v1" and url "example.com", then a default base proxy path should be created, such as:
{
path = "/v1"
methods = ["ANY"]
config = { uri = "example.com/v1" }
},
If the preceding statement is not true, then this assumes your explicit configuration is correct. | `bool` | `true` | no |
| [routes](#input\_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({
path = string
methods = list(string)
config = any
}))
| n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| [default\_config](#output\_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](#output\_methods) | Methods with resource associations and integration configuration. |
| [resources](#output\_resources) | Resources keyed by the route's depth and path, and containing: depth, parent\_key, path\_part. |