Skip to content

Conversation

goruha
Copy link
Contributor

@goruha goruha commented Jan 2, 2025

what

  • Add tests

Summary by CodeRabbit

  • New Features

    • Enhanced configurations for certificate, DNS, and account mapping management.
    • Introduced flexible CLI and vendor configuration options to streamline environment setup.
    • Added new components for DNS and ACM configurations.
  • Tests

    • Added comprehensive integration tests to validate certificate issuance and DNS record setups.
    • Introduced new test configurations for various components to ensure proper functionality.
  • Chores

    • Upgraded module versions and improved dependency management.
    • Refined version control exclusions and removed outdated test scripts.

@goruha goruha requested a review from a team as a code owner January 2, 2025 21:04
Copy link

coderabbitai bot commented Jan 2, 2025

Walkthrough

The changes consist of updates to ignore patterns in Git configuration files, version upgrades to Terraform modules within the remote state configuration, and the addition of a comprehensive testing framework for an AWS ACM component. New YAML configuration files have been added to define various Terraform components and vendor dependencies. A new Go module file has been introduced to manage dependencies, and an outdated test runner script has been removed.

Changes

File(s) Change Summary
.gitignore, test/.gitignore Added ignore patterns: .cache (in global and test) plus additional patterns in the test directory (e.g., state/, test/test-suite.json, .atmos, test_suite.yaml)
src/remote-state.tf Updated module versions for private_ca and dns_delegated from 1.5.0 to 1.8.0
test/component_test.go Introduced a new test file implementing a comprehensive testing suite for an AWS ACM component integration with DNS via Route 53 and SSM
test/fixtures/atmos.yaml Added new Atmos CLI configuration with settings for components, stacks, workflows, and logging
test/fixtures/stacks/catalog/account-map.yaml,
test/fixtures/stacks/catalog/dns-delegated.yaml,
test/fixtures/stacks/catalog/dns-primary.yaml
Added new YAML configurations defining Terraform components for account mapping, DNS delegated, and DNS primary respectively
test/fixtures/stacks/catalog/usecase/basic.yaml,
test/fixtures/stacks/catalog/usecase/disabled.yaml
Introduced new use case configurations for ACM components: one enabled (acm/basic) and one disabled (acm/disabled)
test/fixtures/stacks/orgs/default/test/_defaults.yaml,
test/fixtures/stacks/orgs/default/test/tests.yaml
Added new configurations for Terraform backend settings and an import section for shared test configurations
test/fixtures/vendor.yaml Introduced an Atmos vendor configuration defining vendor components with metadata and source dependency details
test/go.mod Added a new Go module file with specified Go version (1.23.0) and multiple dependencies including direct and indirect packages
test/run.sh Removed the Bash script that previously served as a simple test runner

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestRunner
    participant ComponentSuite
    participant AWS_ACM
    participant Route53
    participant SSM

    User->>TestRunner: Initiate TestRunSuite
    TestRunner->>ComponentSuite: Execute TestBasic
    ComponentSuite->>AWS_ACM: Request certificate details
    AWS_ACM-->>ComponentSuite: Return Certificate ID & ARN
    ComponentSuite->>Route53: Validate DNS records for domain
    ComponentSuite->>SSM: Verify ACM ARN in Parameter Store
    ComponentSuite-->>TestRunner: Report test results
Loading

Suggested labels

auto-update, no-release, migration

Poem

Oh what a hop, what a bound,
Changes in files all around.
New tests and configs, neat and spry,
AWS and DNS reach for the sky.
I'm just a rabbit, thrilled to see,
Code dancing in perfect harmony.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8db27d3 and e17c660.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • test/fixtures/atmos.yaml (1 hunks)
  • test/fixtures/vendor.yaml (1 hunks)
  • test/go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • test/fixtures/vendor.yaml
  • test/go.mod
  • test/fixtures/atmos.yaml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

mergify bot commented Jan 2, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require terratest

Wonderful, this rule succeeded.

This rule require terratest status

  • check-success = test/terratest

@mergify mergify bot added the needs-test Needs testing label Jan 2, 2025
@goruha
Copy link
Contributor Author

goruha commented Jan 2, 2025

/terratest

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: 7

🧹 Nitpick comments (11)
test/fixtures/stacks/orgs/default/test/_defaults.yaml (1)

10-14: Reduce configuration duplication

The remote_state_backend configuration is identical to the main backend configuration. Consider using a shared variable or template.

test/fixtures/stacks/catalog/dns-primary.yaml (2)

6-6: Remove trailing spaces

A trailing space is reported in line 6. Consider removing it to comply with lint rules.

  vars: 
-  
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)


9-9: Add a newline at the end of file

A missing newline is reported in line 9. Consider adding it to comply with lint rules.

  record_config: []
