small changes

This commit is contained in:
José Henrique Ivanchechen 2022-12-01 17:22:04 -03:00
parent 3f0df2084d
commit 919bd4b6cd
3 changed files with 16 additions and 15 deletions

View File

@ -1,4 +1,4 @@
# [Personal website](ivanch.me)
# [Personal website](https://ivanch.me)
## Running
1. `git submodule update --init --recursive`

View File

@ -1,7 +1,7 @@
---
title: "AWS API Gateway Terraform"
date: 2022-12-01T15:56:53-03:00
draft: true
date: 2022-12-01T15:30:00-03:00
draft: false
summary: "How to create API Gateway endpoints with Terraform."
---
@ -45,6 +45,7 @@ resource "aws_api_gateway_integration" "api_users_all" {
type = "HTTP_PROXY"
integration_http_method = "GET"
uri = "https://api.example.com/users/all"
request_parameters = {
"integration.request.header.Authorization" = true
}
@ -119,6 +120,7 @@ output "resource_id" {
As we referenced the `resource_id` in the `outputs.tf`, we need to define it in the `locals.tf`.
```terraform
locals {
// this join is because we can't do aws_api_gateway_resource.api_resource.id
resource_id = join("", aws_api_gateway_resource.api_resource[*].id)
// if starts with '{' and ends with '}' then it's a path parameter
@ -159,7 +161,7 @@ resource "aws_api_gateway_method" "api_method" {
http_method = var.http_methods[count.index]
authorization = var.authorization ? "CUSTOM" : "NONE"
// Got a path variable? No problem! We deal with that too right here.
// Got a path variable? No problem! We deal with that too right here
request_parameters = merge(local.method_request_parameters, local.path_variable != "" ? {
"method.request.path.${local.path_variable}" = local.path_variable != ""
} : {})
@ -194,9 +196,9 @@ Now that we have the module, we can use it in our `main.tf` file. We will use th
module "api_users" {
source = "./api"
parent_id = local.gateway.gateway_config.root_endpoints.api_root
gateway_id = gateway.outputs.gateway.gateway_config.gateway_id
parent_id = gateway.outputs.gateway.gateway_config.root_endpoints.api_root
path_part = "users"
gateway_id = local.gateway.gateway_config.gateway_id
only_resource = true
}
@ -204,33 +206,32 @@ module "api_users" {
module "api_users_all" {
source = "./api"
gateway_id = gateway.outputs.gateway.gateway_config.gateway_id
parent_id = module.api_users.resource_id
path_part = "all"
http_methods = ["GET"]
uri = "http://api.example.com/users/all"
gateway_id = local.gateway.gateway_config.gateway_id
authorizer_id = local.gateway.gateway_config.authorizers.default
}
# /users/all/{userid} (get, post, put, delete)
module "api_users_all" {
source = "./api"
gateway_id = gateway.outputs.gateway.gateway_config.gateway_id
parent_id = module.api_users_all.resource_id
path_part = "{userid}"
http_methods = ["GET", "POST", "PUT", "DELETE"]
uri = "http://api.example.com/users/all/{userid}"
gateway_id = local.gateway.gateway_config.gateway_id
}
# and so on...
```
## Conclusion
For one endpoint, we went from having to manage 11 lines splitted in 3 files to just 5 lines inside of one file. If you have to manage hundreds of endpoints, that will be a great help.
For one endpoint, we went from having to manage 15 lines splitted in 3 files to just 5 lines inside of one file. If you have to manage hundreds of endpoints, that will be a great help.
## WWW-Authenticate header
We can also add the `WWW-Authenticate` header to the request for example. We tried to do that by adding it to the files properly, but that didn't work. The reason is that the API Gateway was not passing the `WWW-Authenticate` to our API, and that's because of the name of the header. You may call it `WWW-Authenticate-Header` for example and it will work.
We can also add the `WWW-Authenticate` header to the request for example. We tried to do that by adding it to the files properly, but it didn't work. The reason was that the API Gateway was not passing the `WWW-Authenticate` to our API, and that's because of the name of the header. You may call it `WWW-Authenticate-Header` for example and it will work.
## Disclaimer
This code has not been tested "as is", though it has been tested as part of a bigger project. There is always room for improvements and more possibilities depending on the context, but it's a good start.

View File

@ -14,7 +14,7 @@ Litty bitty apocalyptic.
## Misc
* [Netdata](https://hub.docker.com/r/netdata/netdata/) - Server monitor.
* [Heimdall](https://www.heimdall.io/) - Panel to add all your selfhosted services.
* [Heimdall](https://hub.docker.com/r/linuxserver/heimdall/) - Panel to add all your selfhosted services.
* [Statping](https://statping.com/) - Application ping.
* [Uptime Kuma](https://uptime.kuma.pet/) - Application ping (beautier).
* [Gitea](https://gitea.com/) - Homemade GitHub.
@ -22,11 +22,11 @@ Litty bitty apocalyptic.
* [Code Server](https://hub.docker.com/r/linuxserver/code-server/) - VSCode inside of a Docker.
* [FileBrowser](https://filebrowser.org/installation#docker/) - The name says by itself.
## Mídia
## Media
* [Transmission](https://hub.docker.com/r/linuxserver/transmission/) - Torrent client with a web interface.
* [Sonarr](https://hub.docker.com/r/linuxserver/sonarr/) - TV shows management (Torrent integration).
* [Radarr](https://hub.docker.com/r/linuxserver/radarr/) - Movies management (Torrent integration).
* [Jekyll](https://hub.docker.com/r/jekyll/jekyll/) - Homemade Netflix.
## Joguinhos
## Game server
* [Minecraft Server](https://hub.docker.com/r/itzg/minecraft-server/) - The name says by itself².