improving things

This commit is contained in:
José Ivanchechen 2022-12-03 20:16:55 +00:00
parent 10db94eeef
commit 291ba01894
3 changed files with 16 additions and 8 deletions

View File

@ -14,6 +14,8 @@ params:
url: "https://www.last.fm/user/dotivanch" url: "https://www.last.fm/user/dotivanch"
- name: "Steam" - name: "Steam"
url: "https://steamcommunity.com/id/dotivanch" url: "https://steamcommunity.com/id/dotivanch"
- name: "Linkedin"
url: "https://www.linkedin.com/in/josehenriqueivan/"
baseURL: 'https://ivanch.me/' baseURL: 'https://ivanch.me/'
languageCode: 'pt-br' languageCode: 'pt-br'

View File

@ -10,7 +10,7 @@ Right when we first started to use the AWS API Gateway, one of the things that d
So we decided to create a module to help us with this. Big thanks to [Stephano](https://www.linkedin.com/in/stephano-macedo/) who helped me a lot! So we decided to create a module to help us with this. Big thanks to [Stephano](https://www.linkedin.com/in/stephano-macedo/) who helped me a lot!
## Before ## Before
Basically, when we are developing a new API, we need to create a lot of resources in the API Gateway. We need to create a new resource, a new method and a new integration, and therefore connecting all of them using their respectives IDs. Basically, when we are developing a new API, we need to create a 3 resources in the API Gateway. We need to create a new gateway_resource, a new gateway_method and a new gateway_integration, and therefore connecting all of them using their respectives IDs.
Let's suppose a endpoint called `/users/all`. This is a snippet of the code we had before: Let's suppose a endpoint called `/users/all`. This is a snippet of the code we had before:
@ -52,7 +52,7 @@ resource "aws_api_gateway_integration" "api_users_all" {
} }
``` ```
Obviously there is more code to that, but this is the main part of it and that's what we will be using in the module. Obviously there is more code to that, but this is the main part of it and we will be focusing on that.
## Creating a module ## Creating a module
Now we can create a module to help us. We can start by creating a separate folder which will be our module, let's call it `terraform/modules/api`, inside of it there will be a couple of files: Now we can create a module to help us. We can start by creating a separate folder which will be our module, let's call it `terraform/modules/api`, inside of it there will be a couple of files:
@ -119,10 +119,10 @@ output "resource_id" {
As we referenced the `resource_id` in the `outputs.tf`, we need to define it in the `locals.tf`. As we referenced the `resource_id` in the `outputs.tf`, we need to define it in the `locals.tf`.
```terraform ```terraform
locals { locals {
// this join is because we can't do aws_api_gateway_resource.api_resource.id // this join is because we simply can't do aws_api_gateway_resource.api_resource.id
resource_id = join("", 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 // if starts with '{' and ends with '}' then it's a path variable
// take all the middle characters // take all the middle characters
// if it's empty then it's a normal path // if it's empty then it's a normal path
path_variable = length(regexall("{.*}", var.path_part)) > 0 ? substr(var.path_part, 1, length(var.path_part) - 2) : "" path_variable = length(regexall("{.*}", var.path_part)) > 0 ? substr(var.path_part, 1, length(var.path_part) - 2) : ""
@ -140,7 +140,7 @@ locals {
``` ```
### gateway.resources.tf ### gateway.resources.tf
Here is where the fun begins, hehe. Thank God it's pretty straightforward. All of the variables are coming from the `variables.tf` file. Here is where the fun begins, thank God it's pretty straightforward. All of the variables are coming from the `variables.tf` file.
```terraform ```terraform
resource "aws_api_gateway_resource" "api_resource" { resource "aws_api_gateway_resource" "api_resource" {
rest_api_id = var.gateway_id rest_api_id = var.gateway_id
@ -168,6 +168,7 @@ resource "aws_api_gateway_method" "api_method" {
``` ```
### gateway.integrations.tf ### gateway.integrations.tf
The same idea goes for api_gateway_integration.
```terraform ```terraform
resource "aws_api_gateway_integration" "api_integration" { resource "aws_api_gateway_integration" "api_integration" {
count = var.only_resource ? 0 : length(var.http_methods) count = var.only_resource ? 0 : length(var.http_methods)
@ -229,7 +230,9 @@ module "api_users_all" {
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. 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 ## 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 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. 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 can call it `WWW-Authenticate-Header` for example and it will work.
## Disclaimer ## 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. This code has not been tested "as is", but 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.
There has been a lot of pieces of Terraform code that was omitted, like when we use the declare the `terraform_remote_state` or the `authorizer_id` which you will need if using authorization "CUSTOM".

View File

@ -5,7 +5,7 @@ draft: false
summary: "Self hosting containers that might be useful." summary: "Self hosting containers that might be useful."
--- ---
Litty bitty apocalyptic. Just having fun.
## Necessary ## Necessary
* [Portainer](https://www.portainer.io/) - Container management. * [Portainer](https://www.portainer.io/) - Container management.
@ -21,11 +21,14 @@ Litty bitty apocalyptic.
* [Notepad](https://github.com/pereorga/minimalist-web-notepad) - Homemade Dontpad. * [Notepad](https://github.com/pereorga/minimalist-web-notepad) - Homemade Dontpad.
* [Code Server](https://hub.docker.com/r/linuxserver/code-server/) - VSCode inside of a Docker. * [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. * [FileBrowser](https://filebrowser.org/installation#docker/) - The name says by itself.
* [Ngnix](https://hub.docker.com/_/nginx/) - Web server like this one.
## Media ## Media
* [Transmission](https://hub.docker.com/r/linuxserver/transmission/) - Torrent client with a web interface. * [Transmission](https://hub.docker.com/r/linuxserver/transmission/) - Torrent client with a web interface.
* [Jackett](https://hub.docker.com/r/linuxserver/jackett/) - Torrent tracker aggregator.
* [Sonarr](https://hub.docker.com/r/linuxserver/sonarr/) - TV shows management (Torrent integration). * [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). * [Radarr](https://hub.docker.com/r/linuxserver/radarr/) - Movies management (Torrent integration).
* [Lidarr](https://hub.docker.com/r/linuxserver/lidarr/) - Music management (Torrent integration).
* [Jellyfin](https://hub.docker.com/r/linuxserver/jellyfin/) - Homemade Netflix. * [Jellyfin](https://hub.docker.com/r/linuxserver/jellyfin/) - Homemade Netflix.
## Game server ## Game server