+ 
🧰 Tools
🪛 yamllint (1.35.1)

[error] 9-9: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/stacks/catalog/dns-delegated.yaml (1)

10-10: Remove trailing spaces

A trailing space is reported in line 10. Consider removing it to comply with lint rules.

   request_acm_certificate: false  
-  
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 10-10: trailing spaces

(trailing-spaces)

test/fixtures/stacks/catalog/usecase/basic.yaml (1)

6-6: Remove trailing spaces

A trailing space is reported in line 6. Consider removing it to comply with lint rules.

   vars: 
-  
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)

test/fixtures/vendor.yaml (2)

45-46: Consider using absolute Git URL for source

Using a relative path ../../src for the acm component could be problematic in different environments or when the repository structure changes. Consider using the same GitHub URL pattern as other components for consistency and reliability.

-      source: "../../src"
+      source: github.com/cloudposse-terraform-components/aws-acm.git//src?ref={{.Version}}

13-53: Consider DRYing up repeated patterns

All components share identical included/excluded paths. Consider extracting these common patterns into a reusable template or using YAML anchors to reduce duplication.

Example using YAML anchors:

spec:
  defaults: &default_paths
    included_paths:
      - "**/*.tf"
      - "**/*.md"
      - "**/*.tftmpl"
      - "**/modules/**"
    excluded_paths: []
  
  sources:
    - component: "account-map"
      <<: *default_paths
      # other specific configs...
🧰 Tools
🪛 yamllint (1.35.1)

[error] 34-34: trailing spaces

(trailing-spaces)

test/fixtures/stacks/catalog/account-map.yaml (1)

11-22: Remove or properly document commented configuration

The commented remote state backend configuration appears to be internal Cloud Posse test infrastructure. Consider either:

  1. Removing it completely if it's not needed
  2. Moving it to documentation if it's an example
  3. Adding more context about when it should be uncommented
src/main.tf (1)

33-33: Consider adding error handling for zone lookup

While the splat expression [*] is a good practice, the join() will silently return an empty string if the zone lookup fails. Consider adding explicit error handling or validation.

-  zone_id = join("", data.aws_route53_zone.default[*].zone_id)
+  zone_id = length(data.aws_route53_zone.default) > 0 ? data.aws_route53_zone.default[0].zone_id : (
+    var.process_domain_validation_options ? 
+    file("ERROR: Route53 zone not found for ${var.zone_name}") : null
+  )
test/fixtures/atmos.yaml (1)

79-87: Enhance test command output format

The test-components command uses a complex jq pipeline to filter components. Consider improving readability and maintainability.

- atmos describe stacks --format json --sections=component,metadata --components=component -s sandbox
-        | jq '.[] | .components.terraform | to_entries | 
-        map(select(.value.component == "component" and (.value.metadata.type != "abstract" or .value.metadata.type == null))) 
-        | .[].key' 
+ atmos describe stacks \
+   --format json \
+   --sections=component,metadata \
+   --components=component \
+   -s sandbox \
+   | jq '
+     .[] 
+     | .components.terraform 
+     | to_entries 
+     | map(
+         select(
+           .value.component == "component" 
+           and (.value.metadata.type != "abstract" or .value.metadata.type == null)
+         )
+       ) 
+     | .[].key
+   '
🧰 Tools
🪛 yamllint (1.35.1)

[error] 85-85: trailing spaces

(trailing-spaces)


[error] 86-86: trailing spaces

(trailing-spaces)


[error] 87-87: trailing spaces

(trailing-spaces)

test/go.mod (1)

19-19: Organize and deduplicate dependencies

The file has multiple require blocks and some potential duplicate dependencies. Consider consolidating them into a single block.

Run go mod tidy to clean up and organize dependencies:

#!/bin/bash
cd test && go mod tidy

Also applies to: 21-91

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01a60ea and 4111870.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (15)
  • .gitignore (1 hunks)
  • src/main.tf (1 hunks)
  • src/remote-state.tf (2 hunks)
  • test/.gitignore (1 hunks)
  • test/component_test.go (1 hunks)
  • test/fixtures/atmos.yaml (1 hunks)
  • test/fixtures/stacks/catalog/account-map.yaml (1 hunks)
  • test/fixtures/stacks/catalog/dns-delegated.yaml (1 hunks)
  • test/fixtures/stacks/catalog/dns-primary.yaml (1 hunks)
  • test/fixtures/stacks/catalog/usecase/basic.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/_defaults.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/tests.yaml (1 hunks)
  • test/fixtures/vendor.yaml (1 hunks)
  • test/go.mod (1 hunks)
  • test/run.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • test/run.sh
