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

extra_arguments doesn't work when downloading remote Terraform configurations #143

Closed
brikis98 opened this issue Feb 22, 2017 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@brikis98
Copy link
Member

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::git@github.com: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.

@brikis98
Copy link
Member Author

brikis98 commented Feb 22, 2017

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?

@jmlrt
Copy link

jmlrt commented Mar 9, 2017

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::git@github.com:foo/bar.git//frontend-app?ref=v0.0.3"
  }

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

@brikis98
Copy link
Member Author

Fix here: #168. Feedback welcome!

@brikis98 brikis98 reopened this Apr 20, 2017
@brikis98
Copy link
Member Author

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

@brikis98
Copy link
Member Author

Fixed by #170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants