Skip to content
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

68 add aws landing zone for the application plane #70

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dudizimber
Copy link
Collaborator

@dudizimber dudizimber commented Aug 22, 2024

fix #68

Summary by CodeRabbit

  • New Features

    • Introduced new Terraform configurations for managing AWS infrastructure, including organizational units and accounts.
    • Added S3 backend configurations for state management in multiple directories.
    • Implemented CloudTrail and S3 bucket management for logging.
  • Bug Fixes

    • Removed outdated workflows for GCP and AWS infrastructure testing.
    • Updated Cloud Build configuration to remove unnecessary environment variables.
  • Documentation

    • Updated variable declarations to enhance clarity and usability.
  • Chores

    • Deleted obsolete files and workflows to streamline the project structure.

- bootstrap
- org
- app plane

comment out actions
@dudizimber dudizimber linked an issue Aug 22, 2024 that may be closed by this pull request
Copy link

vercel bot commented Aug 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
falkordb-dbaas ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 7, 2024 2:13pm

Copy link

coderabbitai bot commented Aug 22, 2024

Walkthrough

The changes involve the deletion of several GitHub Actions workflow files related to Google Cloud Platform (GCP) and AWS infrastructure management, along with the introduction of new Terraform configuration files for AWS. The new configurations include backend settings for S3, provider specifications, and resource definitions for AWS Organizations and CloudTrail. The modifications reflect a shift in infrastructure management practices, emphasizing the use of Tofu for managing AWS resources and removing legacy configurations.

Changes

File Path Change Summary
.github/workflows/gcp-full-infra-test-apply.yaml Deleted workflow for applying GCP infrastructure changes.
.github/workflows/gcp-full-infra-test-plan.yaml Deleted workflow for testing GCP infrastructure creation and deletion.
.github/workflows/testing-apply-aws-infra.yaml Deleted workflow for testing AWS infrastructure application.
.github/workflows/testing-plan-aws-infra.yaml Deleted workflow for testing AWS infrastructure planning.
tofu/aws/.terraform.lock.hcl Deleted Terraform lock file for AWS provider configurations.
tofu/aws/1-bootstrap/.terraform.lock.hcl New Terraform lock file specifying AWS and random providers.
tofu/aws/1-bootstrap/backend.tf New S3 backend configuration for Terraform state management.
tofu/aws/1-bootstrap/main.tf New Terraform configuration for AWS resources, including S3 and AWS Organizations.
tofu/aws/1-bootstrap/outputs.tf New output variable for AWS Organizational Unit ID.
tofu/aws/1-bootstrap/providers.tf New provider configuration for AWS.
tofu/aws/1-bootstrap/variables.tf New variables for configuring AWS resources.
tofu/aws/2-org/.terraform.lock.hcl New Terraform lock file for AWS provider configurations.
tofu/aws/2-org/backend.tf New S3 backend configuration for Terraform state management.
tofu/aws/2-org/main.tf New resources for creating an AWS Organizational Unit and account.
tofu/aws/2-org/variables.tf New variables for configuring AWS Organizations.
tofu/aws/3-application_plane/.terraform.lock.hcl New Terraform lock file specifying AWS and random providers.
tofu/aws/3-application_plane/backend.tf New S3 backend configuration for Terraform state management.
tofu/aws/3-application_plane/main.tf New configuration for CloudTrail and S3 bucket management.
tofu/aws/3-application_plane/variables.tf New variables for configuring the application plane setup.
tofu/aws/main.tf Deleted comprehensive Terraform configuration for EKS and associated resources.
tofu/aws/outputs.tf Deleted output declarations related to the EKS configuration.
tofu/aws/variables.tf Deleted variable declarations used in the previous AWS configuration.

Poem

🐰 In the fields of code we play,
With Tofu guiding the way,
AWS blooms, new paths to find,
Old workflows left behind.
A hop, a skip, to the cloud we soar,
Building dreams, forevermore! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

remove flows
@dudizimber dudizimber marked this pull request as ready for review October 22, 2024 07:45
@dudizimber dudizimber requested a review from AviAvni October 22, 2024 07:45
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Outside diff range and nitpick comments (13)
tofu/aws/1-bootstrap/outputs.tf (1)

1-3: LGTM! Consider adding a description for clarity.

The output is correctly defined and references the Organizational Unit ID from the data source. This is a good practice for making the OU ID available for other modules or processes.