✅ Files skipped from review due to trivial changes (4)
  • test/.gitignore
  • .gitignore
  • src/remote-state.tf
  • test/fixtures/stacks/orgs/default/test/tests.yaml
🧰 Additional context used
🪛 yamllint (1.35.1)
test/fixtures/stacks/catalog/dns-primary.yaml

[error] 6-6: trailing spaces

(trailing-spaces)


[error] 9-9: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/vendor.yaml

[error] 34-34: trailing spaces

(trailing-spaces)

test/fixtures/stacks/catalog/usecase/basic.yaml

[error] 6-6: trailing spaces

(trailing-spaces)

test/fixtures/stacks/catalog/dns-delegated.yaml

[error] 10-10: trailing spaces

(trailing-spaces)

test/fixtures/atmos.yaml

[error] 85-85: trailing spaces

(trailing-spaces)


[error] 86-86: trailing spaces

(trailing-spaces)


[error] 87-87: trailing spaces

(trailing-spaces)

🔇 Additional comments (9)
test/fixtures/stacks/orgs/default/test/_defaults.yaml (5)

1-3: LGTM: Import configuration is properly structured

The import of the account-map catalog is correctly specified.


15-40: LGTM: Well-structured variable configuration

The variable configuration follows best practices with clear label ordering and descriptor formats.


48-49: Security: Review email domain exposure

The hardcoded email domain 'example.com' appears to be a placeholder. Ensure this is intentional for testing purposes.


70-71: Verify empty terraform role configuration

The terraform role for 'default-test' is empty. Verify if this is intentional for testing purposes.

Run this script to check if empty roles are used elsewhere in test configurations:

✅ Verification successful

Let me try a different approach to search for terraform role configurations in test fixtures. The previous regex had syntax issues, so I'll use a simpler search pattern to analyze the context.


Empty terraform role configurations are used consistently in test fixtures

The empty terraform role configurations appear to be intentionally used in test fixtures:

  • In test/fixtures/stacks/orgs/default/test/_defaults.yaml: empty string value ('') for default-test
  • In test/fixtures/stacks/catalog/account-map.yaml: empty object ({})

This pattern of using empty configurations in test fixtures is consistent and appears to be intentional for testing purposes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar test configurations with empty terraform roles
rg -l "terraform_roles:" | xargs rg "terraform_roles:(\s+\w+:\s*''|\s*{})"

Length of output: 233


Script:

#!/bin/bash
# Search for terraform_roles configurations in test fixtures
rg -A 5 "terraform_roles:" test/fixtures/

Length of output: 284


50-50: Verify TEST_ACCOUNT_ID usage

The TEST_ACCOUNT_ID environment variable is used in multiple places with a default placeholder value. Ensure that:

  1. The placeholder <TEST_ACCOUNT_ID> won't cause issues if used accidentally
  2. The test framework properly sets this environment variable

Run this script to verify TEST_ACCOUNT_ID usage in tests:

Also applies to: 65-65, 67-67

test/component_test.go (1)

153-157: Impressive domain validation test coverage!

Verifying that the DNS record matches the ACM resource record value confirms your domain ownership. No improvements needed here.

src/main.tf (1)

Line range hint 1-1: Where are the actual test files?

The PR objective is to "Add tests" and the comment "/terratest" suggests using the Terratest framework. However, I don't see any actual test files (e.g., *_test.go) in this review. Could you please ensure that:

  1. The Terratest files are included in the PR
  2. The tests cover the main functionality of the ACM module
  3. The tests validate both successful and error scenarios
✅ Verification successful

Let me check the content of the test file to verify its completeness.


Test files are present and comprehensive

The PR includes a well-structured Terratest file (test/component_test.go) that thoroughly tests the ACM module functionality. The test:

  • Sets up required DNS infrastructure
  • Validates ACM certificate creation and configuration
  • Verifies DNS validation records
  • Checks SSM parameter storage
  • Includes proper cleanup in teardown
  • Contains multiple assertions validating the expected behavior
  • Handles error scenarios with proper error checking

The test coverage appears complete, testing both the main functionality and proper resource cleanup. No additional test files are needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Terratest files and test coverage

# Look for test files
echo "Looking for test files..."
fd -e go -e tftest.hcl test/

# Check test patterns
echo "Checking for common test patterns..."
rg -l "func Test" test/

Length of output: 549


Script:

#!/bin/bash
# Check the content of the test file
echo "Content of test/component_test.go:"
cat test/component_test.go

# Look for test assertions and validations
echo -e "\nChecking for test assertions:"
rg "assert\." test/component_test.go

# Look for error scenario handling
echo -e "\nChecking for error scenarios:"
rg "Error|err|fail" test/component_test.go -i

Length of output: 6825

test/fixtures/atmos.yaml (2)

