Problem
After changing a workspace's execution mode from "Remote" to "Agent" in HCP Terraform, speculative plans are not triggered for pull requests, even when "Automatic speculative plans" are enabled and VCS trigger patterns are configured for specific directories.
Prerequisites
- An HCP Terraform workspace connected to a Version Control System (VCS) provider.
- The workspace settings have Automatic run triggering enabled for speculative plans on pull requests.
- The workspace uses VCS Triggers with directory patterns to limit runs to changes in specific paths.
Cause
This issue can occur if the directory pattern in the VCS trigger settings starts with an asterisk (*). When a pattern begins with an asterisk, the HCP Terraform agent may interpret it as a wildcard at a lower directory level than intended. This mismatch in path evaluation causes the agent to miss file changes within the specified directory, and as a result, it does not trigger a speculative plan.
Solutions
Solution 1: Adjust the Directory Pattern
To ensure the agent correctly identifies file changes, modify the directory pattern to be more explicit.
- Navigate to your workspace's Settings > VCS.
- In the VCS Triggers section, locate the directory pattern.
- Modify the pattern to start with a forward slash (
/) to anchor the path to the root of the repository. For example, change a pattern like*modules/networking/*to/modules/networking/*. - Save the updated settings.
This change ensures that the path is evaluated from the repository's root, leading to accurate change detection by the agent.
Outcome
After adjusting the directory pattern, pull requests that modify files within the specified path will correctly trigger a speculative plan in the workspace.
Additional Information
- For more details on run triggers, refer to the Speculative Plans on Pull Requests documentation.