toowoxx / terraform-provider-packer

Terraform Provider for HashiCorp Packer
Mozilla Public License 2.0
32 stars 7 forks source link

How to stream packer build output in realtime #17

Closed glebarez closed 1 month ago

glebarez commented 5 months ago

Can you please suggest a recipe to tail packer output while terraform is working on it ?

simaotwx commented 5 months ago

I can take a look at this, it's not that trivial though. It will require changes to the code.

glebarez commented 5 months ago

running packer directly, I can make it produce logs in a separate file by setting PACKER_LOG and PACKER_LOG_PATH env. variables. (see https://developer.hashicorp.com/packer/docs/v1.9.x/debugging#debugging-packer)

But if I pass it trough environment block like this:

resource "packer_image" "my_image" {
  file = data.packer_files.files1.file
  environment = {
    PACKER_LOG = "1"
    PACKER_LOG_PATH = "/path/to/packer.log"
  }
}

It seems to have no effect, somehow.

simaotwx commented 5 months ago

running packer directly, I can make it produce logs in a separate file by setting PACKER_LOG and PACKER_LOG_PATH env. variables. (see https://developer.hashicorp.com/packer/docs/v1.9.x/debugging#debugging-packer)

But if I pass it trough environment block like this:

resource "packer_image" "my_image" {
  file = data.packer_files.files1.file
  environment = {
    PACKER_LOG = "1"
    PACKER_LOG_PATH = "/path/to/packer.log"
  }
}

It seems to have no effect, somehow.

Not sure why this is the case as the env variables are passed here: https://github.com/toowoxx/terraform-provider-packer/blob/main/packer_interop/env.go#L21-L23

simaotwx commented 3 weeks ago

I fixed this in 0.16.0. Turns out there was an issue with how Packer was starting up. The routines that set up logging to files were not being run prior to 0.16.0.