24-24: Verify path configurations are consistent with repository structure

The configuration defines several base paths that need verification:

  • Components: "components/terraform"
  • Stacks: "stacks"
  • Workflows: "stacks/workflows"

Let's ensure these paths exist and follow the expected structure.

Also applies to: 37-37, 54-54


41-42: Verify stack path configuration

The included path pattern orgs/**/* seems very broad. Consider being more specific about which paths should be included to prevent unintended stack inclusions.

✅ Verification successful

The orgs/**/* path pattern is appropriate for this configuration

The broad path pattern is actually suitable in this context because:

  1. It's used in an Atmos configuration file where orgs/**/* specifically targets stack configurations under the organizational hierarchy
  2. The current structure shows a logical organization (orgs/default/test/) which is exactly what this pattern is designed to capture
  3. The excluded_paths configuration already handles excluding specific files like **/_defaults.yaml

The pattern follows Atmos's recommended structure for organizing stacks by organization, and the breadth of the pattern is intentional to allow for multiple organizations and environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check what paths would be included by the current pattern
fd . stacks/orgs -t f -x echo "Would process: {}"

Length of output: 150


Script:

#!/bin/bash
# Let's first check if the 'orgs' directory exists and its location
fd -t d orgs

# Then list all files under any 'orgs' directory to understand the structure
fd . -t f -g "orgs/**/*"

# Also check the context of this YAML file to understand its purpose
cat test/fixtures/atmos.yaml

Length of output: 4104


Script:

#!/bin/bash
# Let's check the actual content of the stacks/orgs directory to understand what files are included
fd . test/fixtures/stacks/orgs -t f

Length of output: 141

@goruha
Copy link
Contributor Author

goruha commented Jan 3, 2025

/terratest

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: 0

🧹 Nitpick comments (2)
test/fixtures/stacks/catalog/usecase/basic.yaml (2)

6-6: Fix trailing whitespace.

Remove trailing spaces after vars: to maintain consistent formatting.

-      vars: 
+      vars:
🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)


11-14: Consider expanding test coverage for subject alternative names.

While the comment about automatic subject alternative names is helpful, consider adding another test fixture that explicitly tests the subject_alternative_names configuration to ensure complete coverage of the module's capabilities.

Would you like me to help create an additional test fixture that covers the subject alternative names configuration?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4111870 and 995c027.

📒 Files selected for processing (2)
  • test/component_test.go (1 hunks)
  • test/fixtures/stacks/catalog/usecase/basic.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/component_test.go
🧰 Additional context used
🪛 yamllint (1.35.1)
test/fixtures/stacks/catalog/usecase/basic.yaml

[error] 6-6: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
test/fixtures/stacks/catalog/usecase/basic.yaml (3)

1-5: LGTM! Well-structured component definition.

The component structure follows best practices with clear metadata definition and appropriate component type specification.


7-10: LGTM! Appropriate test configuration.

The configuration represents a good basic test case with:

  • Enabled component
  • Example domain prefix (good practice for test fixtures)
  • DNS validation method (recommended approach)
  • Domain validation options processing enabled

1-14: Verify DNS validation prerequisites.

Since this test uses DNS validation, we should verify that the necessary DNS permissions and configurations are properly set up in the test environment.

✅ Verification successful

Let me check the content of the DNS-related test files to understand the test setup better.


Let me check the ACM test configurations in the component test file to understand how DNS validation is handled in tests.


DNS validation prerequisites are properly handled in the test environment

The test setup is comprehensive and handles DNS validation correctly:

  • The test framework automatically creates and manages the required DNS zones (primary and delegated) during setup
  • It properly configures Route53 records for ACM certificate validation
  • The test validates that DNS records are created with correct values
  • There's proper cleanup in the teardown phase

The following verifications are performed in the test:

  • DNS validation records are created and verified against Route53
  • Certificate status is checked via AWS ACM API
  • Domain validation options are properly processed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Route53 permissions are included in test configurations
rg -l "route53" test/
# Check for any DNS-related test setup files
fd -t f "dns|route53" test/

Length of output: 145


Script:

#!/bin/bash
# Check the content of DNS-related test files
cat test/fixtures/stacks/catalog/dns-delegated.yaml test/fixtures/stacks/catalog/dns-primary.yaml

# Also check for any ACM-related test configurations that might show DNS validation setup
rg -l "acm" test/

Length of output: 665


Script:

#!/bin/bash
# Check ACM-related test configurations
cat test/component_test.go

# Also check the vendor configuration
cat test/fixtures/vendor.yaml

Length of output: 7469

🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)

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: 0

🧹 Nitpick comments (3)
test/fixtures/stacks/catalog/usecase/basic.yaml (3)

6-6: Fix trailing whitespace.

