Skip to content

Commit

Permalink
- Address SonarCloud Issues
Browse files Browse the repository at this point in the history
- Used IAM in apigw method authorization for now until authorizer has been setup
  • Loading branch information
Ronaldo Macapobre committed Nov 13, 2024
1 parent 50fa6f9 commit fca25b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
13 changes: 7 additions & 6 deletions infrastructure/cloud/environments/dev/webapp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ module "lambda" {

# Create API Gateway
module "apigw" {
source = "../../modules/APIGateway"
environment = var.environment
app_name = var.app_name
region = var.region
account_id = data.aws_caller_identity.current.account_id
lambda_functions = module.lambda.lambda_functions
source = "../../modules/APIGateway"
environment = var.environment
app_name = var.app_name
region = var.region
account_id = data.aws_caller_identity.current.account_id
lambda_functions = module.lambda.lambda_functions
ecs_execution_role_arn = module.iam.ecs_execution_role_arn
}

# Create ECS Cluster
Expand Down
10 changes: 5 additions & 5 deletions infrastructure/cloud/modules/APIGateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resource "aws_api_gateway_rest_api_policy" "apigw_rest_api_policy" {
Statement = [
{
Effect = "Allow"
Principal = "*"
Principal = var.ecs_execution_role_arn
Action = "execute-api:Invoke"
Resource = "arn:aws:execute-api:${var.region}:${var.account_id}:${aws_api_gateway_rest_api.apigw.id}/*"
}
Expand Down Expand Up @@ -63,7 +63,7 @@ resource "aws_api_gateway_method" "get_locations_method" {
rest_api_id = aws_api_gateway_rest_api.apigw.id
resource_id = aws_api_gateway_resource.locations_resource.id
http_method = var.lambda_functions["get-locations"].http_method
authorization = "NONE"
authorization = "AWS_IAM"
api_key_required = true

request_parameters = {
Expand Down Expand Up @@ -92,7 +92,7 @@ resource "aws_api_gateway_method" "get_locations_rooms_method" {
rest_api_id = aws_api_gateway_rest_api.apigw.id
resource_id = aws_api_gateway_resource.rooms_resource.id
http_method = var.lambda_functions["get-rooms"].http_method
authorization = "NONE"
authorization = "AWS_IAM"
api_key_required = true

request_parameters = {
Expand Down Expand Up @@ -130,7 +130,7 @@ resource "aws_api_gateway_method" "get_files_civil_method" {
rest_api_id = aws_api_gateway_rest_api.apigw.id
resource_id = aws_api_gateway_resource.civil_resource.id
http_method = var.lambda_functions["search-civil-files"].http_method
authorization = "NONE"
authorization = "AWS_IAM"
api_key_required = true
}

Expand All @@ -155,7 +155,7 @@ resource "aws_api_gateway_method" "get_files_criminal_method" {
rest_api_id = aws_api_gateway_rest_api.apigw.id
resource_id = aws_api_gateway_resource.criminal_resource.id
http_method = var.lambda_functions["search-criminal-files"].http_method
authorization = "NONE"
authorization = "AWS_IAM"
api_key_required = true
}

Expand Down
5 changes: 5 additions & 0 deletions infrastructure/cloud/modules/APIGateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ variable "lambda_functions" {
invoke_arn = string
}))
}

variable "ecs_execution_role_arn" {
description = "The ECS Task Definition Execution role ARN"
type = string
}

0 comments on commit fca25b7

Please sign in to comment.