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

Terragrunt files #34

Open
nilsdebruin opened this issue Jan 28, 2021 · 3 comments
Open

Terragrunt files #34

nilsdebruin opened this issue Jan 28, 2021 · 3 comments

Comments

@nilsdebruin
Copy link

It could be interesting to include terragrunt.hcl files to the version check. Terragrunt files have the following terraform configuration block (this is an example):

terraform {
source = "git@github.com:terraform-aws-modules/terraform-aws-iam.git//modules/iam-assumable-roles?ref=v2.21.0"
}

Do you know how this could be implemented?

@sgreben
Copy link
Member

sgreben commented Feb 9, 2021

Hi @nilsdebruin, sorry about the late response - last month was a busy one for me.. I had a look at how Terragrunt does config parsing, and it looks like it actually provides a way to parse just those terraform { source=... } blocks:

I think we should be able to generate ModuleCall structs from these. I gave it a shot in #35 - could you have a look at that? I'm not really familiar with Terragrunt, so someone who actually uses it should definitely review that PR 😄

The meat of it is the file pkg/scan/terragrunt.go, the rest of the diff consists almost entirely of changes to vendored packages.

Here's how its output looks right now:

$ terraform-module-versions -terragrunt=true list examples 
TYPE NAME CONSTRAINT VERSION SOURCE
registry consul ~0.7.3 hashicorp/consul/aws
local local ./local
git examples/terragrunt.hcl v2.21.0 git@github.com:terraform-aws-modules/terraform-aws-iam.git//modules/iam-assumable-roles?ref=v2.21.0
git example_git_ssh_branch master git::ssh://git@github.com/keilerkonzept/terraform-module-versions?ref=master
git example_git_scp ~> 0.12 0.12.0 git::git@github.com:keilerkonzept/terraform-module-versions?ref=0.12.0
git consul_github_ssh ~0.1.0 0.1.0 git@github.com:hashicorp/terraform-aws-consul?ref=0.1.0
git consul_github_https_no_ref github.com/hashicorp/terraform-aws-consul
git consul_github_https_missing_ref 0.7.3 github.com/hashicorp/terraform-aws-consul
git consul_github_https 0.8.0 v0.8.0 github.com/hashicorp/terraform-aws-consul?ref=v0.8.0
$ terraform-module-versions -terragrunt=true check examples 
UPDATE? NAME CONSTRAINT VERSION LATEST MATCHING LATEST
(Y) consul ~0.7.3 0.7.11 0.8.4
(Y) consul_github_https 0.8.0 v0.8.0 v0.8.4
(Y) consul_github_https_missing_ref 0.7.3 v0.7.3 v0.8.4
(Y) consul_github_https_no_ref v0.8.4
Y consul_github_ssh ~0.1.0 0.1.0 v0.1.2 v0.8.4
(Y) example_git_scp ~> 0.12 0.12.0 3.0.9
(Y) example_git_ssh_branch master 3.0.9
(Y) examples/terragrunt.hcl v2.21.0 v3.8.0

@nilsdebruin
Copy link
Author

nilsdebruin commented Feb 10, 2021

Hi @sgreben, don't worry, thank you for your time and effort! I am really appreciating that you are taking the time to dive into this. As I am not a Go developer, I can only look at it from a functional perspective. I checked out your code, build it, and tested it on a directory with .hcl files. I can validate that it works for this first example, really cool!

I have included a more elaborate example in the examples directory which I have submitted as a PR: #39. This is a more extended example, which is based on the following repo: https://github.com/gruntwork-io/terragrunt-infrastructure-live-example.

When I run the Terragrunt version as follows:

./binaries/osx_x86_64/terraform-module-versions -terragrunt check examples/

I get the following output:

Error: Error in function call

  on examples/terragrunt-example/terraform/terragrunt.hcl line 9, in locals:
   9:   global_vars = read_terragrunt_config(find_in_parent_folders("global.hcl"))

Call to function "find_in_parent_folders" failed: ParentFileNotFound: Could not find a global.hcl in any of the parent folders of examples. Cause: Traversed
all the way to the root..`

ERRO[0000] Encountered error while evaluating locals.   
[terraform-module-versions] read terragrunt config "examples/terragrunt-example/terraform/terragrunt.hcl": examples/terragrunt-example/terraform/terragrunt.hcl:9,40-63: Error in function call; Call to function "find_in_parent_folders" failed: ParentFileNotFound: Could not find a global.hcl in any of the parent folders of examples. Cause: Traversed all the way to the root..

I think this is due to the fact that a terragrunt function is triggerd which is present in the .hcl file, namely:

find_in_parent_folders()

I am unsure if this can turned off and that the file can be scanned / parsed as is. I can imagine that this is quite a complex problem, so I understand if you just leave it at the first iteration (which in my opinion is already very cool!)

@zen
Copy link

zen commented Dec 29, 2021

This would be great feature man. Let me know if I can help somehow, but my Go knowledge is near to zero :(

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

No branches or pull requests

3 participants