Remove the trailing space after vars: for consistent formatting.

-      vars: 
+      vars:
🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)


8-8: Consider using a more distinctive test domain.

While example.net is a valid placeholder, consider using a more distinctive domain name that clearly indicates this is a test fixture, such as test.example.com or acm-test.example.net. This helps prevent confusion with production configurations.


11-14: Enhance documentation for subject alternative names.

The current comment about subject alternative names could be more informative. Consider adding:

  1. What the automatically added SAN will be
  2. Examples of common use cases for additional SANs
-        # NOTE: The following subject alternative name is automatically added by the module.
-        #       Additional entries can be added by providing this input.
-        # subject_alternative_names:
-        #   - "*.example.net"
+        # NOTE: The module automatically adds a wildcard SAN (*.example.net) for the domain_name.
+        # Additional SANs can be added here for use cases such as:
+        # - Multiple subdomains: app.example.net, api.example.net
+        # - Multiple wildcard levels: *.dev.example.net
+        # subject_alternative_names:
+        #   - "*.example.net"
+        #   - "*.dev.example.net"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 995c027 and 951af01.

📒 Files selected for processing (1)
  • test/fixtures/stacks/catalog/usecase/basic.yaml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
test/fixtures/stacks/catalog/usecase/basic.yaml

[error] 6-6: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
test/fixtures/stacks/catalog/usecase/basic.yaml (1)

1-14: LGTM! The test fixture follows Terraform testing best practices.

The configuration:

  1. Uses DNS validation method (recommended by AWS)
  2. Enables domain validation processing
  3. Provides a clear basic test case structure

Let's verify this test fixture is properly referenced in the test framework:

✅ Verification successful

Test fixture is properly integrated and referenced in the test framework

The verification confirms that:

  1. The acm/basic test fixture is correctly referenced in test/component_test.go
  2. Terratest is properly set up with version v0.47.1 in the Go module dependencies
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test fixture is properly integrated

# Check if the fixture is referenced in the test configuration
echo "Checking test configuration..."
rg "basic.yaml|acm/basic" test/

# Verify Terratest setup
echo "Checking Terratest setup..."
fd -t f "go.mod|go.sum" . -x cat {} \; | rg "terratest"

Length of output: 622

🧰 Tools
🪛 yamllint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)

@goruha
Copy link
Contributor Author

goruha commented Jan 3, 2025

/terratest

goruha added 2 commits January 9, 2025 16:45
…s/aws-acm into add-tests

* 'add-tests' of github.com:cloudposse-terraform-components/aws-acm:
  Update basic.yaml
@goruha goruha requested review from a team as code owners January 9, 2025 15:47
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

🧹 Nitpick comments (2)
test/component_test.go (2)

125-135: Simplify domain validation check

The current implementation has an unnecessary continue statement and redundant assertion.

 for _, validationOption := range validationOptions[0] {
-    if validationOption.DomainName != domainName {
-        continue
-    }
-    assert.Equal(t, domainName, validationOption.DomainName)
+    if validationOption.DomainName == domainName {
+        // Verify DNS validation records
+        resourceRecordName := strings.TrimSuffix(validationOption.ResourceRecordName, ".")
+        validationDNSRecord := aws.GetRoute53Record(t, domainZoneId, resourceRecordName, validationOption.ResourceRecordType, awsRegion)
+        assert.Equal(t, validationOption.ResourceRecordValue, *validationDNSRecord.ResourceRecords[0].Value)
+    }
 }

41-150: Add test cases for error scenarios

The test only covers the happy path. Consider adding test cases for:

  • Invalid domain names
  • DNS validation failures
  • SSM parameter store failures

