Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

[question] directory structure when using terragrunt.hcl files and kitchent-terraform #455

Closed
lmayorga1980 opened this issue Jun 2, 2021 · 2 comments
Labels
question ruby gem unresolved Issues that were not resolved before the project was archived.

Comments

@lmayorga1980
Copy link

I have the following directory structure where the terraform modules are in a specific folder and the terragrunt files reference those modules from an environment/region path.

Screen Shot 2021-06-02 at 10 58 31 AM

The lower level terragrunt.hcl files from each environment/region reference the parent terragunt.hcl at the root level.

I am using the following kitchen.ymljust to kick tires.

---
driver:
  name: terraform
provisioner:
  name: terraform
verifier:
  name: terraform
  fail_fast: false
platforms:
  - name: osx
    driver:
      client: ./terragrunt_darwin_amd64
suites:
  - name: attributes
    driver:
      root_module_directory: modules/compute
      variable_files:
        - test/terraform/compute.variables.tfvars
    verifier:
      systems:
        - name: default
          backend: local
          profile_locations:
            - test/integration/compute
          controls:
            - compute
          reporter:
            - cli

I am getting the following error:

D      Message: Running the command `/Users/user1/repos/tf-gcloud/terragrunt_darwin_amd64 version` failed due to a non-zero exit code of 1.
D      ----------------------
D      ------Backtrace-------
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/kitchen-terraform-5.8.0/lib/kitchen/terraform/raise/action_failed.rb:32:in `call'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/kitchen-terraform-5.8.0/lib/kitchen/driver/terraform.rb:191:in `rescue in destroy'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/kitchen-terraform-5.8.0/lib/kitchen/driver/terraform.rb:188:in `destroy'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:495:in `public_send'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:495:in `block in perform_action'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:560:in `block in synchronize_or_call'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:558:in `synchronize'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:558:in `synchronize_or_call'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:524:in `block in action'
D      /Users/user1/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:523:in `action'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:495:in `perform_action'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:482:in `destroy_action'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:392:in `block (2 levels) in transition_to'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/lifecycle_hooks.rb:47:in `run_with_hooks'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:391:in `block in transition_to'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:390:in `each'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:390:in `transition_to'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:172:in `destroy'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:188:in `block in test'
D      /Users/user1/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/benchmark.rb:293:in `measure'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/instance.rb:186:in `test'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/command.rb:195:in `public_send'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/command.rb:195:in `run_action_in_thread'
D      /Users/user1/.rvm/gems/ruby-2.7.2/gems/test-kitchen-2.11.2/lib/kitchen/command.rb:166:in `block (2 levels) in run_action'
D      ----End Backtrace-----

If I run terragrunt version from the local binary in the relative path i get the following...

06-2-21 11:00:29  tf-gcloud git:(dev) ✗  $ ./terragrunt_darwin_amd64 version  
Error: Invalid index

  on /Users/user1/repos/tf-gcloud/terragrunt.hcl line 2, in locals:
   2:   env_name = split("/", path_relative_to_include())[1]

The given key does not identify an element in this collection value.

ERRO[0000] Encountered error while evaluating locals.   
ERRO[0000] /Users/user1/repos/tf-gcloud/terragrunt.hcl:2,52-55: Invalid index; The given key does not identify an element in this collection value. 
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1

This is because terragrunt is trying to validate the root terragunt.hcl which is not intended since the plan/appy are executed within the environment/region terragrunt files.

Screen Shot 2021-06-02 at 11 06 22 AM

Maybe kitchen-terraform needs to run ./terragrunt<binary> --version?

@aaron-lane
Copy link
Collaborator

Hi @lmayorga1980!

Unfortunately, terragrunt --version only returns the version of Terragrunt, while terragrunt version runs the command terraform --version (not terraform version 🤷🏼) and provides the information that we need to confirm compatibility with Kitchen-Terraform. Could you work around this issue by including an empty terragrunt.hcl file in the root directory?

@lmayorga1980
Copy link
Author

I was thinking on leveling the tree down one level so the root is only with that empty terragrunt.hcl and kitchen.yml and the actual parent reusable terragrunt.hcl goes down 1 level.

That could work.

@aaron-lane aaron-lane added the unresolved Issues that were not resolved before the project was archived. label Oct 22, 2024
@aaron-lane aaron-lane closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question ruby gem unresolved Issues that were not resolved before the project was archived.
Projects
None yet
Development

No branches or pull requests

2 participants