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

New command graph has wrong parameter documentation (+ potential anomaly when running in monorepo) #3342

Open
ziererfl opened this issue Aug 13, 2024 · 4 comments
Assignees
Labels
awaiting response Waiting for a response or more data from issue reporter bug Something isn't working

Comments

@ziererfl
Copy link

Describe the bug

Let me start by saying thank you for the great value and improvements you provide to the community with terragrunt!

My first remark is that the documentation for the new command terragrunt graph <command> states --graph-root as a parameter for the root (by default the git root dir), but it should be --terragrunt-graph-root.

My second remark is that I encountered a weird phenomenon within my monorepo where I have in the git-root three completely decoupled environment directories: terragrunt graph plan escaped my current env-directory and travesed into another env-directory.

Steps To Reproduce

For the first remark:

terragrunt graph plan --graph-root foo/bar/path
ERRO[0000] flag provided but not defined: -graph-root
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1

For the second remark:
In my git root directory I have no terragrunt.hcl. For each environment dev, test, and prod, I have a dedicated directory, each with a root terragrunt.hcl.

When inside a deep directory dir-1 within dev which depends on another dir-2 inside dev and this dir-2 is refering a local file next to its own terragrunt.hcl using get_terragrunt_dir(), e.g., a SOPS encrypted secret like this:

locals {
  secret_values = yamldecode(sops_decrypt_file("${get_terragrunt_dir()}/secrets.yaml"))
}

then terragrunt ended up in test trying to fetch the secrets.yaml found inside test environment.

When I run with

terragrunt graph plan --terragrunt-graph-root <PATH TO DEV-DIR>

then this anomaly does not happen.

Expected behavior

For my first remark:
Either the documentation is updated or the command accepts the key specified at the moment in the documentation.

For my second remark:
Running terragrunt graph plan in a mono-repo containing several envs should not attempt to touch files in a neighbouring environment directory.

Nice to haves

For my first remark:

For my second remark:
I might try creating a hello-world example but lack time right now (also to rule out any other anomalies due to my setup). Till then I was hoping that some experienced person could tell me if this is a false-positive and terragrunt graph is meant to behave like that.

Versions

  • Terragrunt version: v0.66.3
  • OpenTofu/Terraform version: v1.9.4
  • Environment details (Ubuntu 20.04, Windows 10, etc.): darwin_arm64

Additional context

n/a

@ziererfl ziererfl added the bug Something isn't working label Aug 13, 2024
@alex-candfield
Copy link

The graph command seems to be broken, or at least not working with most setups, at the moment. There are many open issues already on this topic.

@ziererfl
Copy link
Author

Thanks for the hint!

Regarding my second remark in this issue, I might implement my own alternative to have a similar look-and-feel: Invoke terragrunt graph-dependencies on the root terragrunt.hcl, then use the digraph to detect all northbound dependencies to my current directory, e.g., dir-1 in my example should have its its dependency dir-2 --> dir-1 visible in the root level digraph. --- Just a random idea, but sounds easy to implement as a custom/home-grown workaround.

PS: I noticed another issue I have no clue how to invoke the terraform command terraform graph via terragrunt now. I will check if an open issue exists and otherwise create a new one.

@denis256 denis256 self-assigned this Aug 14, 2024
@yhakbar
Copy link
Collaborator

yhakbar commented Jan 10, 2025

Hey folks, could I ask that we get a fixture that allows us to reproduce the issue you're experiencing with the Terragrunt graph command? In general, it's really helpful to have a public repo or some code we can copy + paste to reproduce the issues that users face when investigating bugs.

If you need to use the OpenTofu/Terraform graph command, right now the easiest way to do that is to manually invoke it within the .terragrunt-cache directory.

In the future, you'll be able to use the following command to do that:

terragrunt run graph

We're actively working on the CLI Redesign, with the first feature being developed being related to the new exec and run commands for this kind of thing.

Feedback is encouraged!

@yhakbar
Copy link
Collaborator

yhakbar commented Jan 10, 2025

You can try out this alpha I cut today with current progress if you'd like:

$ terragrunt run --log-disable --experiment cli-redesign graph
digraph {
        compound = "true"
        newrank = "true"
        subgraph "root" {
                "[root] null_resource.empty (expand)" [label = "null_resource.empty", shape = "box"]
                "[root] provider[\"registry.opentofu.org/hashicorp/null\"]" [label = "provider[\"registry.opentofu.org/hashicorp/null\"]", shape = "diamond"]
                "[root] null_resource.empty (expand)" -> "[root] provider[\"registry.opentofu.org/hashicorp/null\"]"
                "[root] provider[\"registry.opentofu.org/hashicorp/null\"] (close)" -> "[root] null_resource.empty (expand)"
                "[root] root" -> "[root] provider[\"registry.opentofu.org/hashicorp/null\"] (close)"
        }
}

@yhakbar yhakbar added the awaiting response Waiting for a response or more data from issue reporter label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a response or more data from issue reporter bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants