Skip to content

Conversation

@br3ndonland
Copy link
Contributor

@br3ndonland br3ndonland commented Aug 21, 2025

Description

By default, this module assumes all stacks are in the same repo as the stack with the module instance.

What if the module needs to manage stacks in another repo? We had this use case and developed a "remote stacks" approach. Here's @Gowiem to explain:

It would be great to document this approach for other users.

Changes

This PR will document the remote stacks approach in the README. The example looks like this:

this-repo
├── remote-stacks
│   └── other-repo
│       └── other-repo-random-pet
│           └── stack.yaml
└── stacks
    └── spacelift-automation
        ├── main.tf
        ├── stack.yaml
        └── versions.tofu
# this-repo/remote-stacks/other-repo/other-repo-random-pet/stack.yaml
stack_settings:
  project_root: stacks/random-pet
other-repo
└── stacks
    └── random-pet
        ├── main.tf
        └── versions.tofu

Note that the README recommends that the remote stacks directory should not be nested inside of another stack. This is because of the changes to globbing behavior introduced in #80 and module v1.5.0. The new behavior introduced some unexpected changes for our repo because we had a remote stacks directory nested inside our stacks directory, like this basically:

# this-repo/app/stacks/spacelift-automation/main.tf
module "spacelift_automation_for_stacks_in_this_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = true
  repository               = "this-repo"
  root_module_structure    = "SingleInstance"
  root_modules_path        = "../../../app/stacks"
}

module "spacelift_automation_for_stacks_in_other_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = true
  repository               = "other-repo"
  root_module_structure    = "SingleInstance"
  root_modules_path        = "../../../app/stacks/spacelift-automation/remote-stacks/other-repo"
}

After updating to module v1.5.0, the spacelift_automation_this_repo module instance started picking up the stack.yaml files in the nested remote-stacks subdirectory.

The easiest solution is just to not nest the remote stacks dir. Another solution is to set all_root_modules_enabled = false and then add the stacks in the repo to enabled_root_modules. This of course means that new stacks added to app/stacks/new-stack-name/stack.yaml have to be added to enabled_root_modules to be detected.

# this-repo/app/stacks/spacelift-automation/main.tf
module "spacelift_automation_for_stacks_in_this_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = false
  enabled_root_modules = [
    "development",
    "production",
    "spacelift-automation",
  ]
  repository            = "this-repo"
  root_module_structure = "SingleInstance"
  root_modules_path     = "../../../app/stacks"
}

module "spacelift_automation_for_stacks_in_other_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = true
  repository               = "other-repo"
  root_module_structure    = "SingleInstance"
  root_modules_path        = "../../../app/stacks/spacelift-automation/remote-stacks/other-repo"
}

Related

Summary by CodeRabbit

  • Documentation
    • Added a section on managing stacks in a separate Git repository.
    • Includes guidance on repo setup, access permissions, directory layout, and detection caveats.
    • Provides example file structures and configuration snippets for linking local and remote stacks.
    • Clarifies setting project root paths across repos and referencing multiple root modules.
    • Notes relevant module version context.
    • No functional changes; documentation-only update.

By default, this module assumes all stacks are in the same repo as the
stack with the module instance.

What if users want to use this module to manage stacks in _another
repo_? We had this use case and came up with a "remote stacks" approach.

It would be great to document this approach for other users.

This PR will document the remote stacks approach in the README. The
example looks like this:

```text
this-repo
├── remote-stacks
│   └── other-repo
│       └── other-repo-random-pet
│           └── stack.yaml
└── stacks
    └── spacelift-automation
        ├── main.tf
        ├── stack.yaml
        └── versions.tofu
```

```yaml
# this-repo/remote-stacks/other-repo/other-repo-random-pet/stack.yaml
stack_settings:
  project_root: stacks/random-pet
```

```text
other-repo
└── stacks
    └── random-pet
        ├── main.tf
        └── versions.tofu
```