Would you like me to help generate additional test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 951af01 and b098b91.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • test/component_test.go (1 hunks)
  • test/go.mod (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
test/component_test.go

23-23: type zone is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (3)
test/go.mod (2)

3-3: ⚠️ Potential issue

Invalid Go version specified

The specified Go version 1.23.0 does not exist. The latest stable version is 1.22.0 as of January 2025.

-go 1.23.0
+go 1.22.0

Likely invalid or redundant comment.


15-17: 🛠️ Refactor suggestion

Remove development-specific replace directives

The commented-out replace directives contain local development paths that should not be committed.

-// replace github.com/cloudposse/test-helpers => /Users/goruha/projects/cloudposse/current/cloudposse-terraform-components/test-helpers
-
-// replace github.com/rebuy-de/aws-nuke/v2/mocks => github.com/ekristen/aws-nuke/v3/ v3.29.0

Likely invalid or redundant comment.

test/component_test.go (1)

55-79: ⚠️ Potential issue

Ensure consistency of random identifiers between setup and teardown

Currently, a new random identifier is generated in both setup and teardown. This can result in attempting to destroy resources under a different subdomain than the one actually deployed.

Store the randomly generated subdomain name in a field that persists between setup and teardown:

 fixture.Suite("default", func(t *testing.T, suite *helper.Suite) {
+    var testSubdomain string
     
     suite.Setup(t, func(t *testing.T, atm *helper.Atmos) {
+        testSubdomain = suite.GetRandomIdentifier()
         inputs := map[string]interface{}{
             "zone_config": []map[string]interface{}{
                 {
-                    "subdomain": suite.GetRandomIdentifier(),
+                    "subdomain": testSubdomain,
                     "zone_name": "components.cptest.test-automation.app",
                 },
             },
         }
         atm.GetAndDeploy("dns-delegated", "default-test", inputs)
     })

     suite.TearDown(t, func(t *testing.T, atm *helper.Atmos) {
         inputs := map[string]interface{}{
             "zone_config": []map[string]interface{}{
                 {
-                    "subdomain": suite.GetRandomIdentifier(),
+                    "subdomain": testSubdomain,
                     "zone_name": "components.cptest.test-automation.app",
                 },
             },
         }
         atm.GetAndDestroy("dns-delegated", "default-test", inputs)
     })

Likely invalid or redundant comment.

@goruha
Copy link
Contributor Author

goruha commented Jan 9, 2025

/terratest

Copy link

mergify bot commented Feb 1, 2025

Heads up! This pull request looks stale. It will be closed soon, if there are no new commits. ⏳

@mergify mergify bot added stale This PR has gone stale and removed stale This PR has gone stale labels Feb 1, 2025
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: 1

♻️ Duplicate comments (3)
test/component_test.go (1)

26-42: 🛠️ Refactor suggestion

Remove unused type declaration.

The zone struct is declared but never used in the code. Remove it to improve code maintainability.

🧰 Tools
🪛 golangci-lint (1.62.2)

26-26: type zone is unused

(unused)

test/fixtures/vendor.yaml (1)

34-34: ⚠️ Potential issue

Replace branch reference with specific version tag.

Using a branch name add-tests as a version reference is not recommended as it's mutable and could lead to inconsistent test environments.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 34-34: trailing spaces

(trailing-spaces)

test/go.mod (1)

3-3: ⚠️ Potential issue

Invalid Go version specified.

The specified Go version 1.23.0 does not exist. The latest stable version is 1.22.0.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b098b91 and e5585dd.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • test/component_test.go (1 hunks)
  • test/fixtures/stacks/catalog/usecase/basic.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/_defaults.yaml (1 hunks)
  • test/fixtures/vendor.yaml (1 hunks)
  • test/go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/fixtures/stacks/orgs/default/test/_defaults.yaml
🧰 Additional context used
🪛 YAMLlint (1.35.1)
test/fixtures/stacks/catalog/usecase/basic.yaml

[error] 6-6: trailing spaces

(trailing-spaces)

test/fixtures/vendor.yaml

[error] 34-34: trailing spaces

(trailing-spaces)


[warning] 43-43: too many blank lines

(1 > 0) (empty-lines)

🪛 golangci-lint (1.62.2)
test/component_test.go

26-26: type zone is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (3)
test/component_test.go (1)

89-101: Consider adding error handling for empty validation options.

The code assumes that validationOptions[0] exists but doesn't handle the case where the slice might be empty.

Add error handling:

 validationOptions := [][]validationOption{}
 atmos.OutputStruct(s.T(), options, "domain_validation_options", &validationOptions)
+if len(validationOptions) == 0 {
+    s.T().Fatal("No validation options found")
+}
 for _, validationOption := range validationOptions[0] {
✅ Verification successful

Action Required: Add Error Handling for Empty Validation Options

The code currently assumes that the outer slice always has at least one element, which can lead to a runtime panic if it's empty. Adding a check, as suggested, would avoid this potential issue.

• Update the test to handle the case where "validationOptions" is empty (e.g., using s.T().Fatal or another appropriate error handling).

test/fixtures/stacks/catalog/usecase/basic.yaml (1)

6-6: Remove trailing spaces.

Remove trailing spaces after vars: to maintain consistent formatting.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)

test/go.mod (1)

15-17: Remove or update commented replace directives.

The file contains commented-out replace directives that appear to be development-specific paths.

@goruha
Copy link
Contributor Author

goruha commented Feb 7, 2025

/terratest

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: 0

🧹 Nitpick comments (4)
test/component_test.go (2)

89-101: Simplify domain validation options loop.

The current implementation has a redundant equality check. The continue statement can be removed since the equality check is performed again in the next line.

 for _, validationOption := range validationOptions[0] {
-	if validationOption.DomainName != domainName {
-		continue
-	}
-	assert.Equal(s.T(), domainName, validationOption.DomainName)
+	if validationOption.DomainName == domainName {
+		// Verify DNS validation records
+		resourceRecordName := strings.TrimSuffix(validationOption.ResourceRecordName, ".")
+		validationDNSRecord := aws.GetRoute53Record(s.T(), domainZoneId, resourceRecordName, validationOption.ResourceRecordType, awsRegion)
+		assert.Equal(s.T(), validationOption.ResourceRecordValue, *validationDNSRecord.ResourceRecords[0].Value)
+	}
 }

116-121: Remove redundant test skip message.

The test skip message is redundant since the test name already indicates it's for a disabled ACM test.

 func (s *ComponentSuite) TestEnabledFlag() {
-	s.T().Skip("Skipping disabled ACM test")
+	s.T().Skip()
 	const component = "acm/disabled"
 	const stack = "default-test"
 	s.VerifyEnabledFlag(component, stack, nil)
 }
test/fixtures/stacks/catalog/usecase/disabled.yaml (2)

6-6: Remove trailing spaces.

Remove trailing spaces after vars: to maintain consistent formatting.

-      vars: 
+      vars:
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 6-6: trailing spaces

(trailing-spaces)


12-15: Improve documentation for subject alternative names.

The current comment could be more descriptive about what is automatically added and why additional entries might be needed.

-        # NOTE: The following subject alternative name is automatically added by the module.
-        #       Additional entries can be added by providing this input.
-        # subject_alternative_names:
-        #   - "*.example.net"
+        # NOTE: The wildcard subject alternative name ("*.example.net") is automatically added by the module
+        # for the root domain. Additional subject alternative names can be added here if you need to
+        # secure multiple subdomains or different domain patterns.
+        # subject_alternative_names:
+        #   - "*.example.net"
+        #   - "*.subdomain.example.net"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5585dd and 0488d33.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • test/component_test.go (1 hunks)
  • test/fixtures/stacks/catalog/usecase/disabled.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/_defaults.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/tests.yaml (1 hunks)
  • test/go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/fixtures/stacks/orgs/default/test/tests.yaml
  • test/fixtures/stacks/orgs/default/test/_defaults.yaml
🧰 Additional context used
🪛 YAMLlint (1.35.1)
test/fixtures/stacks/catalog/usecase/disabled.yaml

[error] 6-6: trailing spaces

(trailing-spaces)

🪛 golangci-lint (1.62.2)
test/component_test.go

26-26: type zone is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (4)
test/component_test.go (1)

26-42: 🛠️ Refactor suggestion

Remove unused type declaration.

The zone struct is declared but never used in the code. Remove it to improve code maintainability.

-type zone struct {
-	Arn               string            `json:"arn"`
-	Comment           string            `json:"comment"`
-	DelegationSetId   string            `json:"delegation_set_id"`
-	ForceDestroy      bool              `json:"force_destroy"`
-	Id                string            `json:"id"`
-	Name              string            `json:"name"`
-	NameServers       []string          `json:"name_servers"`
-	PrimaryNameServer string            `json:"primary_name_server"`
-	Tags              map[string]string `json:"tags"`
-	TagsAll           map[string]string `json:"tags_all"`
-	Vpc               []struct {
-		ID     string `json:"vpc_id"`
-		Region string `json:"vpc_region"`
-	} `json:"vpc"`
-	ZoneID string `json:"zone_id"`
-}

Likely invalid or redundant comment.

🧰 Tools
🪛 golangci-lint (1.62.2)

26-26: type zone is unused

(unused)

test/go.mod (3)

3-3: ⚠️ Potential issue

Update to a valid Go version.

The specified Go version 1.23.0 does not exist. The latest stable version is 1.22.0.

-go 1.23.0
+go 1.22.0

Likely invalid or redundant comment.


6-6: ⚠️ Potential issue

Update dependency to a stable version.

The test-helpers dependency version points to a timestamp in February 2025, which is problematic as it's not a stable release.


15-17: 🛠️ Refactor suggestion

Remove commented out replace directives.

The file contains commented-out replace directives that appear to be development-specific paths. These should be removed as they are not needed in the final code.

-// replace github.com/cloudposse/test-helpers => /Users/goruha/projects/cloudposse/current/cloudposse-terraform-components/test-helpers
-
-// replace github.com/rebuy-de/aws-nuke/v2/mocks => github.com/ekristen/aws-nuke/v3/ v3.29.0

Likely invalid or redundant comment.

@goruha
Copy link
Contributor Author

goruha commented Feb 7, 2025

/terratest

@goruha
Copy link
Contributor Author

goruha commented Feb 10, 2025

/terratest

1 similar comment
@goruha
Copy link
Contributor Author

goruha commented Feb 10, 2025

/terratest

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: 0

🧹 Nitpick comments (2)
test/component_test.go (2)

48-116: Consider parameterizing the AWS region and adding edge cases.

The test could be improved by:

  1. Making the AWS region configurable through test parameters or environment variables.
  2. Adding test cases for edge cases like:
    • Multiple domain names
    • Different validation methods
    • Certificate renewal scenarios

124-138: Consider adding explicit cleanup for DNS resources.

While the test setup is correct, consider adding explicit cleanup in a defer statement to ensure DNS resources are properly cleaned up even if tests fail.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0488d33 and e64056a.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • test/.gitignore (1 hunks)
  • test/component_test.go (1 hunks)
  • test/go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/.gitignore
🧰 Additional context used
🪛 golangci-lint (1.62.2)
test/component_test.go

26-26: type zone is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (5)
test/component_test.go (2)

26-42: Remove unused type declaration.

The zone struct is declared but never used in the code. Remove it to improve code maintainability.

🧰 Tools
🪛 golangci-lint (1.62.2)

26-26: type zone is unused

(unused)


118-122: LGTM!

The test correctly verifies the component's behavior when disabled.

test/go.mod (3)

3-3: Invalid Go version specified.

The specified Go version 1.23.0 does not exist. The latest stable version is 1.22.0 as of February 2025.


6-6: Critical Dependency Version Issue.

The test-helpers dependency version points to a future timestamp (February 2025). Update to a stable, released version to avoid potential instability issues.


15-17: Remove or update commented replace directives.

The file contains commented-out replace directives that appear to be development-specific paths. These should either be removed or properly configured.

@goruha
Copy link
Contributor Author

goruha commented Feb 12, 2025

/terratest

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: 3

🧹 Nitpick comments (1)
test/component_test.go (1)

92-95: Add certificate expiry validation.

The test verifies the certificate status and type but doesn't validate the expiry date.

 	assert.Equal(s.T(), string(types.CertificateStatusIssued), string(awsCertificate.Certificate.Status))
 	assert.Equal(s.T(), string(types.CertificateTypeAmazonIssued), string(awsCertificate.Certificate.Type))
 	assert.Equal(s.T(), arn, *awsCertificate.Certificate.CertificateArn)
+	// Ensure certificate is not about to expire
+	require.NotNil(s.T(), awsCertificate.Certificate.NotAfter, "Certificate expiry date is nil")
+	expiryThreshold := time.Now().AddDate(0, 0, 30) // 30 days
+	assert.True(s.T(), awsCertificate.Certificate.NotAfter.After(expiryThreshold), 
+		"Certificate expires in less than 30 days")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e64056a and 8db27d3.

📒 Files selected for processing (1)
  • test/component_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (4)
test/component_test.go (4)

1-17: LGTM!

The imports are well-organized and all are actively used in the test implementation.


19-28: LGTM!

The type declarations are well-structured:

  • validationOption struct correctly maps to ACM domain validation fields
  • ComponentSuite properly extends the test helper suite

100-104: LGTM!

The test correctly verifies the enabled/disabled state of the ACM component using the helper method.


106-120: LGTM!

The test suite setup is well-structured:

  • Generates unique subdomain for isolation
  • Correctly sets up DNS dependency
  • Uses helper.Run for test execution

@goruha
Copy link
Contributor Author

goruha commented Feb 12, 2025

/terratest

goruha added a commit to cloudposse/test-helpers that referenced this pull request Feb 13, 2025
## what
* Added GetAtmosOptions method
* Added `ATMOS_CLI_CONFIG_PATH` env vars
* Fix `VerifyEnabledFlag`
* Add `DriftTest`
* Moved helpers functions to `pkg/aws`

## why
* Allow to get options for dependencies
* Fix remote state terraform read
* OpenTofu and Terraform handle detailed exit codes differently
* Test drifts  
* Consolidate helper functions

## references
* cloudposse-terraform-components/aws-acm#9
@goruha
Copy link
Contributor Author

goruha commented Feb 13, 2025

/terratest

@goruha goruha self-assigned this Feb 16, 2025
mcalhoun
mcalhoun previously approved these changes Feb 19, 2025
@goruha
Copy link
Contributor Author

goruha commented Feb 20, 2025

/terratest

@goruha goruha merged commit e930735 into main Feb 20, 2025
19 checks passed
@goruha goruha deleted the add-tests branch February 20, 2025 01:12
Copy link

These changes were released in v1.536.1.

@goruha goruha removed the needs-test Needs testing label Mar 19, 2025
Copy link

mergify bot commented Apr 3, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require terratest

Wonderful, this rule succeeded.

This rule require terratest status

  • check-success = test/terratest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants