transcend-io / terragrunt-atlantis-config

Generate Atlantis config for Terragrunt projects.
https://transcend.io/blog/why-we-use-terragrunt
MIT License
608 stars 95 forks source link

Missing Environment Variables #259

Open tide-jamiegwatkin opened 1 year ago

tide-jamiegwatkin commented 1 year ago

We're testing terragrunt-atlantis-config with the intention of using it with Atlantis but am having a strange issue where ENV vars are not being found.

When running terragrunt-atlantis-config generate --output atlantis.yaml --autoplan --parallel --root core/eks_main/, terragrunt-atlantis-config fails to find any environment variable that has been defined in terragrunt.hcl.

The error outputted is:

[root@ terraform]$ terragrunt-atlantis-config generate --output atlantis.yaml --autoplan --parallel --root core/eks_main/
ERRO[0000] Error: Error in function call

ERRO[0000]   on /terraform/core/terragrunt.hcl line 3, in locals: 
ERRO[0000]    3:   environment       = get_env("OP_TF_ENV") 
ERRO[0000]                                              
ERRO[0000] Call to function "get_env" failed: EnvVarNotFound: Required environment variable OP_TF_ENV - not found.

ERRO[0000] Encountered error while evaluating locals.   
ERRO[0000] Error: Error in function call

ERRO[0000]   on /terraform/core/terragrunt.hcl line 3, in locals: 
ERRO[0000]    3:   environment       = get_env("OP_TF_ENV") 
ERRO[0000]                                              
ERRO[0000] Call to function "get_env" failed: EnvVarNotFound: Required environment variable OP_TF_ENV - not found.

ERRO[0000] Encountered error while evaluating locals.   
ERRO[0000] Error: Error in function call

ERRO[0000]   on /terraform/core/terragrunt.hcl line 4, in locals: 
ERRO[0000]    4:   application       = get_env("OP_TF_APP") 

When eching the env vars in the shell I'm able to see them all e.g:

[root@ terraform]$ env | grep OP_TF_ENV
OP_TF_ENV=test

The locals defined in /terraform/core/terragrunt.hcl look like this:

locals {
  ...
  environment       = get_env("OP_TF_ENV")
  application       = get_env("OP_TF_APP")
  country           = get_env("OP_TF_COUNTRY")
  root_folder       = get_env("OP_TF_ROOT_DIR")
  production_access = get_env("OP_PRODUCTION_ACCESS", "yes")
...
}

core/eks_main/terragrunt.hcl looks like:

terraform {
  source = ".//."
}

include "root" {
  path = find_in_parent_folders()
}

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

Am I doing something wrong with this configuration?

d4n13lbc commented 1 year ago

Hi, I had the same issue and I moved my env vars from the locals section to the inputs section and it is working well now

carlosz22 commented 1 year ago

Hi. I'm having exactly the same issue. I would prefer not to reorganize all environment variables because it means a huge effort. Why doesn't it fail in inputs and it fails in locals?

terragrunt-atlantis-config version 1.16.0

Sancretor commented 2 weeks ago

Hi there ! I have the very same issue with 1.18.0 and was able to narrow it down a bit. If a terragrunt file has a get_env() call it's working, unless it is used by another terragrunt file. So if the included terragrunt file has a get_env() call, then it seems terragrunt-atlantis-config does not provide the environment variables at all, thus the error we have.

I'll try to spend some more time debugging this and open a PR if I manage to fix it.