From 9d6b3444e1a5e59e6a4a6866253af5b52277d6a8 Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Tue, 13 Jun 2023 16:46:45 +0200 Subject: [PATCH] Added dynamodb infra changes --- config/initializers/rswag_api.rb | 24 +++++++++++++----------- infra/handler/main.tf | 3 ++- infra/shared/dynamodb.tf | 8 ++++++-- infra/staging/dynamodb.tf | 8 ++++++-- infra/staging/main.tf | 3 ++- infra/worker/main.tf | 3 ++- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/config/initializers/rswag_api.rb b/config/initializers/rswag_api.rb index 73bdf6b23..2b9ca8fbe 100644 --- a/config/initializers/rswag_api.rb +++ b/config/initializers/rswag_api.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true -Rswag::Api.configure do |c| - # Specify a root folder where Swagger JSON files are located - # This is used by the Swagger middleware to serve requests for API descriptions - # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure - # that it's configured to generate files in the same folder - c.swagger_root = "#{Rails.root}/swagger" +unless Rails.env.production? + Rswag::Api.configure do |c| + # Specify a root folder where Swagger JSON files are located + # This is used by the Swagger middleware to serve requests for API descriptions + # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure + # that it's configured to generate files in the same folder + c.swagger_root = "#{Rails.root}/swagger" - # Inject a lambda function to alter the returned Swagger prior to serialization - # The function will have access to the rack env for the current request - # For example, you could leverage this to dynamically assign the "host" property - # - # c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] } + # Inject a lambda function to alter the returned Swagger prior to serialization + # The function will have access to the rack env for the current request + # For example, you could leverage this to dynamically assign the "host" property + # + # c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] } + end end diff --git a/infra/handler/main.tf b/infra/handler/main.tf index 585d08061..dc2f0a6ac 100644 --- a/infra/handler/main.tf +++ b/infra/handler/main.tf @@ -84,8 +84,9 @@ data "aws_iam_policy_document" "task_policy" { "dynamodb:Query", "dynamodb:UpdateItem", "dynamodb:DeleteItem", + "dynamodb:DescribeTable", ] - resources = [var.shared_resources.dynamo_registration_table] + resources = ["${var.shared_resources.dynamo_registration_table}/*"] } statement { effect = "Allow" diff --git a/infra/shared/dynamodb.tf b/infra/shared/dynamodb.tf index 0a9f4b642..d95f2d3fd 100644 --- a/infra/shared/dynamodb.tf +++ b/infra/shared/dynamodb.tf @@ -25,14 +25,18 @@ resource "aws_dynamodb_table" "registrations" { } global_secondary_index { hash_key = "competition_id" - name = "competition_id" + name = "registrations_index_competition_id" projection_type = "ALL" + write_capacity = 5 + read_capacity = 5 } global_secondary_index { hash_key = "user_id" - name = "user_id" + name = "registrations_index_user_id" projection_type = "ALL" + write_capacity = 5 + read_capacity = 5 } lifecycle { diff --git a/infra/staging/dynamodb.tf b/infra/staging/dynamodb.tf index e29450c15..3e67e765f 100644 --- a/infra/staging/dynamodb.tf +++ b/infra/staging/dynamodb.tf @@ -25,14 +25,18 @@ resource "aws_dynamodb_table" "registrations" { } global_secondary_index { hash_key = "competition_id" - name = "competition_id" + name = "registrations-staging_index_competition_id" projection_type = "ALL" + write_capacity = 5 + read_capacity = 5 } global_secondary_index { hash_key = "user_id" - name = "user_id" + name = "registrations-staging_index_user_id" projection_type = "ALL" + write_capacity = 5 + read_capacity = 5 } lifecycle { diff --git a/infra/staging/main.tf b/infra/staging/main.tf index 36f821822..8155064f1 100644 --- a/infra/staging/main.tf +++ b/infra/staging/main.tf @@ -88,8 +88,9 @@ data "aws_iam_policy_document" "task_policy" { "dynamodb:Query", "dynamodb:UpdateItem", "dynamodb:DeleteItem", + "dynamodb:DescribeTable", ] - resources = [aws_dynamodb_table.registrations.arn] + resources = ["${aws_dynamodb_table.registrations.arn}/*"] } statement { effect = "Allow" diff --git a/infra/worker/main.tf b/infra/worker/main.tf index 4dae54190..49f5d63ab 100644 --- a/infra/worker/main.tf +++ b/infra/worker/main.tf @@ -72,8 +72,9 @@ data "aws_iam_policy_document" "task_policy" { "dynamodb:Query", "dynamodb:UpdateItem", "dynamodb:DeleteItem", + "dynamodb:DescribeTable", ] - resources = [var.shared_resources.dynamo_registration_table] + resources = ["${var.shared_resources.dynamo_registration_table}/*"] } statement { effect = "Allow"