Consider adding a description to the output for better documentation:

 output "ou_id" {
+  description = "The ID of the AWS Organizational Unit used in this configuration."
   value = data.aws_organizations_organizational_unit.ou.id
 }
tofu/aws/1-bootstrap/backend.tf (1)

2-4: Consider removing the commented local backend configuration.

While transitioning to S3 backend, it's generally a good practice to remove unused code to maintain cleanliness and prevent confusion.

If you decide to keep the commented local backend for documentation or fallback purposes, please add a comment explaining why it's retained. Otherwise, consider removing these lines:

-  # backend "local" {
-  #   path = "bootstrap.tfstate"
-  # }
tofu/aws/2-org/variables.tf (4)

6-9: LGTM: Well-defined variable for workloads OU parent ID.

The variable workloads_ou_parent_id is correctly defined with an appropriate type and clear description. It pairs well with the previous workloads_ou_name variable.

Consider grouping related variables using comments or newlines for better readability, especially if more variables are added in the future.


11-14: LGTM: Well-defined variable for application plane account name.

The variable app_plane_account_name is correctly defined with an appropriate type and clear description.

For consistency with the previous variables, consider using "application" instead of "app" in the variable name, i.e., application_plane_account_name. This would make it more explicit and consistent with the description.


16-19: LGTM with suggestions: Well-defined variable for application plane account email.

The variable app_plane_account_email is correctly defined with an appropriate type and clear description.

Consider the following improvements:

  1. For consistency, rename to application_plane_account_email to match the full word used in the description.
  2. Add input validation for the email format. Here's an example of how you can do this:
variable "application_plane_account_email" {
  type        = string
  description = "Email of the application plane account"
  validation {
    condition     = can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", var.application_plane_account_email))
    error_message = "The application_plane_account_email must be a valid email address."
  }
}

This ensures that the provided email adheres to a basic email format, reducing the risk of input errors.


1-19: Overall: Well-structured variables file with room for minor improvements.

The variables in this file are well-defined and serve their purpose for AWS organization and account management. They provide flexibility for configuration and are appropriately typed.

To enhance readability and organization, consider grouping related variables with comments. Here's a suggested structure:

# Workloads Organizational Unit
variable "workloads_ou_name" {
  # ... (existing content)
}

variable "workloads_ou_parent_id" {
  # ... (existing content)
}

# Application Plane Account
variable "application_plane_account_name" {
  # ... (existing content, with suggested rename)
}

variable "application_plane_account_email" {
  # ... (existing content, with suggested rename and validation)
}

This structure clearly separates the two groups of variables, making the file easier to read and maintain as it grows.

tofu/aws/3-application_plane/variables.tf (1)

1-20: Well-structured variables file for AWS application plane configuration.

This variables file provides a solid foundation for configuring the application plane within an AWS Organizations setup. It includes essential variables for organizational unit management and CloudTrail log retention. The structure is consistent and follows Terraform best practices.

Consider adding comments to group related variables (e.g., OU-related, account-related, and logging-related) for improved readability as the file grows.

tofu/aws/1-bootstrap/variables.tf (3)

8-11: LGTM: Well-defined variable for parent OU ID

The ou_parent_id variable is correctly defined with an appropriate type and clear description.

Consider adding a note in the description about where to find this ID, e.g., "Can be obtained from the AWS Organizations console or API."


18-21: LGTM with suggestions: Well-defined variable for account email

The account_email variable is correctly defined with an appropriate type and description.

Consider the following improvements:

  1. Enhance the description to be more specific, e.g., "The email address associated with the AWS account to be created."
  2. Add input validation to ensure a valid email format. For example:
variable "account_email" {
  type        = string
  description = "The email address associated with the AWS account to be created."
  validation {
    condition     = can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", var.account_email))
    error_message = "The account_email must be a valid email address."
  }
}

23-26: LGTM with suggestions: Well-defined variable for AWS region

The region variable is correctly defined with an appropriate type and description.

Consider the following improvements:

  1. Enhance the description to be more specific about what bucket it refers to, e.g., "The AWS region where the S3 bucket for state storage will be created."
  2. Add input validation to ensure a valid AWS region is provided. For example:
variable "region" {
  type        = string
  description = "The AWS region where the S3 bucket for state storage will be created."
  validation {
    condition     = can(regex("^[a-z]{2}(-[a-z]+)+-\\d$", var.region))
    error_message = "The region must be a valid AWS region name, e.g., us-west-2."
  }
}
tofu/aws/2-org/main.tf (2)

