Terragrunt: extra_arguments doesn't work when downloading remote Terraform configurations

Created on 22 Feb 2017  Â·  5Comments  Â·  Source: gruntwork-io/terragrunt

Imagine you have the following folder structure:

infra-live
â”” global.tfvars
â”” stage
    â”” terraform.tfvars

The stage/terraform.tfvars has the following contents:

terragrunt = {
  terraform {
    source = "git::[email protected]:foo/bar.git//frontend-app?ref=v0.0.3"
  }

  extra_arguments "global" {
    arguments = [
      "-var-file=terraform.tfvars",
      "-var-file=../global.tfvars"
    ]
  }
}

When you run terragrunt apply in stage, it will fail, because it will download the Terraform code into a temporary folder, switch to that folder, and then try to use the relative path to global.tfvars. Since global.tfvars is in the infra-live folder and not the temp folder, it won't find it.

enhancement help wanted

Most helpful comment

Ideas on possible fixes:

  1. Explicitly parse extra_arguments for -var-file arguments and automatically copy those into the proper folder structure in the temporary folder. This sounds like it would be very messy.

  2. Instead of downloading code into a temporary folder, download it into the current folder, run Terraform, and then clean up. Again, this sounds like it would be very messy.

  3. Add a new helper similar to ${path.module}. For example:

    arguments = [
      "-var-file=${path.module}/terraform.tfvars",
      "-var-file=${path.module}/../global.tfvars"
    ]
    

    Terragrunt would automatically fill in the path of the original working directory, so those relative paths would become absolute paths.

The third option seems like the proper solution and it should be pretty easy to implement. Anyone up for a PR?

All 5 comments

Ideas on possible fixes:

  1. Explicitly parse extra_arguments for -var-file arguments and automatically copy those into the proper folder structure in the temporary folder. This sounds like it would be very messy.

  2. Instead of downloading code into a temporary folder, download it into the current folder, run Terraform, and then clean up. Again, this sounds like it would be very messy.

  3. Add a new helper similar to ${path.module}. For example:

    arguments = [
      "-var-file=${path.module}/terraform.tfvars",
      "-var-file=${path.module}/../global.tfvars"
    ]
    

    Terragrunt would automatically fill in the path of the original working directory, so those relative paths would become absolute paths.

The third option seems like the proper solution and it should be pretty easy to implement. Anyone up for a PR?

As a workaround you can symlink ../global.tfvars into your stage directory and reference the symlink file into the extra_argument block. This way you can reuse the same global.tfvars everywhere without code duplication.

example:

infra-live
â”” global.tfvars
â”” stage
    â”” terraform.tfvars
    â”” global.tfvars (symlink -> ../global.tfvars)

stage/terraform.tfvars:

terragrunt = {
  terraform {
    source = "git::[email protected]:foo/bar.git//frontend-app?ref=v0.0.3"
  }

  extra_arguments "global" {
    arguments = [
      "-var-file=terraform.tfvars",
      "-var-file=global.tfvars"
    ]
  }
}

Whoops, meant to hit comment, but hit close. Reopened this one until #168 is merged :)

Fixed by #170.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MacFlurry picture MacFlurry  Â·  4Comments

Tensho picture Tensho  Â·  3Comments

GauntletWizard picture GauntletWizard  Â·  3Comments

mmorianos picture mmorianos  Â·  3Comments

antonbabenko picture antonbabenko  Â·  3Comments