-
-
Notifications
You must be signed in to change notification settings - Fork 525
Add tests and checks for cache and database module
#3333
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
Merged
arkid15r
merged 4 commits into
OWASP:feature/nest-zappa-migration
from
rudransh-shrivastava:feature/nest-zappa-migration-cache-db-tests
Jan 15, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| test-infrastructure: | ||
| @for dir in infrastructure/modules/*/; do \ | ||
| if [ -d "$$dir/tests" ]; then \ | ||
| echo "Testing $$dir..."; \ | ||
| terraform -chdir="$$dir" init -backend=false -input=false && \ | ||
| terraform -chdir="$$dir" test || exit 1; \ | ||
| fi \ | ||
| done |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| variables { | ||
| common_tags = { Environment = "test", Project = "nest" } | ||
| environment = "test" | ||
| log_retention_in_days = 30 | ||
| project_name = "nest" | ||
| redis_engine_version = "7.0" | ||
| redis_node_type = "cache.t3.micro" | ||
| redis_num_cache_nodes = 1 | ||
| redis_port = 6379 | ||
| security_group_ids = ["sg-12345678"] | ||
| subnet_ids = ["subnet-12345678"] | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| run "test_auth_token_generated" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = length(random_password.redis_auth_token) == 1 | ||
| error_message = "Redis auth token must be generated." | ||
| } | ||
| } | ||
|
|
||
| run "test_auth_token_length" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = random_password.redis_auth_token[0].length == 32 | ||
| error_message = "Redis auth token must be 32 characters." | ||
| } | ||
| } | ||
|
|
||
| run "test_encryption_enabled_at_rest" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_elasticache_replication_group.main.at_rest_encryption_enabled | ||
| error_message = "At-rest encryption must be enabled." | ||
| } | ||
| } | ||
|
|
||
| run "test_encryption_enabled_in_transit" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_elasticache_replication_group.main.transit_encryption_enabled == true | ||
| error_message = "Transit encryption must be enabled." | ||
| } | ||
| } | ||
|
|
||
| run "test_engine_is_redis" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_elasticache_replication_group.main.engine == "redis" | ||
| error_message = "Engine must be Redis." | ||
| } | ||
| } | ||
|
|
||
| run "test_failover_disabled_for_single_node" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_elasticache_replication_group.main.automatic_failover_enabled == false | ||
| error_message = "Automatic failover must be disabled for single-node clusters." | ||
| } | ||
| } | ||
|
|
||
| run "test_failover_enabled_for_multi_node" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| redis_num_cache_nodes = 2 | ||
| } | ||
|
|
||
| assert { | ||
| condition = aws_elasticache_replication_group.main.automatic_failover_enabled == true | ||
| error_message = "Automatic failover must be enabled for multi-node clusters." | ||
| } | ||
| } | ||
|
|
||
| run "test_log_groups_created" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_cloudwatch_log_group.engine_log.retention_in_days == var.log_retention_in_days | ||
| error_message = "Engine log group must be created with correct retention." | ||
| } | ||
|
|
||
| assert { | ||
| condition = aws_cloudwatch_log_group.slow_log.retention_in_days == var.log_retention_in_days | ||
| error_message = "Slow log group must be created with correct retention." | ||
| } | ||
| } | ||
|
|
||
| run "test_replication_group_id_format" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_elasticache_replication_group.main.replication_group_id == "${var.project_name}-${var.environment}-cache" | ||
| error_message = "Replication group ID must follow naming convention: {project}-{environment}-cache." | ||
| } | ||
| } | ||
|
|
||
| run "test_ssm_parameter_is_secure_string" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_ssm_parameter.django_redis_password.type == "SecureString" | ||
| error_message = "Redis password must be stored as SecureString." | ||
| } | ||
| } | ||
|
|
||
| run "test_ssm_parameter_path_format" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = aws_ssm_parameter.django_redis_password.name == "/${var.project_name}/${var.environment}/DJANGO_REDIS_PASSWORD" | ||
| error_message = "SSM parameter must follow path: /{project}/{environment}/DJANGO_REDIS_PASSWORD." | ||
| } | ||
| } | ||
|
|
||
| run "test_subnet_group_uses_provided_subnets" { | ||
| command = plan | ||
|
|
||
| assert { | ||
| condition = toset(aws_elasticache_subnet_group.main.subnet_ids) == toset(var.subnet_ids) | ||
| error_message = "Subnet group must use the provided subnet IDs." | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 always avoided committing lock files inside modules, as they served no purpose since the main (staging or production) lock file would take precedence.
Committing them seems to cause no problems but improves test speed (
terraform initis faster).https://discuss.hashicorp.com/t/what-is-the-best-practise-with-terraform-lock-hcl-in-modules-commit-or-not/28648
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.
Yeah, it seems it's fine to have them in git