8-20: LGTM with suggestions: AWS account resource is well-configured.

The aws_organizations_account resource is correctly defined with appropriate use of variables and dependencies. However, consider the following suggestions:

  1. The close_on_deletion = false setting prevents the account from being closed when the resource is destroyed. While this can be a safeguard, it may also lead to orphaned accounts. Consider if this aligns with your organization's security and resource management policies.

  2. The role_name is hardcoded. For consistency with other variables, consider making this configurable:

role_name = var.organization_account_access_role_name
  1. The lifecycle block ignores changes to role_name and name. Ensure this aligns with your change management processes, as it prevents updates to these fields via Terraform.

1-20: Overall structure aligns with AWS landing zone setup.

This Terraform configuration file effectively sets up the basic structure for an AWS Organizations landing zone. It creates a "workloads" Organizational Unit and an associated AWS account, which aligns with the PR objective of setting up an AWS landing zone for the application plane.

The use of variables throughout the configuration allows for flexibility and easier management of different environments or configurations. The dependency between resources ensures proper creation order.

Consider documenting the purpose of this configuration and any specific organizational policies (e.g., the reason for close_on_deletion = false) in comments at the top of the file for better maintainability.

tofu/aws/1-bootstrap/main.tf (1)

37-45: Rename resource "example" to a more descriptive name

The resource aws_s3_bucket_versioning is currently named example, which may cause confusion. Renaming it to something more descriptive improves code clarity.

Apply this diff to rename the resource:

