Skip to content

Conversation

@Gowiem
Copy link
Member

@Gowiem Gowiem commented Feb 4, 2025

what

  • Updates runtime_overrides for a given stack to be included in the deep merge instead of TF's simple merge.

why

  • Short version: Properly merges runtime overrides on top of static StackConfig values
  • Long version: I found this bug when doing some diligent integration testing in our mp-infra repo. Prior to this fix, if we included runtime_overrides with only one value in the overrides, it would overwrite the static StackConfig stack_settings for that stack and result in only including the runtime_overrides + the variable defaults. Not good 💥
    • This is exactly what @westonplatter was working to avoid when he was pushing me in this thread: feat: adds the runtime_overrides variable + tests #44 (comment). He added a test for this, but it was with labels and he was checking a common label... sadly that didn't catch this bug even though he was spot on that there was bug here!!! Luckily, integration testing surfaced this and then unit testing enabled me to quickly reproduce in the module. Now we have a solid fix 🎉

references

Summary by CodeRabbit

  • Refactor
    • Enhanced the configuration merging process to now apply runtime overrides after base and stack-specific settings, offering greater flexibility and dynamic control.
  • Tests
    • Expanded test coverage with additional validations and refined naming to ensure consistent behavior and reliability of the configuration adjustments.

@Gowiem Gowiem requested a review from westonplatter February 4, 2025 00:53
@Gowiem Gowiem self-assigned this Feb 4, 2025
@Gowiem Gowiem requested a review from a team as a code owner February 4, 2025 00:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

The pull request updates the Terraform configuration for managing stack settings. It refines the merging logic in the module "deep" block to combine common configurations, stack-specific settings, and runtime overrides in a precise order. Test definitions are also modified, notably renaming a variable for clarity and expanding assertions for various stack properties. Comments have been updated to better explain the new merging process.

Changes

File Change Summary
main.tf Updated the merging logic in the module "deep" block to merge common configurations, stack-specific settings, and runtime overrides in that order. Updated comments to clarify the process; resource signatures remain unchanged.
tests/main.tftest.hcl Changed variable name from administrator to administrative in runtime overrides. Expanded assertions for multiple properties of the spacelift_stack resource and enhanced comment clarity for test cases.

Sequence Diagram(s)

sequenceDiagram
    participant M as Module "deep"
    participant C as Common Config
    participant S as Stack Config
    participant R as Runtime Overrides
    Note over M: Merge order: Common -> Stack -> Runtime
    M->>C: Retrieve common configuration
    M->>S: Retrieve stack-specific configuration
    M->>R: Retrieve runtime overrides
    M->>M: Merge configurations (C, then S, then R)
    M-->>System: Apply final configuration
Loading

Possibly related PRs

Suggested reviewers

  • westonplatter

Poem

In Terraform's realm, our configs now glow,
Merging common, stack, and runtime in a row.
Tests stand ready, their verdicts are clear,
Code refined and vibrant, a change we cheer!
Here's to progress and clarity in flow!
🚀🌟


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.

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
Contributor

@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 (1)
main.tf (1)

310-322: Deep Merge Logic Update:
The updated deep merge configuration in the module "deep" block now combines three layers of configuration in the proper order: the common configuration, the static StackConfig values, and finally the runtime overrides. The inline comments clearly explain the intended override precedence. One suggestion is to consider validating that the output of the jsondecode call is indeed a map (or the expected type) before merging, which could help guard against malformed runtime override inputs.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6030f94 and fe4fec6.

📒 Files selected for processing (2)
  • main.tf (1 hunks)
  • tests/main.tftest.hcl (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
main.tf (1)

Pattern **/*.tf: You're a Terraform expert who has thoroughly studied all the documentation from Hashicorp https://developer.hashicorp.com/terraform/docs and OpenTofu https://opentofu.org/docs/.
You have a strong grasp of Terraform syntax and prioritize providing accurate and insightful code suggestions.
As a fan of the Cloud Posse / SweetOps ecosystem, you incorporate many of their best practices https://docs.cloudposse.com/best-practices/terraform/ while balancing them with general Terraform guidelines.

🔇 Additional comments (2)
tests/main.tftest.hcl (2)

220-264: Full Runtime Overrides Test:
This test block defines a comprehensive set of runtime override settings that update almost every field in the stack configuration (from administrative to drift_detection_timezone). The detailed override values paired with targeted assertions ensure that the deep merge functionality is correctly applying runtime overrides on top of the static configuration.


459-664: Partial Runtime Overrides Test:
This test verifies that providing only a subset of runtime override settings (in this case, only overriding administrative) leaves the other static configuration values intact. The assertions confirm that the deep merge does not inadvertently clobber unspecified settings. This provides good coverage against overzealous merging.

Copy link
Member

@gberenice gberenice left a comment

Choose a reason for hiding this comment

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

:shipit:

@Gowiem Gowiem merged commit b352674 into main Feb 4, 2025
4 checks passed
@Gowiem Gowiem deleted the fix/runtime-merging-issue branch February 4, 2025 17:30
Gowiem added a commit that referenced this pull request Feb 4, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](v0.7.0...v1.0.0)
(2025-02-04)


### ⚠ BREAKING CHANGES

* TF Version pinning has been updated to require terraform v1.9+ and
OpenTofu v1.7+. Please update the consuming root module accordingly.
(#43)
* Scopes `tfvars` + `default_tf_workspace_enabled` settings under
`automation_settings` object in StackConfig schema. [See
README](https://github.com/masterpointio/terraform-spacelift-automation?tab=readme-ov-file#what-goes-in-a-stack-config-file-eg-stacksdevyaml-stackscommonyaml-stackyaml-and-similar)
for example of StackConfig schema. (#42)

### Features

* adds support for description as a templatestring
([#43](#43))
([1bbb74f](1bbb74f))
* adds the runtime_overrides variable + tests
([#44](#44))
([6030f94](6030f94))
* feat: allow specifying `space_name` that maps to space_id #46
* **schema:** adds initial JSON schema + StackConfig changes
([#42](#42))
([f247b5e](f247b5e))


### Bug Fixes

* cron validator regex escape characters
([#45](#45))
([81a386b](81a386b))
* dont clobber static config with overrides
([#50](#50))
([b352674](b352674))
* external space changed so update test data
([#51](#51))
([569d8d4](569d8d4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Gowie <[email protected]>
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.

3 participants