Note that the README recommends that the remote stacks directory should
_not_ be nested inside of another stack. This is because of the changes
to globbing behavior introduced in masterpointio#80 and module v1.5.0. The new
behavior introduced some unexpected changes for our repo because we had
a remote stacks directory nested inside our stacks directory, like this
basically:

```hcl
# this-repo/app/stacks/spacelift-automation/main.tf
module "spacelift_automation_for_stacks_in_this_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = true
  repository               = "this-repo"
  root_module_structure    = "SingleInstance"
  root_modules_path        = "../../../app/stacks"
}

module "spacelift_automation_for_stacks_in_other_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = true
  repository               = "other-repo"
  root_module_structure    = "SingleInstance"
  root_modules_path        = "../../../app/stacks/spacelift-automation/remote-stacks/other-repo"
}
```

After updating to module v1.5.0, the `spacelift_automation_this_repo`
module instance started picking up the `stack.yaml` files in the nested
`remote-stacks` subdirectory.

The easiest solution is just to not nest the remote stacks dir. Another
solution is to set `all_root_modules_enabled = false` and then add the
stacks in the repo to `enabled_root_modules`. This of course means that
new stacks added to `app/stacks/new-stack-name/stack.yaml` have to be
added to `enabled_root_modules` to be detected.

```hcl
# this-repo/app/stacks/spacelift-automation/main.tf
module "spacelift_automation_for_stacks_in_this_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = false
  enabled_root_modules = [
    "development",
    "production",
    "spacelift-automation",
  ]
  repository            = "this-repo"
  root_module_structure = "SingleInstance"
  root_modules_path     = "../../../app/stacks"
}

module "spacelift_automation_for_stacks_in_other_repo" {
  source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"

  all_root_modules_enabled = true
  repository               = "other-repo"
  root_module_structure    = "SingleInstance"
  root_modules_path        = "../../../app/stacks/spacelift-automation/remote-stacks/other-repo"
}
```
@br3ndonland br3ndonland requested a review from a team as a code owner August 21, 2025 03:20
@br3ndonland br3ndonland requested a review from oycyc August 21, 2025 03:20
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 21, 2025

Walkthrough

Adds a new README section titled “What if my stacks are in another repo?” describing how to manage Spacelift stacks located in a separate Git repository. It outlines repository structure, access requirements, the use of a remote-stacks directory (with placement caveats), example layouts, stack.yaml project_root guidance, and Terraform module configuration examples referencing both local and remote repositories. No code or API changes; documentation only.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • Gowiem

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 (6)
README.md (6)

247-247: Fix typo and casing.

“here's now it might look” ➜ “here’s how it might look”; also capitalize “Spacelift Automation” for consistency with the rest of the README.

- ... For example, here's now it might look for a repo named ...
+ ... For example, here’s how it might look for a repo named ...
- ... within the Spacelift automation stack directory ...
+ ... within the Spacelift Automation stack directory ...

272-289: Pin the module version (prefer registry) to ensure reproducibility.

Using a floating Git source can lead to surprise changes. Recommend the Terraform Registry with a pinned version, or pin a Git tag/commit via ?ref.

- module "spacelift_automation_this_repo" {
-   source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"
+ module "spacelift_automation_this_repo" {
+   # Prefer the Registry and pin a version
+   source  = "masterpointio/automation/spacelift"
+   version = "~> 1.5"
    ...
- }
+ }

Alternative (if you must keep Git):

- source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git"
+ source = "git::https://github.com/masterpointio/terraform-spacelift-automation.git?ref=v1.5.0"

277-281: Double‑check root_modules_path semantics; consider dropping “../../”.

The Inputs table documents root_modules_path as “relative to the root of the repository.” If that’s the case, the examples should be repo‑root‑relative (e.g., "stacks" and "remote-stacks/other-repo") instead of pathing relative to the module file’s folder.

- root_modules_path     = "../../stacks"
+ root_modules_path     = "stacks"
...
- root_modules_path     = "../../remote-stacks/other-repo"
+ root_modules_path     = "remote-stacks/other-repo"

