Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add engine support to dependencies #3974

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

partcyborg
Copy link
Contributor

@partcyborg partcyborg commented Mar 6, 2025

Description

Fixes #3973

Add support for parsing the engine block to PartialParseConfig so that terraform commands run in dependency blocks use the engine config if present and enabled.

TODOs

  • Update the docs.
    • No docs update necessary, as this functionality isn't mentioned either way
  • Run the relevant tests successfully, including pre-commit checks.
    • NOTE: some tests I couldn't run locally as I couldn't do PGP decryption
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added support for IaC engines to dependency blocks.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added support for an engine configuration block in Terragrunt configuration files, enabling users to include engine-specific settings.
    • Introduced new output variables and configuration files for managing engine dependencies in Terraform.
    • Added a new .gitignore file to exclude specific files from version control.
  • Bug Fixes
    • Improved error handling and control flow related to engine options in configuration parsing.
  • Documentation
    • Updated help notes to reflect the enhanced configuration parsing with the new engine settings support.

Add support for parsing the `engine` block to `PartialParseConfig` so that terraform commands run in `dependency` blocks use the engine config if present and enabled.
Copy link

vercel bot commented Mar 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
terragrunt-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 8, 2025 0:39am

Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

📝 Walkthrough

Walkthrough

The update introduces support for an additional "engine" block in the Terragrunt configuration. A new constant, EngineBlock, is added to the PartialDecodeSectionType enum, and the PartialParseConfig function is modified to handle this new block. The getTerragruntOutputJSON function is also updated to include engineOpts as a parameter in the parsing process. Documentation for the configuration function is revised to reflect these changes. Additionally, new configuration files and test cases are introduced to support the engine functionality.

Changes

File Change Summary
config/config_partial.go Added constant EngineBlock, defined terragruntEngine struct, modified PartialParseConfig to include a case for decoding the engine block into EngineConfig, and updated documentation for TerragruntConfigFromPartialConfig.
config/dependency.go Updated method signatures for getTerragruntOutputJSONFromInitFolder, getTerragruntOutputJSONFromRemoteState, and setupTerragruntOptionsForBareTerraform to include engineOpts. Enhanced error handling for engineOpts retrieval.
test/fixtures/engine/engine-dependencies/.gitignore Created a new .gitignore file specifying backend.gen.tf and test.txt to be ignored by Git.
test/fixtures/engine/engine-dependencies/app1/main.tf Added output variable value set to "app1-test" to the Terraform configuration.
test/fixtures/engine/engine-dependencies/app1/terragrunt.hcl Introduced terragrunt.hcl file with an engine block specifying the source and version of the engine.
test/fixtures/engine/engine-dependencies/app2/main.tf Added variable app1_output and created a local_file resource named test that uses this variable.
test/fixtures/engine/engine-dependencies/app2/terragrunt.hcl Introduced terragrunt.hcl file with an include directive, an engine block, and a dependency declaration for app1.
test/fixtures/engine/engine-dependencies/root.hcl Added a new remote_state configuration block specifying backend details and state file path.
test/integration_engine_test.go Introduced TestEngineDependency function to test engine dependency setup and added constant testFixtureEngineDependency for fixture path.

Suggested reviewers

  • levkohimins
  • yhakbar

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f49af73 and 60632e1.

