Managing Terraform Plans for Nested Directory Structures
Last updated: July 14, 2025
When working with Terraform configurations spread across nested directories, you may want to control which stacks run plans based on file changes. Here's how to set this up effectively.
Best Practice: Separate Stacks
For nested directory structures (e.g., resources/a and resources/a/b), create separate stacks for each directory that needs independent management. This provides better control over when plans are triggered.
Preventing Unwanted Plans
By default, changes in a subdirectory (e.g., resources/a/b) will trigger plans in both the parent and child stacks. To prevent this, implement a push policy to ignore changes outside the root directory.
Use this policy example from our policy library to block unwanted plan triggers:
Ignore Changes Outside Root Policy
Alternative Approach: Targeted Replans
If you need more granular control over specific resources, you can use targeted replans. This feature allows you to prevent changes to resources that are in an unconfirmed state of a tracked plan. Learn more about targeted replans in our documentation.
While targeted replans are available, they should be used sparingly and not as a default workflow practice. Reserve targeting for specific scenarios where precision is required.