-resource "aws_s3_bucket_versioning" "example" {
+resource "aws_s3_bucket_versioning" "terraform_state_versioning" {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 622da07 and db6c1a3.

📒 Files selected for processing (22)
  • .github/workflows/gcp-full-infra-test-apply.yaml (0 hunks)
  • .github/workflows/gcp-full-infra-test-plan.yaml (0 hunks)
  • .github/workflows/testing-apply-aws-infra.yaml (0 hunks)
  • .github/workflows/testing-plan-aws-infra.yaml (0 hunks)
  • tofu/aws/.terraform.lock.hcl (0 hunks)
  • tofu/aws/1-bootstrap/.terraform.lock.hcl (1 hunks)
  • tofu/aws/1-bootstrap/backend.tf (1 hunks)
  • tofu/aws/1-bootstrap/main.tf (1 hunks)
  • tofu/aws/1-bootstrap/outputs.tf (1 hunks)
  • tofu/aws/1-bootstrap/providers.tf (1 hunks)
  • tofu/aws/1-bootstrap/variables.tf (1 hunks)
  • tofu/aws/2-org/.terraform.lock.hcl (1 hunks)
  • tofu/aws/2-org/backend.tf (1 hunks)
  • tofu/aws/2-org/main.tf (1 hunks)
  • tofu/aws/2-org/variables.tf (1 hunks)
  • tofu/aws/3-application_plane/.terraform.lock.hcl (1 hunks)
  • tofu/aws/3-application_plane/backend.tf (1 hunks)
  • tofu/aws/3-application_plane/main.tf (1 hunks)
  • tofu/aws/3-application_plane/variables.tf (1 hunks)
  • tofu/aws/main.tf (0 hunks)
  • tofu/aws/outputs.tf (0 hunks)
  • tofu/aws/variables.tf (0 hunks)
💤 Files with no reviewable changes (8)
  • .github/workflows/gcp-full-infra-test-apply.yaml
  • .github/workflows/gcp-full-infra-test-plan.yaml
  • .github/workflows/testing-apply-aws-infra.yaml
  • .github/workflows/testing-plan-aws-infra.yaml
  • tofu/aws/.terraform.lock.hcl
  • tofu/aws/main.tf
  • tofu/aws/outputs.tf
  • tofu/aws/variables.tf
✅ Files skipped from review due to trivial changes (6)
  • tofu/aws/1-bootstrap/.terraform.lock.hcl
  • tofu/aws/1-bootstrap/providers.tf
  • tofu/aws/2-org/.terraform.lock.hcl
  • tofu/aws/2-org/backend.tf
  • tofu/aws/3-application_plane/.terraform.lock.hcl
  • tofu/aws/3-application_plane/backend.tf
🧰 Additional context used
🪛 checkov
tofu/aws/3-application_plane/main.tf

[HIGH] 58-69: Ensure Terraform module sources use a tag with a version number

(CKV_TF_2)

🔇 Additional comments (13)
tofu/aws/1-bootstrap/outputs.tf (1)

1-3: Verify the data source configuration.

Ensure that the aws_organizations_organizational_unit data source is properly configured in the main.tf file. This output depends on its correct setup.

Run the following script to check the data source configuration:

✅ Verification successful

Data source configuration is correctly set up.

All necessary variables for aws_organizations_organizational_unit are properly defined and referenced.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the aws_organizations_organizational_unit data source configuration

# Test: Search for the data source configuration
rg -A 5 'data\s+"aws_organizations_organizational_unit"\s+"ou"' tofu/aws/1-bootstrap/main.tf

# Test: Check for related variables that might be used in the data source
rg 'variable\s+.*ou' tofu/aws/1-bootstrap/variables.tf

Length of output: 412

tofu/aws/1-bootstrap/backend.tf (1)

1-9: LGTM: File structure and consistency are appropriate.

The overall structure of the file is correct for a Terraform backend configuration and aligns with the broader changes described in the PR objectives and AI summary.

tofu/aws/2-org/variables.tf (1)

1-4: LGTM: Well-defined variable for workloads OU name.

The variable workloads_ou_name is correctly defined with an appropriate type and clear description. It's good practice to define these as variables for flexibility.

tofu/aws/3-application_plane/variables.tf (4)

1-4: LGTM: Well-defined variable for workloads OU name.

The variable declaration is clear, with an appropriate type and description. Requiring this value to be provided ensures explicit configuration of the workloads OU.


6-9: LGTM: Well-defined variable for workloads OU parent ID.

The variable declaration is clear, with an appropriate type and description. Requiring this value to be provided ensures explicit configuration of the parent OU for workloads.


11-14: LGTM: Well-defined variable for application plane account name.

The variable declaration is clear, with an appropriate type and description. Requiring this value to be provided ensures explicit naming of the application plane account.


16-20: LGTM: Well-defined variable for CloudTrail log retention, but verify the default value.

The variable declaration is clear, with an appropriate type and description. The default value of 90 days for CloudTrail log retention is reasonable, but it's worth verifying if this aligns with your organization's data retention policies and compliance requirements.

To ensure compliance, please run the following script to check for any existing CloudTrail retention policies in the AWS Organizations:

tofu/aws/1-bootstrap/variables.tf (3)

3-6: LGTM: Well-defined variable for OU name

The ou_name variable is correctly defined with an appropriate type and clear description.


13-16: LGTM: Well-defined variable for account name

The account_name variable is correctly defined with an appropriate type and clear description.


1-26: Overall: Well-structured and comprehensive variables file

This variables.tf file provides a solid foundation for configuring AWS resources related to Organizations and account creation. The variables are well-named, typed, and described. Minor suggestions have been made to enhance descriptions and add input validations for improved robustness.

tofu/aws/2-org/main.tf (1)

1-5: LGTM: Organizational Unit resource is well-defined.

The aws_organizations_organizational_unit resource is correctly configured using variables for flexibility. This approach allows for easy modifications to the OU name and parent ID without changing the main code.

tofu/aws/1-bootstrap/main.tf (2)

16-17: Verify that the account email is unique and valid

The email parameter in aws_organizations_account must be unique across all AWS accounts. Ensure that var.account_email is not already in use to prevent account creation failures.


47-58: Review object lock configuration for compliance requirements

While the object lock is set to COMPLIANCE mode with a retention period of 14 days, ensure this configuration aligns with your organization's compliance policies.

Would you like assistance in verifying the compliance settings or adjusting the configuration?

Comment on lines +6 to +8
backend "s3" {

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Populate the S3 backend configuration with required parameters.

The S3 backend block is currently empty. To ensure proper state management, please add the necessary configuration parameters.

Consider adding the following parameters to the S3 backend configuration:

backend "s3" {
  bucket         = "your-terraform-state-bucket-name"
  key            = "bootstrap/terraform.tfstate"
  region         = "your-aws-region"
  encrypt        = true
  dynamodb_table = "your-terraform-state-lock-table-name"
}

Replace the placeholder values with your actual AWS resource names and region. Also, ensure that the S3 bucket and DynamoDB table for state locking are created beforehand or in a separate bootstrapping process.

Comment on lines +23 to +29
provider "aws" {
alias = "seed-account"
region = var.region
assume_role {
role_arn = "arn:aws:iam::${aws_organizations_account.account.id}:role/OrganizationAccountAccessRole"
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure the new account's IAM role is available before assuming it

After creating a new AWS account with aws_organizations_account, there might be a delay before the OrganizationAccountAccessRole is fully available. This delay can cause the seed-account provider to fail when attempting to assume the role immediately.

Consider adding a dependency to ensure that the account is fully provisioned before the provider attempts to assume the role. You can add a depends_on attribute to the provider configuration:

 provider "aws" {
   alias  = "seed-account"
   region = var.region
+  depends_on = [aws_organizations_account.account]
   assume_role {
     role_arn = "arn:aws:iam::${aws_organizations_account.account.id}:role/OrganizationAccountAccessRole"
   }
 }
📝 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.

Suggested change
provider "aws" {
alias = "seed-account"
region = var.region
assume_role {
role_arn = "arn:aws:iam::${aws_organizations_account.account.id}:role/OrganizationAccountAccessRole"
}
}
provider "aws" {
alias = "seed-account"
region = var.region
depends_on = [aws_organizations_account.account]
assume_role {
role_arn = "arn:aws:iam::${aws_organizations_account.account.id}:role/OrganizationAccountAccessRole"
}
}

Comment on lines +31 to +35
resource "aws_s3_bucket" "terraform_state" {
bucket = "tf-state-${random_id.suffix.hex}"

provider = aws.seed-account
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure the S3 bucket name is globally unique

The bucket name tf-state-${random_id.suffix.hex} might not be sufficiently unique globally, potentially leading to naming conflicts.

Consider incorporating the AWS account ID or another unique identifier to ensure global uniqueness:

 bucket = "tf-state-${aws_organizations_account.account.id}-${random_id.suffix.hex}"

Committable suggestion was skipped due to low confidence.

}),
{}
)
app_plane_account = local.workload_accounts[var.app_plane_account_name]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle potential null value for 'app_plane_account'

local.app_plane_account may be null if var.app_plane_account_name does not exist in local.workload_accounts. This could lead to errors when accessing local.app_plane_account.id in the provider configuration.

Consider adding a validation to ensure local.app_plane_account is defined:

locals {
  # Existing locals...

  app_plane_account = try(local.workload_accounts[var.app_plane_account_name], null)
}

# Add validation
resource "null_resource" "validate_app_plane_account" {
  provisioner "local-exec" {
    command = <<EOT
if [ "${local.app_plane_account}" == "null" ]; then
  echo "Error: app_plane_account is null. Verify that var.app_plane_account_name is correct."
  exit 1
fi
EOT
  }
}

Alternatively, use Terraform's validation block:

variable "app_plane_account_name" {
  type        = string
  description = "Name of the application plane account"

  validation {
    condition     = local.app_plane_account != null
    error_message = "The provided app_plane_account_name does not exist in workload_accounts."
  }
}

{}
)
app_plane_account = local.workload_accounts[var.app_plane_account_name]
app_plane_trail_bucket_name = nonsensitive("${lower(replace(var.app_plane_account_name, " ", "-"))}-cloudtrail-${random_bytes.suffix.hex}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Bucket name length may exceed 63 characters. Implement truncation or validation to ensure compliance.

  • Consider truncating var.app_plane_account_name in tofu/aws/3-application_plane/main.tf to maintain the bucket name within the 63-character limit.
🔗 Analysis chain

Ensure S3 bucket name does not exceed the length limit

The generated S3 bucket name may exceed the AWS S3 bucket name length limit of 63 characters, especially if var.app_plane_account_name is long. Consider truncating or validating the bucket name to ensure compliance.

Run the following script to check the length of the generated bucket name:

If the bucket name is too long, consider modifying line 19 as follows:

 app_plane_trail_bucket_name = nonsensitive("${lower(replace(substr(var.app_plane_account_name, 0, N), " ", "-"))}-cloudtrail-${random_bytes.suffix.hex}")

Replace N with a suitable number to truncate the account name appropriately.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the bucket name length exceeds 63 characters

# Substitute the actual values for APP_PLANE_ACCOUNT_NAME and SUFFIX
APP_PLANE_ACCOUNT_NAME="your-app-plane-account-name"
SUFFIX="your-random-bytes-suffix"

BUCKET_NAME="$(echo "${APP_PLANE_ACCOUNT_NAME,,}" | tr ' ' '-')-cloudtrail-${SUFFIX}"
BUCKET_NAME_LENGTH=${#BUCKET_NAME}

echo "Bucket Name: $BUCKET_NAME"
echo "Bucket Name Length: $BUCKET_NAME_LENGTH"

if [ "$BUCKET_NAME_LENGTH" -gt 63 ]; then
  echo "Error: Bucket name exceeds 63 characters."
else
  echo "Bucket name length is within the limit."
fi

Length of output: 563


Script:

#!/bin/bash
# Description: Find the definition of var.app_plane_account_name and check for length constraints

# Search for the variable definition in Terraform files
rg 'variable\s+"app_plane_account_name"' --type tf --context 5

# Search for any validation rules related to the variable
rg 'validation\s+\{' --type tf --context 5 | rg 'var\.app_plane_account_name' --context 2

Length of output: 1455

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (8)
tofu/aws/3-application_plane/variables.tf (3)

1-9: Add validation blocks for OU-related variables.

While the variables are well-structured, consider adding validation blocks to enforce AWS Organizations naming constraints and parent ID format.

 variable "workloads_ou_name" {
   type        = string
   description = "Name of the OU for workloads"
+  validation {
+    condition     = can(regex("^[a-zA-Z0-9-_ ]+$", var.workloads_ou_name))
+    error_message = "OU name must only contain alphanumeric characters, hyphens, underscores, and spaces."
+  }
 }

 variable "workloads_ou_parent_id" {
   type        = string
   description = "Parent OU ID for workloads"
+  validation {
+    condition     = can(regex("^ou-[0-9a-z]{4,32}-[a-z0-9]{8,32}$", var.workloads_ou_parent_id))
+    error_message = "Parent OU ID must be a valid AWS Organizations OU ID format (e.g., ou-xxxx-yyyyyyyy)."
+  }
 }

11-14: Enhance account name variable with validation and clearer description.

The account name variable should include AWS-specific constraints and a more detailed description.

 variable "app_plane_account_name" {
   type        = string
-  description = "Name of the application plane account"
+  description = "Name of the application plane AWS account (must be between 1-50 characters)"
+  validation {
+    condition     = length(var.app_plane_account_name) >= 1 && length(var.app_plane_account_name) <= 50
+    error_message = "Account name must be between 1 and 50 characters."
+  }
 }

16-20: Add validation and documentation for CloudTrail retention.

The retention period should have a minimum value and include documentation about compliance considerations.

 variable "cloudtrail_retention_days" {
   type        = number
-  description = "Number of days to retain CloudTrail logs"
+  description = <<EOT
+  Number of days to retain CloudTrail logs.
+  Default is 90 days to meet common compliance requirements.
+  Minimum recommended value is 30 days.
+  EOT
   default     = 90
+  validation {
+    condition     = var.cloudtrail_retention_days >= 30
+    error_message = "CloudTrail retention period must be at least 30 days for security best practices."
+  }
 }
backend/services/auth/cloudbuild.dev.yaml (1)

35-35: Improve readability of environment variables.

The long line of environment variables could be split for better readability and maintainability.

Consider reformatting like this:

-      - NODE_ENV=${_NODE_ENV},MONGODB_DB=${_MONGODB_DB},FALKORDB_AUTH_URL=${_FALKORDB_AUTH_URL},FALKORDB_ORGANIZATIONS_URL=${_FALKORDB_ORGANIZATIONS_URL},FALKORDB_PROVISIONER_URL=${_FALKORDB_PROVISIONER_URL},FALKORDB_USERS_URL=${_FALKORDB_USERS_URL},RECOVER_PASSWORD_RETURN_URL=${_RECOVER_PASSWORD_RETURN_URL},GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT},MOCK_CAPTCHA_REPOSITORY=${_MOCK_CAPTCHA_REPOSITORY},MOCK_MESSAGING_REPOSITORY=${_MOCK_MESSAGING_REPOSITORY}
+      - >-
+        NODE_ENV=${_NODE_ENV},
+        MONGODB_DB=${_MONGODB_DB},
+        FALKORDB_AUTH_URL=${_FALKORDB_AUTH_URL},
+        FALKORDB_ORGANIZATIONS_URL=${_FALKORDB_ORGANIZATIONS_URL},
+        FALKORDB_PROVISIONER_URL=${_FALKORDB_PROVISIONER_URL},
+        FALKORDB_USERS_URL=${_FALKORDB_USERS_URL},
+        RECOVER_PASSWORD_RETURN_URL=${_RECOVER_PASSWORD_RETURN_URL},
+        GOOGLE_CLOUD_PROJECT=${_GOOGLE_CLOUD_PROJECT},
+        MOCK_CAPTCHA_REPOSITORY=${_MOCK_CAPTCHA_REPOSITORY},
+        MOCK_MESSAGING_REPOSITORY=${_MOCK_MESSAGING_REPOSITORY}
tofu/aws/3-application_plane/main.tf (4)

2-9: Add error handling for organizational unit data sources

The data sources look correct, but consider adding validation to ensure the OU exists and contains child accounts.

variable "workloads_ou_name" {
  # ... existing configuration ...
  validation {
    condition     = can(regex("^[a-zA-Z0-9-_ ]+$", var.workloads_ou_name))
    error_message = "OU name must contain only alphanumeric characters, hyphens, underscores, and spaces."
  }
}

28-33: Consider parameterizing the IAM role name

The OrganizationAccountAccessRole is hardcoded. Consider making it configurable for flexibility.

 provider "aws" {
   alias = "app-plane-account"
   assume_role {
-    role_arn = "arn:aws:iam::${local.app_plane_account.id}:role/OrganizationAccountAccessRole"
+    role_arn = "arn:aws:iam::${local.app_plane_account.id}:role/${var.organization_access_role_name}"
   }
 }

95-106: Add lifecycle rules for access logs retention

Consider adding lifecycle rules to manage the retention of access logs.

 module "aws-s3-bucket-access-logs" {
   source                   = "trussworks/s3-private-bucket/aws"
   bucket                   = local.app_plane_access_logs_bucket_name
   use_account_alias_prefix = false
   enable_analytics         = false
+  lifecycle_rules = [{
+    enabled = true
+    expiration = {
+      days = 90  # Adjust retention period as needed
+    }
+  }]
🧰 Tools
🪛 checkov

[HIGH] 95-106: Ensure Terraform module sources use a tag with a version number

(CKV_TF_2)


108-120: Document why CloudTrail module is commented out

Add a comment explaining why the CloudTrail module is disabled and under what conditions it should be enabled.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between db6c1a3 and 0335aa4.

📒 Files selected for processing (3)
  • backend/services/auth/cloudbuild.dev.yaml (1 hunks)
  • tofu/aws/3-application_plane/main.tf (1 hunks)
  • tofu/aws/3-application_plane/variables.tf (1 hunks)
🧰 Additional context used
🪛 checkov
tofu/aws/3-application_plane/main.tf

[HIGH] 59-70: Ensure Terraform module sources use a tag with a version number

(CKV_TF_2)


[HIGH] 95-106: Ensure Terraform module sources use a tag with a version number

(CKV_TF_2)

🔇 Additional comments (5)
tofu/aws/3-application_plane/variables.tf (1)

22-26: 🛠️ Refactor suggestion

Add ARN validation and verify security implications.

The variable needs ARN format validation, and the security implications of an empty default list should be verified.

 variable "app_plane_lb_bucket_access_allow_list" {
   type        = list(string)
-  description = "List of ARNs of load balancers that are allowed to write to the access logs bucket"
+  description = <<EOT
+  List of ARNs of load balancers that are allowed to write to the access logs bucket.
+  IMPORTANT: An empty list means no load balancers can write access logs.
+  EOT
   default     = []
+  validation {
+    condition     = alltrue([for arn in var.app_plane_lb_bucket_access_allow_list : can(regex("^arn:aws:elasticloadbalancing:[a-z0-9-]+:[0-9]{12}:loadbalancer/.+$", arn))])
+    error_message = "All entries must be valid AWS load balancer ARNs."
+  }
 }

Let's verify how this variable is used in the codebase:

backend/services/auth/cloudbuild.dev.yaml (1)

35-35: Verify service dependencies are correctly configured.

The auth service appears to depend on several other microservices. Let's verify these dependencies are correctly configured.

✅ Verification successful

The previous results showed that all services have URLs configured, but we need to verify the actual usage patterns to ensure there are no circular dependencies and the configurations are properly used. This will help us understand if the dependencies are correctly configured and actually needed.


The previous results showed that all services have the URLs configured in their environment schemas and app initialization, but we need to verify the actual HTTP client usage to understand the real service-to-service communication patterns and validate if all configured dependencies are actually needed.


Service dependencies are correctly configured and justified by the codebase

The analysis of the codebase shows that the service dependencies are properly configured and actively used:

  1. Auth service uses:

    • Users service: For user deletion and management
    • Organizations service: For authentication flows
  2. Organizations service uses:

    • Users service: For member management and invitation flows
    • Auth service: For user verification
  3. Users service uses:

    • Organizations service: For membership and invitation management

Each configured URL in cloudbuild.dev.yaml corresponds to actual service-to-service communication patterns found in the codebase, with clear separation of concerns and no circular dependencies. The implementations show proper usage through repository patterns and service layers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the service URLs are consistent across the codebase
# and check for any potential circular dependencies.

echo "Checking for service URL references..."
rg --type yaml "FALKORDB_(AUTH|ORGANIZATIONS|PROVISIONER|USERS)_URL" -A 2

echo "Checking for potential circular dependencies in Cloud Build configs..."
fd -e yaml -e yml cloudbuild --exec grep -l "FALKORDB.*_URL"

Length of output: 3861


Script:

#!/bin/bash
# Let's check the actual service implementations to understand the dependencies better

echo "Checking service-to-service calls in auth service..."
rg -t ts -t js "FALKORDB.*_URL" ./backend/services/auth/src -C 2

echo "Checking service-to-service calls in organizations service..."
rg -t ts -t js "FALKORDB.*_URL" ./backend/services/organizations/src -C 2

echo "Checking service-to-service calls in users service..."
rg -t ts -t js "FALKORDB.*_URL" ./backend/services/users/src -C 2

Length of output: 5769


Script:

#!/bin/bash
# Let's check for actual HTTP client usage to understand the real service dependencies

echo "Checking HTTP client calls in auth service..."
rg -t ts -t js "\.get\(|\.post\(|\.put\(|\.delete\(" ./backend/services/auth/src -C 2

echo "Checking HTTP client calls in organizations service..."
rg -t ts -t js "\.get\(|\.post\(|\.put\(|\.delete\(" ./backend/services/organizations/src -C 2

echo "Checking HTTP client calls in users service..."
rg -t ts -t js "\.get\(|\.post\(|\.put\(|\.delete\(" ./backend/services/users/src -C 2

Length of output: 27065

tofu/aws/3-application_plane/main.tf (3)

23-25: LGTM! Good choice of suffix length

The 4-byte random suffix provides sufficient uniqueness while keeping bucket names concise.


36-56: LGTM! Well-structured IAM policy

The policy correctly implements least privilege by granting only necessary permissions to CloudTrail service.


72-93: LGTM! Well-structured access logs policy

The policy correctly grants necessary permissions for S3 access logging service.

Comment on lines +19 to +20
app_plane_trail_bucket_name = nonsensitive("${lower(replace(var.app_plane_account_name, " ", "-"))}-cloudtrail-${random_bytes.suffix.hex}")
app_plane_access_logs_bucket_name = nonsensitive("${lower(replace(var.app_plane_account_name, " ", "-"))}-access-logs-${random_bytes.suffix.hex}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for S3 bucket name length

The bucket names are generated using account name and random suffix. Add validation to ensure they don't exceed AWS S3's 63-character limit.

locals {
  validate_bucket_name = {
    for name in [local.app_plane_trail_bucket_name, local.app_plane_access_logs_bucket_name] :
    name => regex("^.{1,63}$", name)
  }
}

Comment on lines +59 to +70
module "aws-s3-bucket" {
source = "trussworks/s3-private-bucket/aws"
bucket = local.app_plane_trail_bucket_name
use_account_alias_prefix = false
enable_analytics = false

custom_bucket_policy = data.aws_iam_policy_document.cloudtrail_bucket_policy.json

providers = {
aws = aws.app-plane-account
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enable server-side encryption for CloudTrail bucket

Consider enabling server-side encryption for additional security of CloudTrail logs.

 module "aws-s3-bucket" {
   source                   = "trussworks/s3-private-bucket/aws"
   bucket                   = local.app_plane_trail_bucket_name
   use_account_alias_prefix = false
   enable_analytics         = false
+  enable_default_encryption = true
+  encryption_key_arn       = var.kms_key_arn  # Add this variable

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 checkov

[HIGH] 59-70: Ensure Terraform module sources use a tag with a version number

(CKV_TF_2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add AWS landing zone for the application plane
1 participant