📒 Files selected for processing (1)
  • config/dependency.go (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/dependency.go

🪧 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.
  • @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 (2)
config/config_partial.go (2)

86-90: Unused struct declaration

The terragruntEngine struct is declared but never used. The EngineBlock case (lines 454-462) directly uses EngineConfig instead of this struct.

Consider either:

  1. Removing this struct if it's not needed
  2. Using it consistently by updating the EngineBlock case to follow the pattern used for other blocks:
case EngineBlock:
-    decoded := EngineConfig{}
+    decoded := terragruntEngine{}

    err := file.Decode(&decoded, evalParsingContext)
    if err != nil {
        return nil, err
    }
-    output.Engine = &decoded
+    output.Engine = &decoded.Engine
🧰 Tools
🪛 golangci-lint (1.62.2)

87-87: type terragruntEngine is unused

(unused)


454-462: Consider following consistent pattern for block parsing

This implementation directly decodes into an EngineConfig type rather than using a wrapper struct like other block types (e.g., terragruntRemoteState for RemoteStateBlock).

For consistency with other code patterns in this file, consider using the declared terragruntEngine struct:

case EngineBlock:
-    decoded := EngineConfig{}
+    decoded := terragruntEngine{}

    err := file.Decode(&decoded, evalParsingContext)
    if err != nil {
        return nil, err
    }
-    output.Engine = &decoded
+    output.Engine = &decoded.Engine
🧰 Tools
🪛 golangci-lint (1.62.2)

461-461: assignments should only be cuddled with other assignments

(wsl)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 466edb1 and 2e6d342.

📒 Files selected for processing (2)
  • config/config_partial.go (4 hunks)
  • config/dependency.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code for quality and correctness. M...

**/*.go: Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

  • config/dependency.go
  • config/config_partial.go
🪛 golangci-lint (1.62.2)
config/config_partial.go

87-87: type terragruntEngine is unused

(unused)


461-461: assignments should only be cuddled with other assignments

(wsl)

🔇 Additional comments (3)
config/dependency.go (1)

759-759: LGTM: Added engine block support for dependencies

This change enhances the PartialParseConfigFile call to include the new EngineBlock parameter, allowing dependency configurations to utilize engine settings if present.

config/config_partial.go (2)

38-38: LGTM: Added EngineBlock to PartialDecodeSectionType

Adding the EngineBlock constant to the enum allows the parser to recognize the engine block section.


339-339: LGTM: Updated documentation

Documentation updated to include the new EngineBlock in the list of valid values.

Copy link
Collaborator

@yhakbar yhakbar left a comment

Choose a reason for hiding this comment

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

Thanks for cutting this PR!

There are some things I'd like addressed, if you don't mind.

  1. Please do add a test that uses a dependency via the engine config. A simple test added here to verify that dependencies are loaded with the engine block would be great. If you don't have time for that or aren't comfortable, please say so, and we can look to add it for you in another PR.
  2. See the comment generated by CodeRabbit here. It looks like there's an unused terragruntEngine struct. Please address that.

@partcyborg
Copy link
Contributor Author

Thanks for cutting this PR!

There are some things I'd like addressed, if you don't mind.

  1. Please do add a test that uses a dependency via the engine config. A simple test added here to verify that dependencies are loaded with the engine block would be great. If you don't have time for that or aren't comfortable, please say so, and we can look to add it for you in another PR.
  2. See the comment generated by CodeRabbit here. It looks like there's an unused terragruntEngine struct. Please address that.

Thanks for the quick followup. I fixed the CodeRabbit issue. I can add a test that utilizes a dependency, but upon a quick scan of the existing integration tests, it isn't clear to me exactly how I verify that the dependency block is actually following the engine codepath, outside of building a custom client or server that i can somehow verify the list of calls made through it. This would be a pretty big departure from the other tests as they are all using pre-built engine client/servers.

Do you have any thoughts on this? Or is it enough to just have a test that uses 2 modules with dependencies?

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: 1

🧹 Nitpick comments (1)
config/config_partial.go (1)

448-456: Linting issue with assignment formatting

The implementation for parsing the EngineBlock correctly follows the pattern used for other blocks. However, there's a linting issue where the assignment at line 455 should follow other assignments rather than being placed directly after the error handling block.

			err := file.Decode(&decoded, evalParsingContext)
			if err != nil {
				return nil, err
			}
+			
			output.Engine = &decoded
🧰 Tools
🪛 golangci-lint (1.62.2)

455-455: assignments should only be cuddled with other assignments

(wsl)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e6d342 and 53fbaf9.

📒 Files selected for processing (1)
  • config/config_partial.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code for quality and correctness. M...

**/*.go: Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

  • config/config_partial.go
🪛 golangci-lint (1.62.2)
config/config_partial.go

455-455: assignments should only be cuddled with other assignments

(wsl)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (4)
config/config_partial.go (4)

38-38: Good addition of the EngineBlock constant

The addition of EngineBlock to the PartialDecodeSectionType enum aligns with the PR's objective to support parsing the engine block within the configuration.


333-333: Well-documented new feature

Documentation is properly updated to include the new EngineBlock in the list of blocks that can be parsed, which maintains good code documentation standards.


448-456: Previous review mentioned an unused "terragruntEngine"

A previous review comment mentioned that terragruntEngine seems to be unused. This variable doesn't appear in the current implementation. Please verify if this was addressed or is still relevant.

#!/bin/bash
# Check for occurrences of terragruntEngine in the codebase

rg "terragruntEngine" config/
🧰 Tools
🪛 golangci-lint (1.62.2)

455-455: assignments should only be cuddled with other assignments

(wsl)


448-456:

✅ Verification successful

Verify implementation completeness

The PR aims to allow Terraform commands in dependency blocks to use the engine configuration. Let's verify that the EngineBlock is properly used in the dependency-related code.


🏁 Script executed:

#!/bin/bash
# Check where EngineBlock is used in the codebase, particularly in dependency-related code

rg "EngineBlock" --type go
rg -A 10 "getTerragruntOutputJSON" config/dependency.go

Length of output: 5651


EngineBlock integration verified for dependency configuration

  • The engine block decoding in config/config_partial.go (lines 448–456) correctly decodes and assigns the Engine configuration.
  • In config/dependency.go, the call to PartialParseConfigFile includes EngineBlock (along with other blocks), ensuring that Terraform commands in dependency blocks can properly use the engine configuration.
  • No further changes are necessary.
🧰 Tools
🪛 golangci-lint (1.62.2)

455-455: assignments should only be cuddled with other assignments

(wsl)

@yhakbar
Copy link
Collaborator

yhakbar commented Mar 6, 2025

Do you have any thoughts on this? Or is it enough to just have a test that uses 2 modules with dependencies?

It can be as simple as checking logs to verify that the engine was run twice:

$ eza -T
.
├── dependency
│   ├── main.tf
│   └── terragrunt.hcl
└── dependent
    ├── main.tf
    └── terragrunt.hcl
$ fd -tf -x bash -c 'echo "# {}" && cat {} && echo'
# ./dependency/terragrunt.hcl
engine {
  source  = "github.com/gruntwork-io/terragrunt-engine-opentofu"
  version = "v0.0.16"
}


# ./dependent/terragrunt.hcl
engine {
  source  = "github.com/gruntwork-io/terragrunt-engine-opentofu"
  version = "v0.0.16"
}


dependency "dependency" {
  config_path = "../dependency"
}

# ./dependency/main.tf
output "foo" {
        value = "foo"
}

# ./dependent/main.tf

$ terragrunt plan --experimental-engine
15:22:53.810 ERROR  [../dependency] tofu: Tofu Initialization started
15:22:53.810 ERROR  [../dependency] tofu: Tofu Initialization completed
15:22:53.881 INFO   [../dependency] tofu: Initializing the backend...
15:22:53.882 INFO   [../dependency] tofu: Initializing provider plugins...
15:22:53.882 INFO   [../dependency] tofu: OpenTofu has been successfully initialized!
15:22:53.882 INFO   [../dependency] tofu:
15:22:53.882 INFO   [../dependency] tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
15:22:53.882 INFO   [../dependency] tofu: any changes that are required for your infrastructure. All OpenTofu commands
15:22:53.882 INFO   [../dependency] tofu: should now work.
15:22:53.882 INFO   [../dependency] tofu: If you ever set or change modules or backend configuration for OpenTofu,
15:22:53.882 INFO   [../dependency] tofu: rerun this command to reinitialize your working directory. If you forget, other
15:22:53.882 INFO   [../dependency] tofu: commands will detect it and remind you to do so if necessary.
15:22:53.936 ERROR  tofu: Tofu Initialization started
15:22:53.937 ERROR  tofu: Tofu Initialization completed
15:22:53.969 INFO   tofu: Initializing the backend...
15:22:53.970 INFO   tofu: Initializing provider plugins...
15:22:53.970 INFO   tofu: OpenTofu has been successfully initialized!
15:22:53.970 INFO   tofu:
15:22:53.970 INFO   tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
15:22:53.970 INFO   tofu: any changes that are required for your infrastructure. All OpenTofu commands
15:22:53.970 INFO   tofu: should now work.
15:22:53.970 INFO   tofu: If you ever set or change modules or backend configuration for OpenTofu,
15:22:53.971 INFO   tofu: rerun this command to reinitialize your working directory. If you forget, other
15:22:53.971 INFO   tofu: commands will detect it and remind you to do so if necessary.
15:22:54.009 STDOUT tofu: No changes. Your infrastructure matches the configuration.
15:22:54.010 STDOUT tofu: OpenTofu has compared your real infrastructure against your configuration and
15:22:54.010 STDOUT tofu: found no differences, so no changes are needed.
15:22:54.013 ERROR  [../dependency] tofu: Tofu Shutdown completed
15:22:54.015 ERROR  [../dependency] 2025-03-06T15:22:54.015-0500 [INFO]  plugin process exited: plugin=../../../.cache/terragrunt/plugins/iac-engine/rpc/v0.0.16/darwin/arm64/terragrunt-iac-engine-opentofu_rpc_v0.0.16_darwin_arm64 id=40806
15:22:54.017 ERROR  tofu: Tofu Shutdown completed
15:22:54.019 ERROR  2025-03-06T15:22:54.019-0500 [INFO]  plugin process exited: plugin=../../../.cache/terragrunt/plugins/iac-engine/rpc/v0.0.16/darwin/arm64/terragrunt-iac-engine-opentofu_rpc_v0.0.16_darwin_arm64 id=40809

It's brittle, and ideally, we would have a better method of verifying this kind of thing, but that's not really in scope for this PR. As long as we can verify that it's working in tests, we're good. If this test fails because we adjust logging too much, then we can create a better system.

I created #3980 while playing with this, as we can do much better at communicating to users that they're using an engine than what's displayed here.

@partcyborg
Copy link
Contributor Author

It can be as simple as checking logs to verify that the engine was run twice:

I have now added an integration test that includes a terragrunt dependency block and verifies that it uses the engine for both tofu output -json and tofu apply by reading the debug logs.

Thanks @yhakbar and @denis256 for your help!

@partcyborg partcyborg requested a review from yhakbar March 6, 2025 23:41
if_exists = "overwrite_terragrunt"
}
config = {
path = "${get_terragrunt_dir()}/terraform.tfstate"
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: always bias towards OpenTofu. Don't change this now, we can edit after this PR.

yhakbar
yhakbar previously approved these changes Mar 7, 2025
@yhakbar
Copy link
Collaborator

yhakbar commented Mar 7, 2025

Everything looks good, @partcyborg .

If tests pass, I'll merge this in. Thanks for contributing this! We're invested in your success with engines. Keep us in the loop as you adopt them.

@partcyborg
Copy link
Contributor Author

Everything looks good, @partcyborg .

If tests pass, I'll merge this in. Thanks for contributing this! We're invested in your success with engines. Keep us in the loop as you adopt them.

Thanks @yhakbar again for all your help.

I noticed that integration_test_terraform_aws is failing, but unfortunately I can't see why as I can't login to your circleci. Is there something I need to fix with my code to make this test pass again?

@yhakbar
Copy link
Collaborator

yhakbar commented Mar 7, 2025

Is there something I need to fix with my code to make this test pass again?

Hey @partcyborg

Sorry, I was looking into this issue, then got sidetracked. This is the assertion that's failing in TestDependenciesOptimisation:
https://github.com/partcyborg/terragrunt/blob/engine-dependencies/test/integration_test.go#L3090-L3091

You should be able to run that test locally to investigate.

I'm not sure why it's failing for you, but we will need that resolved before we can merge.

@partcyborg
Copy link
Contributor Author

partcyborg commented Mar 7, 2025

Is there something I need to fix with my code to make this test pass again?

Hey @partcyborg

Sorry, I was looking into this issue, then got sidetracked. This is the assertion that's failing in TestDependenciesOptimisation: https://github.com/partcyborg/terragrunt/blob/engine-dependencies/test/integration_test.go#L3090-L3091

You should be able to run that test locally to investigate.

I'm not sure why it's failing for you, but we will need that resolved before we can merge.

Thanks again @yhakbar for the quick followup. I found two problems with the code:

  1. My added support for parsing engine blocks to PartialParseConfig was not working. This was causing terragrunt to always skip the dependency optimization path. I have fixed this and confirmed the parsing is working correctly and the TestDependenciesOptimisation test is now passing.
  2. This caused the new TestEngineDependency test to fail because terragrunt was now using the optimized path for fetching the dependency which specifically bypasses additional functionality such as IaC engines. To resolve this, I have disabled the optimized dependency codepath when engines are enabled.

Please let me know if this is the right approach, as it did not appear to be appropriate to try and inject the engine functionality into the optimized codepaths.

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)
config/config_partial.go (1)

