Coder.comC
Coder.com15mo ago
51 replies
Andrej

Bug with local exec in a module

Local exec works fine in terraform script in root, but once it is in any module, it is throwing weird errors.
To reproduce this issue create following template:
|main.tf
|
/module/main.tf
# main.tf
module "test_exec" {
  source = "./module"
}

resource "null_resource" "main_test_exec" {
   triggers = {
    always_run = "${timestamp()}"
  }
  provisioner "local-exec" {
    command = <<EOT
      whoami
      ls ~/.ssh/
    EOT
  }
}


# module/main.tf
resource "null_resource" "module_test_exec" {
   triggers = {
    always_run = "${timestamp()}"
  }
  provisioner "local-exec" {
    command = <<EOT
      whoami
      ls ~/.ssh/
    EOT
  }
}

With this template, first local exec finishes successfully, but the second one fails with:
image.png
Was this page helpful?