add option to specify Terraform working directory - #483
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a configurable ChangesTerraform root override
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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. Comment |
| } | ||
|
|
||
| const projectConfig = context.projectsConfigurations?.projects?.[projectName] | ||
| const projectTerraformRoot = projectConfig && 'terraformRoot' in projectConfig |
There was a problem hiding this comment.
| const projectTerraformRoot = projectConfig && 'terraformRoot' in projectConfig | |
| const projectTerraformRoot = projectConfig && 'root' in projectConfig |
There was a problem hiding this comment.
If i see it correctly you now support two different root options?
Also, context.projectName is I think something Nx itself sets, so the check should not be needed.
There was a problem hiding this comment.
Hi There!
Type 'undefined' cannot be used as an index type. warning occurs if I leave it without the check.
Yes, for project.json you can use "terraformRoot": "pathto/terraform" - I thought it might be a bit better to not have it generic inside project.json
In the targets you can use:
"options": {
"root": "pathto/terraform"
}There was a problem hiding this comment.
I'll also apply coderabbit's requested changes here
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/terraform/src/utils/create-executor.ts (1)
40-42: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider typing
terraformRootmore safely.The
(projectConfig as Record<string, any>).terraformRootcast works but bypasses type safety. A typed interface orRecord<string, unknown>with a narrowing check would be cleaner.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/terraform/src/utils/create-executor.ts` around lines 40 - 42, The `createExecutor` logic is bypassing type safety by casting `projectConfig` to `Record<string, any>` to read `terraformRoot`. Update the `projectConfig` handling in `create-executor.ts` to use a safer typed shape or `Record<string, unknown>` with a proper narrowing check before accessing `terraformRoot`, keeping the existing `projectTerraformRoot` assignment path intact.packages/terraform/README.md (1)
133-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the fallback chain in the
rootoption description.The schema descriptions mention overriding
terraformRoot, but the README only says "Path to the Terraform working directory". Adding the fallback priority (root→terraformRoot→sourceRoot) would help users understand the option's relationship to existing configuration.📝 Suggested description update
-| **`root`** | `string` | - | Path to the Terraform working directory | `all` | +| **`root`** | `string` | - | Path to the Terraform working directory. Overrides `terraformRoot` and `sourceRoot` | `all` |🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/terraform/README.md` at line 133, The README description for the `root` option is missing the fallback chain, so update the `root` row in the Terraform options table to mention the priority order used by the config, referencing the `root`, `terraformRoot`, and `sourceRoot` option names. Keep the description concise but explicit so users can see that `root` is preferred first, then `terraformRoot`, then `sourceRoot` when resolving the Terraform working directory.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/terraform/README.md`:
- Line 133: The README description for the `root` option is missing the fallback
chain, so update the `root` row in the Terraform options table to mention the
priority order used by the config, referencing the `root`, `terraformRoot`, and
`sourceRoot` option names. Keep the description concise but explicit so users
can see that `root` is preferred first, then `terraformRoot`, then `sourceRoot`
when resolving the Terraform working directory.
In `@packages/terraform/src/utils/create-executor.ts`:
- Around line 40-42: The `createExecutor` logic is bypassing type safety by
casting `projectConfig` to `Record<string, any>` to read `terraformRoot`. Update
the `projectConfig` handling in `create-executor.ts` to use a safer typed shape
or `Record<string, unknown>` with a proper narrowing check before accessing
`terraformRoot`, keeping the existing `projectTerraformRoot` assignment path
intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 648b3d5c-82eb-4a8d-bee6-673a764f1c7a
📒 Files selected for processing (11)
packages/terraform/README.mdpackages/terraform/src/executors/apply/schema.jsonpackages/terraform/src/executors/destroy/schema.jsonpackages/terraform/src/executors/fmt/schema.jsonpackages/terraform/src/executors/init/schema.jsonpackages/terraform/src/executors/plan/schema.jsonpackages/terraform/src/executors/providers/schema.jsonpackages/terraform/src/executors/test/schema.jsonpackages/terraform/src/executors/validate/schema.jsonpackages/terraform/src/executors/workspace/schema.jsonpackages/terraform/src/utils/create-executor.ts
|
Can you also checkout the nitpick comment from coderabbit about the readme? |
fixes #482
Summary by CodeRabbit
New Features
rootsetting to run Terraform tasks from a custom working directory.rootoverride consistently across plan, apply, destroy, init, validate, test, fmt, workspace, and providers tasks.Documentation
root, including its intended behavior and supported command coverage.