https://infracost.io logo
#general
Title
# general
f

freezing-spoon-15505

09/29/2021, 1:42 PM
Hello, Using terragrunt in a monorepo with many modules, I am trying to run
infracost diff --path=/my/path/to/terragrunt/files
but I get
Copy code
Detected Terraform directory at .
  ✖ Running terraform plan 

  Terraform command failed with:
    Error: No configuration files
    Plan requires configuration to be present. Planning without a configuration
    would mark everything for destruction, which is normally not what is desired.
    If you would like to destroy everything, run plan with the -destroy option.
    Otherwise, create a Terraform configuration file (.tf file) and try again.

Error: Error running terraform plan: exit status 1
This is probably because I have a weird structure
Copy code
├── app-1
│   ├── aws-data
│   │   ├── <http://data.tf|data.tf>
│   │   └── terragrunt.hcl
│   ├── ec2-app
│   │   └── terragrunt.hcl
│   ├── iam-app-user
│   │   └── terragrunt.hcl
│   ├── iam-instance-profile
│   │   └── terragrunt.hcl
│   ├── iam-instance-profile-policy
│   │   └── terragrunt.hcl
│   ├── postgres-rds
│   │   └── terragrunt.hcl
├── ec2-prometheus
│   └── terragrunt.hcl
├── app-3
│   ├── iam-user
│   │   └── terragrunt.hcl
│   └── s3
│       └── terragrunt.hcl
If I use
infracost diff --path=./app-1
for example, then Infracost will use Terragrunt instead of Terraform and it will run successfully, however since it will execute
run-all
commands it will take a lot of time to finish which is a problem especially for the CI. Is there a workaround for this? Please let me know if I am missing something or if it is better to open a GH Issue for my case.
c

crooked-daybreak-55253

09/29/2021, 1:52 PM
Hi! First what version of infracost are you using? It looks like the CLI decided it was a terraform project (
Detected Terraform directory
). Are there files at
/my/path/to/terragrunt/files
that have an extension of
.tf
,
.hcl
,
.hcl.json
, or
.tf.json
?
f

freezing-spoon-15505

09/29/2021, 2:03 PM
Infracost v0.9.8
Yes there are 2
region.hcl
account.hcl
c

crooked-daybreak-55253

09/29/2021, 2:25 PM
Ok, those file are causing it to decide it’s a
terraform directory
. We have been debating adding something like a
--type
flag so people can explicitly state what their project is. It would be great if you could create a GH issue for your case. As far as work arounds, I can think of three and none of them are great: 1. Adding an empty
terragrunt.hcl
at
/my/path/to/terragrunt/files
will cause the CLI to recognize it as a terragrunt project. I’m not sure if this works, makes sense, or is even possible from a terragrunt perspective. 2. Moving
region.hcl
and
account.hcl
out of ``/my/path/to/terragrunt/files`` will make it search for the nested
terragrunt.hcl
files (up to 5 levels deep).
3. If you could point
--path
to a directory one level above
/my/path/to/terragrunt
it would also search for nested
terragrunt.hcl
(as long as there are no hcl/tf at that directory).
l

little-author-61621

09/29/2021, 5:39 PM
If I use infracost diff --path=./app-1 for example, then Infracost will use Terragrunt instead of Terraform and it will run successfully, however since it will execute run-all commands it will take a lot of time to finish which is a problem especially for the CI.
@freezing-spoon-15505 can you explain this case a little more please? Is running
terragrunt run-all
picking up resources that aren't in the
./app-1
directory?
f

freezing-spoon-15505

09/29/2021, 6:42 PM
I am sorry, there was a misconfiguration by me in this case. It works perfectly. Thanks!
🦜 1
🎉 1
Something that I have noticed. Having a big directory with many terragrunt modules and use run-all in this directory can lead to errors if some of the modules are not configured properly. Can Infracost ignore those errors and show output for the other modules?
w

white-airport-8778

09/30/2021, 1:15 PM
@freezing-spoon-15505 that’s not a bad idea, so the CLI would log the error and do skip that module vs failing the entire run? Can you please open a GH issue with a short desc and an example so we can track it? I suspect other Terragrunt users might be interested in this too
f

freezing-spoon-15505

09/30/2021, 2:17 PM
I will open it shortly. For the sake of conversation, Terragrunt is hard to use with many external tools due to how it runs modules and handles state. For example, having Infracost to run
terragrunt run-all plan
in a project with hundreds of modules to get the plan output, takes a lot of time. There is a similar problem with Atlantis which this project is trying to solve terragrunt-atlantis-config. It basically generates atlantis config with all the terragrunt modules that were changed. Hopefully we might see tools like this from the community, for Infracost too.
w

white-airport-8778

09/30/2021, 2:22 PM
Thanks! this is awesome context. I remember we discussed running step 3 of https://www.infracost.io/docs/iac_tools/terragrunt#how-the-terragrunt-integration-works in parallel but that won’t help if step 2 is the bottleneck (if I understood it correctly?)
f

freezing-spoon-15505

09/30/2021, 2:34 PM
Yes, that is correct. However, I'm not sure that this is something Infracost should handle.
👍 1
146 Views