-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(DMVP-1806): In api-gateway module resolve checkov errors #274
base: main
Are you sure you want to change the base?
Changes from all commits
baa7807
ac8f3cb
f7c26c0
eb67d66
31b58a8
e2fa07d
d8b79d1
c0cf081
aa8a0ff
3693ba1
14e6c32
283941d
792ab53
93822bc
b8d26de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ data "aws_s3_bucket" "selected" { | |
} | ||
|
||
resource "aws_cloudwatch_log_group" "log" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest deleting this module from the repo, cause it's already exists in eks module. |
||
count = var.create_lambda ? 1 : 0 | ||
name = "alb-${var.alb_log_bucket_name}" | ||
retention_in_days = 365 | ||
count = var.create_lambda ? 1 : 0 | ||
name = "alb-${var.alb_log_bucket_name}" | ||
kms_key_id = var.kms_key_id | ||
retention_in_days = 365 | ||
} | ||
|
||
module "alb_logs_to_cloudwatch" { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
terraform { | ||
required_providers { | ||
test = { | ||
source = "terraform.io/builtin/test" | ||
} | ||
|
||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 1.0.7" | ||
} | ||
} | ||
|
||
required_version = ">= 1.0.7" | ||
} | ||
|
||
/** | ||
* set the following env vars so that aws provider will get authenticated before apply: | ||
export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxxxxxx | ||
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxx | ||
*/ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module "alb-logs-lambda" { | ||
source = "../../" | ||
alb_log_bucket_name = "aws-cloudtrail-logs-565580475168-fb3dbb26" | ||
account_id = "565580475168" | ||
create_alb_log_bucket = false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resource "test_assertions" "dummy" { | ||
component = "this" | ||
|
||
equal "scheme" { | ||
description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." | ||
got = "all good" | ||
want = "all good" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# basic | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.7 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 1.0.7 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_test"></a> [test](#provider\_test) | n/a | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_alb-logs-lambda"></a> [alb-logs-lambda](#module\_alb-logs-lambda) | ../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| test_assertions.dummy | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,32 @@ variable "region" { | |
default = "us-east-1" | ||
description = "Default region" | ||
} | ||
|
||
variable "account_id" { | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "kms_key_id" { | ||
type = string | ||
default = null | ||
description = " (Optional) The ARN of the KMS Key to use when encrypting log data. Please note, after the AWS KMS CMK is disassociated from the log group, AWS CloudWatch Logs stops encrypting newly ingested data for the log group. All previously ingested data remains encrypted, and AWS CloudWatch Logs requires permissions for the CMK whenever the encrypted data is requested." | ||
} | ||
|
||
variable "sse_algorithm" { | ||
type = string | ||
default = null | ||
description = "sse_algorithm - (Required) The server-side encryption algorithm to use. Valid values are AES256 and aws:kms" | ||
} | ||
|
||
variable "enabled" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name and description of variable is not descriptive, please have descriptive name/descriptions for variables |
||
type = bool | ||
default = false | ||
description = "enabled" | ||
} | ||
|
||
variable "logging" { | ||
type = list(any) | ||
default = [] | ||
description = "logging" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
resource "aws_cloudwatch_log_group" "access_logs" { | ||
count = var.enable_access_logs ? 1 : 0 | ||
|
||
name = "api-gateway-${var.name}-${var.stage_name}-logs" | ||
name = "api-gateway-${var.name}-${var.stage_name}-logs" | ||
retention_in_days = var.retention_in_days | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ resource "aws_api_gateway_rest_api" "this" { | |
endpoint_configuration { | ||
types = [var.endpoint_config_type] | ||
} | ||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
|
||
# root resource methods configs | ||
|
@@ -65,8 +68,11 @@ resource "aws_api_gateway_integration_response" "root_methods_integration_respon | |
resource "aws_api_gateway_stage" "stage" { | ||
stage_name = var.stage_name | ||
|
||
deployment_id = aws_api_gateway_deployment.deployment.id | ||
rest_api_id = aws_api_gateway_rest_api.this.id | ||
deployment_id = aws_api_gateway_deployment.deployment.id | ||
rest_api_id = aws_api_gateway_rest_api.this.id | ||
xray_tracing_enabled = var.xray_tracing_enabled | ||
cache_cluster_enabled = var.cache_cluster_enabled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll be better to have a map of these 2 variables. |
||
cache_cluster_size = var.cache_cluster_size | ||
|
||
dynamic "access_log_settings" { | ||
for_each = aws_cloudwatch_log_group.access_logs | ||
|
@@ -133,8 +139,10 @@ resource "aws_api_gateway_method_settings" "general_settings" { | |
# Limit the rate of calls to prevent abuse and unwanted charges | ||
throttling_rate_limit = var.monitoring_settings.throttling_rate_limit | ||
throttling_burst_limit = var.monitoring_settings.throttling_burst_limit | ||
} | ||
|
||
caching_enabled = var.monitoring_settings.caching_enabled | ||
cache_data_encrypted = var.monitoring_settings.cache_data_encrypted | ||
} | ||
depends_on = [ | ||
module.account_settings, | ||
aws_api_gateway_stage.stage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
terraform { | ||
required_providers { | ||
test = { | ||
source = "terraform.io/builtin/test" | ||
} | ||
|
||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 1.0.7" | ||
} | ||
} | ||
|
||
required_version = ">= 1.0.7" | ||
} | ||
|
||
/** | ||
* set the following env vars so that aws provider will get authenticated before apply: | ||
export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxxxxxx | ||
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxx | ||
*/ | ||
provider "aws" { | ||
region = "eu-central-1" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module "api_gateway" { | ||
source = "../../" | ||
|
||
name = "api_gw" | ||
endpoint_config_type = "REGIONAL" | ||
stage_name = "api-stage" | ||
|
||
root_resource_configs = { | ||
ANY = { | ||
authorization = "NONE" | ||
api_key_required = true | ||
|
||
integration = { | ||
type = "HTTP" | ||
endpoint_uri = "https://www.google.de" | ||
integration_http_method = "ANY" | ||
request_parameters = { "integration.request.header.x-api-key" = "method.request.header.x-api-key" } | ||
} | ||
} | ||
} | ||
|
||
usage_plan_values = {} | ||
|
||
providers = { | ||
aws.virginia = aws.virginia | ||
} | ||
} | ||
|
||
provider "aws" { | ||
alias = "virginia" | ||
region = "us-east-1" | ||
} | ||
|
||
output "access_key_id" { | ||
value = module.api_gateway.access_key_id | ||
} | ||
|
||
output "access_secret_key" { | ||
value = nonsensitive(module.api_gateway.access_secret_key) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resource "test_assertions" "dummy" { | ||
component = "this" | ||
|
||
equal "scheme" { | ||
description = "As module does not have any output and data just make sure the case runs. Probably can be thrown away." | ||
got = "all good" | ||
want = "all good" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let the users pass these "true" values dynamically and not have it hardcoded here. Also, you can set "true" the default values for those variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no special need to have this options controller from outside as this access is for blocking public access to bucket always,
we have to decide and test to make sure this is ok, as I see this bucket should be accessible to write and read from lambda and cloudwatch and this services should be able to get access to do those actions?