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

Support for updating local modules when using Terragrunt #2145

Closed
Taiki130 opened this issue Dec 24, 2024 · 9 comments
Closed

Support for updating local modules when using Terragrunt #2145

Taiki130 opened this issue Dec 24, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@Taiki130
Copy link
Contributor

Taiki130 commented Dec 24, 2024

Feature Overview

Currently, the system supports updating local modules when using Terraform, but it does not support updating local modules when using Terragrunt.

Why is the feature needed?

When updating local modules in Terragrunt, the changes are not detected, and the plan is not triggered.

Example Code

No response

Note

Alternatively, enabling the ability to configure dependencies on directories or files related to the target could provide a viable alternative solution.

tfaction-root.yaml

  - working_directory: foo/bar
    target: foo/bar
    extra_dependencies:
      - modules
@Taiki130 Taiki130 added the enhancement New feature or request label Dec 24, 2024
@Taiki130 Taiki130 changed the title Support for Updating Local Modules in Terragrunt Support for Updating Local Modules when using Terragrunt Dec 24, 2024
@Taiki130 Taiki130 changed the title Support for Updating Local Modules when using Terragrunt Support for updating local modules when using Terragrunt Dec 24, 2024
@suzuki-shunsuke
Copy link
Owner

Thank you for reporting the issue.
I'll try to reproduce the issue.

Alternatively, enabling the ability to configure dependencies on directories or files related to the target could provide a viable alternative solution.

I think this issue is related.

@suzuki-shunsuke
Copy link
Owner

I see.

tfaction uses terraform-config-inspect to detect dependencies.

https://suzuki-shunsuke.github.io/tfaction/docs/feature/local-path-module/

But this tool can't resolve dependencies defined by Terragrunt.

https://github.com/suzuki-shunsuke/test-tfaction/blob/4de137787a1a242c27b20417908dda225a131c9c/terragrunt/terragrunt.hcl#L1-L3

terragrunt.hcl

terraform {
  source = "../module"
}
terraform-config-inspect --json terragrunt

Output:

{
  "path": "terragrunt",
  "variables": {},
  "outputs": {},
  "required_providers": {},
  "managed_resources": {},
  "data_resources": {},
  "module_calls": {}
}

@Taiki130
Copy link
Contributor Author

@suzuki-shunsuke Thank you for your investigation. I found that Terragrunt provides a useful command called render-json:
https://terragrunt.gruntwork.io/docs/reference/cli-options/#render-json
By using this command, we can get detailed JSON output. Here's an example:

terragrunt render-json --terragrunt-json-out /dev/stdout | jq

{
  "dependencies": null,
  "download_dir": "",
  "generate": {},
  "iam_assume_role_duration": null,
  "iam_assume_role_session_name": "",
  "iam_role": "",
  "iam_web_identity_token": "",
  "inputs": null,
  "locals": null,
  "retry_max_attempts": null,
  "retry_sleep_interval_sec": null,
  "retryable_errors": null,
  "terraform": {
    "after_hook": {},
    "before_hook": {},
    "copy_terraform_lock_file": null,
    "error_hook": {},
    "extra_arguments": {},
    "include_in_copy": null,
    "source": "../module"
  },
  "terraform_binary": "",
  "terraform_version_constraint": "",
  "terragrunt_version_constraint": ""
}

Since the JSON output includes the source of the dependent module, this might be a viable solution.

@suzuki-shunsuke
Copy link
Owner

Cool. Thank you for your suggestion!

@suzuki-shunsuke
Copy link
Owner

Could you try v1.15.0-0?

@Taiki130
Copy link
Contributor Author

Taiki130 commented Jan 2, 2025

@suzuki-shunsuke I tried with v1.15.0-0 and found an adjustment was necessary:

  • Environment Variables for Terragrunt Execution
    • I needed to set specific environment variables during the list-target action execution.
      • In my case, since I handle SOPS files using the sops_decrypt_file function, I had to export the key to decrypt.

After making this adjustment, the detection of local module changes worked as expected!

@suzuki-shunsuke
Copy link
Owner

Thank you for your feedback. Interesting.
I have no idea to improve tfaction to handle such a case.
You could solve the problem yourself, so seems like we don't need to do something, but if you have any idea please open a new issue.

Anyway, I think v1.15.0-0 works well, so I'm going to release v1.15.0.

@suzuki-shunsuke
Copy link
Owner

🎉 https://github.com/suzuki-shunsuke/tfaction/releases/tag/v1.15.0

@Taiki130
Copy link
Contributor Author

Taiki130 commented Jan 3, 2025

@suzuki-shunsuke I’ll take some time to think about whether there’s a better way to handle cases like this. Thanks for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants