gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.06k stars 979 forks source link

terragrunt crash on parsing root terraform.tfvars #592

Closed goseeped closed 4 years ago

goseeped commented 6 years ago

terragrunt version v0.17.1 Terraform v0.11.10 OS macOS 10.12.6 Provider : GCP

├── account.tfvars
├── infra
│   ├── network
│   │   ├── pan
│   │   │   └── terraform.tfvars
│   │   └── vpc
│   │       └── terraform.tfvars
│   └── project
│       └── terraform.tfvars
├── terraform.tfvars

Having root terraform.tfvars

terragrunt = {
  Configure Terragrunt to automatically store tfstate files in an GCS bucket
  remote_state {
    backend = "gcs"
    config {
      bucket         = "terraform-non-prod-state"
      prefix         = "${path_relative_to_include()}"
      region         = "us-west2"
      project        = "terraform-123456"
    }
  }

  terraform {
    extra_arguments "bucket" {
      commands = "${get_terraform_commands_that_need_vars()}"
      optional_var_files = [
        "${get_tfvars_dir()}/${find_in_parent_folders("account.tfvars")}"
      ]
    }
  }
}

and this is the terraform.tfvars on the module vpc

terragrunt = {
  # Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
  # working directory, into a temporary folder, and execute your Terraform commands in that folder.
  terraform {
    # replace here an local URL to use the proper module for development if you clone and want to change/test
    source = "../../../../../../terraform-infra-modules/gcp/infra//network/vpc"

  }

  include = {
    path = "${find_in_parent_folders()}"
  }

  dependencies {
    paths = ["../../project"]
  }

}

Seems like the crash happens when adding the include with path = "${find_in_parent_folders()}" if I comment the include terragrunt won't crash but i can't add global vars in account.tfvars :(

Crash :(

TF_LOG=DEBUG TERRAGRUNT_DEBUG="true" terragrunt plan
[terragrunt] [/Users/jriveros/git/terraform-infra-live/non-prod/gcp/infra/network/vpc] 2018/10/26 17:31:32 Running command: terraform --version
[terragrunt] 2018/10/26 17:31:32 Reading Terragrunt config file at /Users/jriveros/git/terraform-infra-live/non-prod/gcp/infra/network/vpc/terraform.tfvars
[terragrunt] 2018/10/26 17:31:32 *parser.PosError At 16:36: expected: IDENT | STRING | ASSIGN | LBRACE got: COMMA
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:328 (0x1480bdc)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:287 (0x148076c)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:272 (0x1480529)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:464 (0x1481a30)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:308 (0x1480800)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:272 (0x1480529)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/config/config.go:257 (0x1480414)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:222 (0x150e44b)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:212 (0x150e3d1)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/cli/cli_app.go:193 (0x150e0c5)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/vendor/github.com/urfave/cli/app.go:502 (0x14b0e38)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/src/github.com/gruntwork-io/terragrunt/vendor/github.com/urfave/cli/app.go:268 (0x14aef37)
/private/tmp/terragrunt-20181016-67933-1wfys8l/terragrunt-0.17.1/main.go:20 (0x1515cd4)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/proc.go:201 (0x102dcd7)
/usr/local/Cellar/go/1.11.1/libexec/src/runtime/asm_amd64.s:1333 (0x1059591)

[terragrunt] 2018/10/26 17:31:32 Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Not sure if this more a configuration issue or recently terragrunt change this I try to check for weird character or something,

brikis98 commented 6 years ago

"${get_tfvars_dir()}/${find_in_parent_folders("account.tfvars")}"

If you remove this temporarily, does the error go away? Nested quotes are supported by Terraform, but not HCL / Terragrunt.

goseeped commented 6 years ago

@brikis98 I found the issue, forget to put in the commands = [""] i carry the error from here xD

I had

commands = "${get_terraform_commands_that_need_vars()}"

instead of

commands = ["${get_terraform_commands_that_need_vars()}"]

Now it worked :)

-probably an exception in the future rather than a crash? -you want me to do another test?

brikis98 commented 6 years ago

Ah, OK. Yes, we should handle that error better! PR to fix that error handling is very welcome.

conorgil commented 5 years ago

@goseeped I was just looking through old issues seeing if anything could possibly be closed out. Has the change to HCL2 support in terragrunt 0.19 resolved this issue?

brikis98 commented 4 years ago

Switching to HCL2 has likely fixed this, and this issue is a year old, so closing.