If the module intentionally resolves relative to the module call site, ignore this suggestion—but then consider clarifying that behavior here to avoid confusion.

Also applies to: 285-289


236-244: Clarify why the remote repo should not contain a stack.yaml.

Add one sentence explaining that stack.yaml lives in the host repo to avoid duplicate detection and to keep Spacelift config co-located with the automation module.

- There should not be a `stack.yaml` file in the other repo.
+ There should not be a `stack.yaml` file in the other repo, since the Spacelift configuration for remote stacks is defined in this repo to prevent duplicate discovery and to keep all Stack config alongside the automation module.

262-268: Include “kind” for consistency with earlier examples (optional).

Earlier you showed kind: StackConfigV1. Consider including it here so readers can copy/paste a fully valid example.

 # this-repo/remote-stacks/other-repo/other-repo-random-pet/stack.yaml
- stack_settings:
+ kind: StackConfigV1
+ stack_settings:
   project_root: stacks/random-pet

246-261: Document the alternative mitigation for nested remote-stacks (enabled_root_modules).

Since #80 changed globbing, add a short note showing the second mitigation (set all_root_modules_enabled = false and enumerate enabled_root_modules) with its tradeoff.

  • Note: If you must nest remote-stacks under the Spacelift Automation stack, set:
  • all_root_modules_enabled = false
  • enabled_root_modules = ["spacelift-automation", "remote-stacks/other-repo"]
  • Tradeoff: new stacks won’t be auto-discovered—you must add them to enabled_root_modules.

Happy to add this snippet where you’d like it and adjust wording for your style guide.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

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

**💡 Knowledge Base configuration:**

- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 0f35dae7f0beff4df86488b0e5aafff765c6a6b1 and c0fc07dd57dcc69f339b7ed3c3a750276a62d493.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `README.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧠 Learnings (1)</summary>

<details>
<summary>📚 Learning: 2025-05-12T15:44:10.001Z</summary>

Learnt from: gberenice
PR: masterpointio/terraform-users-groups-automation-googleworkspace#1
File: examples/import-existing-org/imports.tf:7-7
Timestamp: 2025-05-12T15:44:10.001Z
Learning: In Terraform, local variables defined in one .tf file are available throughout all other .tf files in the same module directory, which allows for referencing locals across different files.


**Applied to files:**
- `README.md`

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (1)</summary><blockquote>

<details>
<summary>README.md (1)</summary>

`232-289`: **Nice addition — clear, actionable guidance for “remote stacks.”**

The new section is helpful and aligns with how the module models stacks across repos. The stepwise walkthrough, example trees, and configuration blocks will save users time.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

The config in `.trunk/configs/.markdownlint.yaml` has `strict: false`
for `MD013`, but the GitHub Actions lint job is still erroring. Error:

```
README.md:247:0
247:0  low  Line length  markdownlint/MD013
```

fix:

```sh
prettier --print-width 350 --prose-wrap always --write README.md
```
@oycyc
Copy link
Contributor

oycyc commented Aug 21, 2025

Thanks for highlighting that nested glob pattern. I'm going to think more on that. This PR is great. I'll leave it to Matt to review further.

Copy link
Member

@Gowiem Gowiem left a comment

Choose a reason for hiding this comment

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

@br3ndonland this is an awesome FAQ addition -- thank you for circling back around to this and contributing it. Love seeing previous clients contribute to our OSS ❤️

Few small requests and then let's :shipit: !

@br3ndonland
Copy link
Contributor Author

Thanks @Gowiem @oycyc for your reviews. I've accepted your suggestions.

Looks like there some unrelated test failures, but otherwise the changes are passing CI checks.

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.

Thanks a lot @br3ndonland!
I've fixed the tests and now this is good to 🚢

@gberenice gberenice merged commit 3fce25e into masterpointio:main Sep 3, 2025
4 checks passed
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.

4 participants