Feature/infrastructure setup#1
Feature/infrastructure setup#1Ramesh Dilshan Dissanayaka (RDilshan2000) wants to merge 2 commits into
Conversation
📝 WalkthroughI need to use the exact rangeIds from the list. Let me fix this properly. I keep making mistakes on the rangeId. Let me be very careful — the exact IDs from all_range_ids are:
Wait, let me re-check: WalkthroughTerraform configurations are updated with hardcoded S3 bucket names for state and uploads storage, the AWS provider constraint is bumped to ChangesTerraform Infrastructure Updates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (4)
terraform/bootstrap/main.tf (2)
18-25: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueConsider adding lifecycle configuration for state bucket.
State buckets can accumulate old versions over time. A lifecycle rule to expire non-current versions after a reasonable retention period (e.g., 90 days) helps manage storage costs while retaining recent history for recovery.
♻️ Example lifecycle configuration
resource "aws_s3_bucket_lifecycle_configuration" "tfstate" { bucket = aws_s3_bucket.tfstate.id rule { id = "expire-old-versions" status = "Enabled" noncurrent_version_expiration { noncurrent_days = 90 } } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@terraform/bootstrap/main.tf` around lines 18 - 25, The aws_s3_bucket resource named tfstate lacks lifecycle configuration to manage old versions of state files. Add a new aws_s3_bucket_lifecycle_configuration resource that references the tfstate bucket with a rule configured to expire non-current versions after 90 days. Include the id expire-old-versions, set status to Enabled, and configure noncurrent_version_expiration with noncurrent_days set to 90 to help manage storage costs while retaining recent history.Source: Linters/SAST tools
17-25: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winInconsistent naming approach: bucket hardcoded but DynamoDB uses variable.
The S3 bucket name is hardcoded (
serene-stay-tfstate-ramesh-98) while the DynamoDB table still derives its name fromvar.project_name(${var.project_name}-tfstate-lock). This creates inconsistency and could cause confusion during maintenance.Either hardcode both resources or use variables for both. If hardcoding is intentional for the bucket, consider the same approach for DynamoDB, or document why they differ.
Also applies to: 54-68
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@terraform/bootstrap/main.tf` around lines 17 - 25, The S3 bucket resource "tfstate" uses a hardcoded bucket name while the DynamoDB table resource (likely around lines 54-68) derives its name from var.project_name variable. Standardize the naming approach by either hardcoding both resource names consistently or using variables for both. If you choose to keep the S3 bucket name hardcoded as "serene-stay-tfstate-ramesh-98", update the DynamoDB table name in the aws_dynamodb_table resource to use a hardcoded value instead of var.project_name, or vice versa if you prefer the variable approach for both.terraform/main.tf (1)
23-23: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueNon-English comment may reduce code accessibility.
The inline comment is in Sinhala script. Consider using English comments for maintainability across international teams, or add an English translation alongside.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@terraform/main.tf` at line 23, Replace the non-English (Sinhala) inline comment on the bucket attribute assignment with either an English translation or remove it entirely if not necessary for code clarity. The comment appears on the same line as the bucket assignment in the terraform configuration and should be updated to use English only to ensure accessibility for international development teams.devops-aws (1)
1-1: 🧹 Nitpick | 🔵 TrivialConsider parameterizing
force_deletefor reusability across environments.
force_delete = trueis hardcoded at line 14 ofterraform/modules/ecr/main.tf. While this is appropriate for the current demo environment (environment defaults to"demo"), exposing it as a module variable would prevent accidental data loss if this code is reused in production contexts. Add a variable in the ECR module (default totruefor demo, conditionally set tofalsefor production) and pass it from the root module based on theenvironmentvariable.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@devops-aws` at line 1, The `force_delete = true` parameter is hardcoded in the ECR resource in the terraform/modules/ecr/main.tf file, which creates a risk for accidental data loss in production environments. Add a new variable in the ECR module (in the variables.tf file) called `force_delete` with a default value of `true`, then replace the hardcoded value in the ECR resource with a reference to this variable. Finally, update the root module to conditionally pass the `force_delete` variable based on the `environment` variable, setting it to `false` for production environments while keeping it as `true` for demo environments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@terraform/bootstrap/main.tf`:
- Line 5: The AWS provider version constraint in the bootstrap module specifies
`~> 5.100.0` while the root module terraform/main.tf uses `~> 5.0`, creating a
version mismatch. Update the version constraint in the bootstrap module to match
the root module by changing the version from `~> 5.100.0` to `~> 5.0` to ensure
consistent provider versions are used across both modules.
In `@terraform/main.tf`:
- Around line 22-27: The backend S3 configuration block is missing the encrypt
attribute which ensures Terraform encrypts state data during upload operations.
Add the encrypt = true attribute to the backend "s3" block alongside the
existing bucket, key, region, and dynamodb_table attributes to restore this
security layer.
In `@terraform/modules/database/main.tf`:
- Line 78: The backup_retention_period value at line 78 has been set to 1 day,
which conflicts with the documented 3-day retention standard in README.md Line
466 and weakens recovery capabilities. To fix this, either revert
backup_retention_period back to 3, or better yet, create a new variable called
var.backup_retention_days (with a default value of 3) in the variables file and
replace the hardcoded 1 with a reference to this variable. This allows non-demo
environments to maintain longer retention periods while still allowing ephemeral
stacks to override it if needed. Update the README.md documentation accordingly
to reflect the new variable-driven approach if implemented.
In `@terraform/modules/storage/main.tf`:
- Around line 7-9: Remove the unused `locals` block containing `name_prefix` and
replace the hardcoded bucket names (such as "demo" and "ramesh-98" and the
access_logs bucket) with dynamic naming that uses the `name_prefix` variable
derived from var.project_name and var.environment. This will restore proper
module reusability across different environments and projects by using the
intended variable-based naming scheme instead of hardcoded developer-specific
identifiers.
---
Nitpick comments:
In `@devops-aws`:
- Line 1: The `force_delete = true` parameter is hardcoded in the ECR resource
in the terraform/modules/ecr/main.tf file, which creates a risk for accidental
data loss in production environments. Add a new variable in the ECR module (in
the variables.tf file) called `force_delete` with a default value of `true`,
then replace the hardcoded value in the ECR resource with a reference to this
variable. Finally, update the root module to conditionally pass the
`force_delete` variable based on the `environment` variable, setting it to
`false` for production environments while keeping it as `true` for demo
environments.
In `@terraform/bootstrap/main.tf`:
- Around line 18-25: The aws_s3_bucket resource named tfstate lacks lifecycle
configuration to manage old versions of state files. Add a new
aws_s3_bucket_lifecycle_configuration resource that references the tfstate
bucket with a rule configured to expire non-current versions after 90 days.
Include the id expire-old-versions, set status to Enabled, and configure
noncurrent_version_expiration with noncurrent_days set to 90 to help manage
storage costs while retaining recent history.
- Around line 17-25: The S3 bucket resource "tfstate" uses a hardcoded bucket
name while the DynamoDB table resource (likely around lines 54-68) derives its
name from var.project_name variable. Standardize the naming approach by either
hardcoding both resource names consistently or using variables for both. If you
choose to keep the S3 bucket name hardcoded as "serene-stay-tfstate-ramesh-98",
update the DynamoDB table name in the aws_dynamodb_table resource to use a
hardcoded value instead of var.project_name, or vice versa if you prefer the
variable approach for both.
In `@terraform/main.tf`:
- Line 23: Replace the non-English (Sinhala) inline comment on the bucket
attribute assignment with either an English translation or remove it entirely if
not necessary for code clarity. The comment appears on the same line as the
bucket assignment in the terraform configuration and should be updated to use
English only to ensure accessibility for international development teams.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e17ac65c-b137-4299-903a-dfdee0ac50de
📒 Files selected for processing (5)
devops-awsterraform/bootstrap/main.tfterraform/main.tfterraform/modules/database/main.tfterraform/modules/storage/main.tf
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 5.0" | ||
| version = "~> 5.100.0" |
There was a problem hiding this comment.
Provider version constraint is inconsistent with root module.
The bootstrap module specifies ~> 5.100.0 while terraform/main.tf uses ~> 5.0. This could cause version drift or unexpected behavior if different provider versions are used between bootstrap and main infrastructure.
Consider aligning both constraints, either by using ~> 5.100.0 in both files or relaxing this to ~> 5.0 here as well.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@terraform/bootstrap/main.tf` at line 5, The AWS provider version constraint
in the bootstrap module specifies `~> 5.100.0` while the root module
terraform/main.tf uses `~> 5.0`, creating a version mismatch. Update the version
constraint in the bootstrap module to match the root module by changing the
version from `~> 5.100.0` to `~> 5.0` to ensure consistent provider versions are
used across both modules.
| backend "s3" { | ||
| bucket = "serene-stay-tfstate" | ||
| key = "demo/terraform.tfstate" | ||
| bucket = "serene-stay-tfstate-ramesh-98" # <- මෙන්න මේ නම විතරක් වෙනස් කරන්න | ||
| key = "dev/terraform.tfstate" | ||
| region = "us-east-1" | ||
| encrypt = true | ||
| dynamodb_table = "serene-stay-tfstate-lock" | ||
| } |
There was a problem hiding this comment.
Removed encrypt attribute from S3 backend configuration.
The encrypt = true attribute was removed from the backend block. While the bucket has server-side encryption configured, explicitly setting encrypt = true in the backend provides defense-in-depth by ensuring Terraform encrypts state data during upload operations.
🔒 Recommended fix
backend "s3" {
bucket = "serene-stay-tfstate-ramesh-98" # <- මෙන්න මේ නම විතරක් වෙනස් කරන්න
key = "dev/terraform.tfstate"
region = "us-east-1"
+ encrypt = true
dynamodb_table = "serene-stay-tfstate-lock"
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| backend "s3" { | |
| bucket = "serene-stay-tfstate" | |
| key = "demo/terraform.tfstate" | |
| bucket = "serene-stay-tfstate-ramesh-98" # <- මෙන්න මේ නම විතරක් වෙනස් කරන්න | |
| key = "dev/terraform.tfstate" | |
| region = "us-east-1" | |
| encrypt = true | |
| dynamodb_table = "serene-stay-tfstate-lock" | |
| } | |
| backend "s3" { | |
| bucket = "serene-stay-tfstate-ramesh-98" # <- මෙන්න මේ නම විතරක් වෙනස් කරන්න | |
| key = "dev/terraform.tfstate" | |
| region = "us-east-1" | |
| encrypt = true | |
| dynamodb_table = "serene-stay-tfstate-lock" | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@terraform/main.tf` around lines 22 - 27, The backend S3 configuration block
is missing the encrypt attribute which ensures Terraform encrypts state data
during upload operations. Add the encrypt = true attribute to the backend "s3"
block alongside the existing bucket, key, region, and dynamodb_table attributes
to restore this security layer.
|
|
||
| # Backups | ||
| backup_retention_period = 3 | ||
| backup_retention_period = 1 |
There was a problem hiding this comment.
Backup retention drop to 1 day weakens recovery guarantees and breaks the documented reliability contract.
At Line 78, changing retention to 1 reduces PITR/restore window and now conflicts with README.md Line 466 (3-day retention). If this module is shared beyond ephemeral demo stacks, keep 3 or make retention environment-driven (e.g., var.backup_retention_days) so non-demo environments preserve the longer window.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@terraform/modules/database/main.tf` at line 78, The backup_retention_period
value at line 78 has been set to 1 day, which conflicts with the documented
3-day retention standard in README.md Line 466 and weakens recovery
capabilities. To fix this, either revert backup_retention_period back to 3, or
better yet, create a new variable called var.backup_retention_days (with a
default value of 3) in the variables file and replace the hardcoded 1 with a
reference to this variable. This allows non-demo environments to maintain longer
retention periods while still allowing ephemeral stacks to override it if
needed. Update the README.md documentation accordingly to reflect the new
variable-driven approach if implemented.
| locals { | ||
| name_prefix = "${var.project_name}-${var.environment}" | ||
| bucket_name = "${var.project_name}-uploads-${var.environment}" | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Unused locals block and hardcoded bucket names reduce module reusability.
The name_prefix local is defined but no longer used since bucket names are now hardcoded. This:
- Leaves dead code (
locals.name_prefix) - Makes the module non-reusable across environments
- Embeds what appear to be developer-specific identifiers (
demo,ramesh-98) in the module
Consider either removing the module's parameterization entirely (if single-use is intentional) or restoring variable-based naming for proper module reusability.
♻️ Option: Restore variable-based naming
resource "aws_s3_bucket" "uploads" {
- bucket = "serene-stay-uploads-demo-ramesh-98"
+ bucket = "${local.name_prefix}-uploads"
tags = {
- Name = "serene-stay-uploads-demo-ramesh-98"
+ Name = "${local.name_prefix}-uploads"
}
}Similar change for access_logs bucket.
Also applies to: 13-18
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@terraform/modules/storage/main.tf` around lines 7 - 9, Remove the unused
`locals` block containing `name_prefix` and replace the hardcoded bucket names
(such as "demo" and "ramesh-98" and the access_logs bucket) with dynamic naming
that uses the `name_prefix` variable derived from var.project_name and
var.environment. This will restore proper module reusability across different
environments and projects by using the intended variable-based naming scheme
instead of hardcoded developer-specific identifiers.
Summary by CodeRabbit