terraformterragrunt

terragrunt - Unable to evaluate directory symlink


I am trying to use terrgrunt with terraform. this is the dumb down version of what I am trying to achieve. However, basically. I want to store all the environment specific variables in terragrunt.hcl file and my main logic (Which calls to another module) in a separate main.tf.

This is how it looks like.

.
├── live
│   ├── env
│   │   ├── dev
│   │   │   └── terragrunt.hcl
│   │   └── qa
│   ├── main.tf
│   └── variables.tf
├── module
│   ├── main.tf
│   └── varriables.tf

and this is the content.

module/main.tf

resource "null_resource" "default" {
  provisioner "local-exec" {
    command = "echo ${var.name}"
  }
}

module/variables.tf

variable "name" {
  type    = string
  default = "xxx"
}

live/main.tf


module "test_terragrunt" {
  source = "../module/"
  name   = var.name
}

live/variables.tf

variable "name" {
  type    = string
}

live/env/dev/terragrunt.hcl

include {
  path = find_in_parent_folders()
}

terraform {
  source = "../../"
}
inputs = {
  name = "gaurang"
}

and when I run terragrunt plan I am getting following error

╷
│ Error: Unreadable module directory
│
│ Unable to evaluate directory symlink: lstat ../../module: no such file or
│ directory
╷
│ Error: Unreadable module directory
│
│ The directory  could not be read for module "test_terragrunt" at main.tf:2.
╵

Solution

  • Use a double-slash in the source path.

    live/env/dev/terragrunt.hcl

    include {
      path = find_in_parent_folders()
    }
    
    terraform {
      source = "../../..//live"
    }
    inputs = {
      name = "gaurang"
    }
    

    Terragrunt downloads all the code in the folder before the double-slash into the temporary folder so that relative paths between modules work correctly. Terraform may display a “Terraform initialized in an empty directory” warning, but you can safely ignore it.