455-462: Fix code style: address linting issues

The implementation of the EngineBlock case follows the same pattern as other cases, but there are code style violations from the linter regarding "cuddled" assignments.

Consider adding a blank line after line 461 to address the linting issues:

			}
			output.Engine = decoded.Engine
+
🧰 Tools
🪛 golangci-lint (1.62.2)

461-461: assignments should only be cuddled with other assignments

(wsl)


458-458: only one cuddle assignment allowed before if statement

(wsl)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 31bed9b and c94a2b3.

📒 Files selected for processing (2)
  • config/config_partial.go (4 hunks)
  • config/dependency.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/dependency.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code for quality and correctness. M...

**/*.go: Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

  • config/config_partial.go
🧠 Learnings (1)
config/config_partial.go (1)
Learnt from: partcyborg
PR: gruntwork-io/terragrunt#3974
File: config/config_partial.go:448-456
Timestamp: 2025-03-06T23:44:09.413Z
Learning: The TerragruntConfig struct in config/config.go does contain an Engine field that's used to store engine configuration data.
🪛 golangci-lint (1.62.2)
config/config_partial.go

461-461: assignments should only be cuddled with other assignments

(wsl)


458-458: only one cuddle assignment allowed before if statement

(wsl)

🔇 Additional comments (3)
config/config_partial.go (3)

38-38: LGTM: New engine block constant

Adding EngineBlock to the PartialDecodeSectionType enum follows the same pattern as other configuration block types.


122-126: LGTM: New terragruntEngine struct

The terragruntEngine struct is well-defined and follows the same pattern as other block-specific structs in the file, with an Engine field for the parsed configuration and a Remain field for any additional HCL content.


339-339: LGTM: Documentation update

Documentation for PartialParseConfigString function has been properly updated to include the new EngineBlock type.

@partcyborg
Copy link
Contributor Author

Actionable comments posted: 0

🧹 Nitpick comments (1)

config/config_partial.go (1)> 455-462: Fix code style: address linting issues

The implementation of the EngineBlock case follows the same pattern as other cases, but there are code style violations from the linter regarding "cuddled" assignments.
Consider adding a blank line after line 461 to address the linting issues:

			}
			output.Engine = decoded.Engine
+

🧰 Tools

🪛 golangci-lint (1.62.2)
461-461: assignments should only be cuddled with other assignments
(wsl)

458-458: only one cuddle assignment allowed before if statement
(wsl)

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

📥 Commits
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used
🔇 Additional comments (3)

I don't understand this comment. There is already a blank line after output.Engine = decoded.Engine. Line 462 is blank, and I don't think there should be 2 blank lines

@yhakbar
Copy link
Collaborator

yhakbar commented Mar 7, 2025

I don't understand this comment. There is already a blank line after output.Engine = decoded.Engine. Line 462 is blank, and I don't think there should be 2 blank lines

Sometimes the AI makes mistakes. If it seems wrong, just ignore it. If you don't have golangci-lint configured for your editor, I recommend doing that. It's the easiest way to make sure this isn't an issue in our CI.

Please let me know if this is the right approach, as it did not appear to be appropriate to try and inject the engine functionality into the optimized codepaths.

The optimized codepath being taken here is a short circuit when attempting to parse dependencies, preventing dependencies of dependencies from being parsed. For the most part, nothing about engines should be affecting that, so I'm confused as to why your changes had any impact on that. We parse things like the terraform block from dependencies, we just explicitly don't parse things like inputs, because those can rely on the dependencies block, which can trigger cascading dependency parsing. This optimization is only done when the skip-dependencies-inputs strict control is enabled, so I don't think your overall approach was wrong.

I can look into this a bit further next week.

@partcyborg
Copy link
Contributor Author

I don't understand this comment. There is already a blank line after output.Engine = decoded.Engine. Line 462 is blank, and I don't think there should be 2 blank lines

Sometimes the AI makes mistakes. If it seems wrong, just ignore it. If you don't have golangci-lint configured for your editor, I recommend doing that. It's the easiest way to make sure this isn't an issue in our CI.

Please let me know if this is the right approach, as it did not appear to be appropriate to try and inject the engine functionality into the optimized codepaths.

The optimized codepath being taken here is a short circuit when attempting to parse dependencies, preventing dependencies of dependencies from being parsed. For the most part, nothing about engines should be affecting that, so I'm confused as to why your changes had any impact on that. We parse things like the terraform block from dependencies, we just explicitly don't parse things like inputs, because those can rely on the dependencies block, which can trigger cascading dependency parsing. This optimization is only done when the skip-dependencies-inputs strict control is enabled, so I don't think your overall approach was wrong.

I can look into this a bit further next week.

I guess I could refactor setupTerragruntOptionsForBareTerraform() so it accepts the engine config as well as the iam role options so that the resulting TerragruntOptions struct has the correct values. I will look into this if it is worth holding on to the optimized path for engine usage.

@partcyborg
Copy link
Contributor Author

I don't understand this comment. There is already a blank line after output.Engine = decoded.Engine. Line 462 is blank, and I don't think there should be 2 blank lines

Sometimes the AI makes mistakes. If it seems wrong, just ignore it. If you don't have golangci-lint configured for your editor, I recommend doing that. It's the easiest way to make sure this isn't an issue in our CI.

Please let me know if this is the right approach, as it did not appear to be appropriate to try and inject the engine functionality into the optimized codepaths.

The optimized codepath being taken here is a short circuit when attempting to parse dependencies, preventing dependencies of dependencies from being parsed. For the most part, nothing about engines should be affecting that, so I'm confused as to why your changes had any impact on that. We parse things like the terraform block from dependencies, we just explicitly don't parse things like inputs, because those can rely on the dependencies block, which can trigger cascading dependency parsing. This optimization is only done when the skip-dependencies-inputs strict control is enabled, so I don't think your overall approach was wrong.

I can look into this a bit further next week.

This was easier than I thought to wire through. I shouldn't have given up so easily 🙂

Engines now work as expected for dependencies in both the optimized path and the un-optimized path.

@yhakbar
Copy link
Collaborator

yhakbar commented Mar 8, 2025

Setting a reminder to review this on Monday.

Great job, @partcyborg !

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.

Iac Engines not used for dependency blocks
3 participants