Git Product home page Git Product logo

Comments (3)

dmattia avatar dmattia commented on August 16, 2024 1

Upgrading to v0.5.0 should fix your issue, as I added in the HCL parsing. Please let me know if that fix didn't solve your problem :)

from terragrunt-atlantis-config.

dmattia avatar dmattia commented on August 16, 2024

This is certainly an interesting bug! Thanks, @gmaghera for finding this

Why this bug happens

We currently follow this pseudocode:

files := find_all_terragrunt_files()
for file in files:
  parsed := parseFile(file)
  if the parsed file does not have a Terragrunt.Source value and --ignore-parent-terragrunt is on:
    skip this file
  else do all the dependency analysis stuff

The real life code is here: https://github.com/transcend-io/terragrunt-atlantis-config/blob/master/cmd/generate.go#L103-L112

The parseFile in that pseudocode is actually using Terragrunt's parser, imported directly from their repo.

The error you are showing comes directly from the Terragrunt parser

Why it's hard to fix this bug

If we don't use the parser, we cannot easily tell if a file is a parent terragrunt file or not. And then we don't know to skip that top level terragrunt.hcl file.

If we do use the Terragrunt parser, we get an error. This isn't so bad, except the error message is useless in this context. Terragrunt always parses locals first, so even if we could detect exactly the error in your output, we still wouldn't know if the file was a parent file or not.

Workaround

As this fix may take a bit of time to create, here is a workaround: You could change the name of the top level terragrunt.hcl file to anything else, such as parent.hcl, and then update your child path = find_in_parent_folders() expressions to be path = find_in_parent_folders("parent.hcl")

This works because this repo uses the FindConfigFilesInPath directly from Terragrunt to determine which files are terraform modules: https://github.com/gruntwork-io/terragrunt/blob/24d9a82dd5c45aa0a08d56bafb95b3ffe8eb5a30/config/config.go#L237 and that function only looks for files named terragrunt.hcl or terragrunt.hcl.json: https://github.com/gruntwork-io/terragrunt/blob/24d9a82dd5c45aa0a08d56bafb95b3ffe8eb5a30/config/config.go#L22

At my company, we do this workaround, but not because we knew of the bug, but just because we have a few differently named parent config files we switch between based on infra environment.

Actual fix

I think the only good fix here is to determine if a terragrunt file is a parent, while not parsing it with Terragrunt's parser, which means we'll need to parse the HCL on our own. I haven't done this before, but it doesn't look too awful.

from terragrunt-atlantis-config.

gmaghera avatar gmaghera commented on August 16, 2024

Thank you David for the thoughtful analysis and the suggested workaround. They both make sense.

from terragrunt-atlantis-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.