terratest icon indicating copy to clipboard operation
terratest copied to clipboard

fix: handle updated packer version output from 1.10

Open batinicaz opened this issue 8 months ago • 13 comments

Description

Fixes #1379.

Minimal fix to handle the version output Packer introduced in https://github.com/hashicorp/packer/pull/12569.

Added a couple of simple unit tests to validate support for both the old version output and the new version output.

Also ran the hello-world test for v1.10:

=== RUN   TestPackerHelloWorldExample
TestPackerHelloWorldExample 2023-12-16T09:29:06Z logger.go:66: Running Packer to generate a custom artifact for template ../examples/packer-hello-world-example/build.pkr.hcl
TestPackerHelloWorldExample 2023-12-16T09:29:06Z logger.go:66: Creating a temporary directory for Packer plugins
TestPackerHelloWorldExample 2023-12-16T09:29:06Z logger.go:66: Running command packer with args [-version]
TestPackerHelloWorldExample 2023-12-16T09:29:06Z logger.go:66: Packer v1.10.0
TestPackerHelloWorldExample 2023-12-16T09:29:07Z retry.go:91: Running Packer init
TestPackerHelloWorldExample 2023-12-16T09:29:07Z logger.go:66: Running command packer with args [init ../examples/packer-hello-world-example/build.pkr.hcl]
TestPackerHelloWorldExample 2023-12-16T09:29:10Z logger.go:66: [1;36mInstalled plugin github.com/hashicorp/docker v1.0.8 in "/var/folders/0n/w2gfg1v92bj732s73hd5c6m00000gn/T/terratest-packer-3799156733/github.com/hashicorp/docker/packer-plugin-docker_v1.0.8_x5.0_darwin_arm64"[0m
TestPackerHelloWorldExample 2023-12-16T09:29:10Z retry.go:91: packer [build -machine-readable ../examples/packer-hello-world-example/build.pkr.hcl]
TestPackerHelloWorldExample 2023-12-16T09:29:10Z logger.go:66: Running command packer with args [build -machine-readable ../examples/packer-hello-world-example/build.pkr.hcl]
TestPackerHelloWorldExample 2023-12-16T09:29:10Z logger.go:66: 1702718950,,ui,say,==> docker.ubuntu-docker: Creating a temporary directory for sharing data...
TestPackerHelloWorldExample 2023-12-16T09:29:10Z logger.go:66: 1702718950,,ui,say,==> docker.ubuntu-docker: Pulling Docker image: gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,message,    docker.ubuntu-docker: 16.04: Pulling from gruntwork/ubuntu-test
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,message,    docker.ubuntu-docker: Digest: sha256:aed71132b5cf1facc84ed57c3206cc481156ec0ba6825750813d03e64e8819b6
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,message,    docker.ubuntu-docker: Status: Image is up to date for gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,message,    docker.ubuntu-docker: docker.io/gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,say,==> docker.ubuntu-docker: Starting docker container...
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,message,    docker.ubuntu-docker: Run command: docker run -v /Users/zak/.config/packer/tmp3184480124:/packer-files -d -i -t --entrypoint=/bin/sh -- gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,message,    docker.ubuntu-docker: Container ID: a1e2373179d2beb5a137ef4c6a2d4eb148f16dc961665d587c1bfa3edd9b30eb
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,say,==> docker.ubuntu-docker: Using docker communicator to connect: 172.17.0.2
TestPackerHelloWorldExample 2023-12-16T09:29:12Z logger.go:66: 1702718952,,ui,say,==> docker.ubuntu-docker: Provisioning with shell script: /var/folders/0n/w2gfg1v92bj732s73hd5c6m00000gn/T/packer-shell1001670580
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,==> docker.ubuntu-docker: Committing the container
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,message,    docker.ubuntu-docker: Image ID: sha256:0fe8f01ca905864b0dcdbe50c3783f668b474a0f52b009c048a8bb1416b634f6
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,==> docker.ubuntu-docker: Killing the container: a1e2373179d2beb5a137ef4c6a2d4eb148f16dc961665d587c1bfa3edd9b30eb
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,==> docker.ubuntu-docker: Running post-processor:  (type docker-tag)
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,==> docker.ubuntu-docker (docker-tag): Deprecation warning: "tag" option has been replaced with "tags". In future versions of Packer%!(PACKER_COMMA) this configuration may not work. Please call `packer fix` on your template to update.
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,message,    docker.ubuntu-docker (docker-tag): Tagging image: sha256:0fe8f01ca905864b0dcdbe50c3783f668b474a0f52b009c048a8bb1416b634f6
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,message,    docker.ubuntu-docker (docker-tag): Repository: gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,Build 'docker.ubuntu-docker' finished after 2 seconds 821 milliseconds.
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,\n==> Wait completed after 2 seconds 821 milliseconds
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,\n==> Builds finished. The artifacts of successful builds are:
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact-count,2
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,0,builder-id,packer.post-processor.docker-import
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,0,id,sha256:0fe8f01ca905864b0dcdbe50c3783f668b474a0f52b009c048a8bb1416b634f6
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,0,string,Imported Docker image: sha256:0fe8f01ca905864b0dcdbe50c3783f668b474a0f52b009c048a8bb1416b634f6
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,0,files-count,0
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,0,end
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,--> docker.ubuntu-docker: Imported Docker image: sha256:0fe8f01ca905864b0dcdbe50c3783f668b474a0f52b009c048a8bb1416b634f6
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,1,builder-id,packer.post-processor.docker-tag
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,1,id,gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,1,string,Imported Docker image: gruntwork/packer-hello-world-example:latest with tags gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,1,files-count,0
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,docker.ubuntu-docker,artifact,1,end
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: 1702718953,,ui,say,--> docker.ubuntu-docker: Imported Docker image: gruntwork/packer-hello-world-example:latest with tags gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: Running 'docker run' on image 'gruntwork/packer-hello-world-example'
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: Running command docker with args [run gruntwork/packer-hello-world-example cat /test.txt]
TestPackerHelloWorldExample 2023-12-16T09:29:13Z logger.go:66: Hello, World!
--- PASS: TestPackerHelloWorldExample (7.16s)
PASS
ok  	command-line-arguments	7.241s

And for 1.9.4:

=== RUN   TestPackerHelloWorldExample
TestPackerHelloWorldExample 2023-12-16T09:32:04Z logger.go:66: Running Packer to generate a custom artifact for template ../examples/packer-hello-world-example/build.pkr.hcl
TestPackerHelloWorldExample 2023-12-16T09:32:04Z logger.go:66: Creating a temporary directory for Packer plugins
TestPackerHelloWorldExample 2023-12-16T09:32:04Z logger.go:66: Running command packer with args [-version]
TestPackerHelloWorldExample 2023-12-16T09:32:05Z logger.go:66: 1.9.4
TestPackerHelloWorldExample 2023-12-16T09:32:05Z retry.go:91: Running Packer init
TestPackerHelloWorldExample 2023-12-16T09:32:05Z logger.go:66: Running command packer with args [init ../examples/packer-hello-world-example/build.pkr.hcl]
TestPackerHelloWorldExample 2023-12-16T09:32:06Z retry.go:91: packer [build -machine-readable ../examples/packer-hello-world-example/build.pkr.hcl]
TestPackerHelloWorldExample 2023-12-16T09:32:06Z logger.go:66: Running command packer with args [build -machine-readable ../examples/packer-hello-world-example/build.pkr.hcl]
TestPackerHelloWorldExample 2023-12-16T09:32:06Z logger.go:66: 1702719126,,ui,say,==> docker.ubuntu-docker: Creating a temporary directory for sharing data...
TestPackerHelloWorldExample 2023-12-16T09:32:06Z logger.go:66: 1702719126,,ui,say,==> docker.ubuntu-docker: Pulling Docker image: gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:32:07Z logger.go:66: 1702719127,,ui,message,    docker.ubuntu-docker: 16.04: Pulling from gruntwork/ubuntu-test
TestPackerHelloWorldExample 2023-12-16T09:32:07Z logger.go:66: 1702719127,,ui,message,    docker.ubuntu-docker: Digest: sha256:aed71132b5cf1facc84ed57c3206cc481156ec0ba6825750813d03e64e8819b6
TestPackerHelloWorldExample 2023-12-16T09:32:07Z logger.go:66: 1702719127,,ui,message,    docker.ubuntu-docker: Status: Image is up to date for gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:32:07Z logger.go:66: 1702719127,,ui,message,    docker.ubuntu-docker: docker.io/gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:32:07Z logger.go:66: 1702719127,,ui,say,==> docker.ubuntu-docker: Starting docker container...
TestPackerHelloWorldExample 2023-12-16T09:32:07Z logger.go:66: 1702719127,,ui,message,    docker.ubuntu-docker: Run command: docker run -v /Users/zak/.config/packer/tmp1060987461:/packer-files -d -i -t --entrypoint=/bin/sh -- gruntwork/ubuntu-test:16.04
TestPackerHelloWorldExample 2023-12-16T09:32:08Z logger.go:66: 1702719128,,ui,message,    docker.ubuntu-docker: Container ID: b5bc559729f30bbc6d9e2d058846eed857991b598270aa719e8ee21d82aca929
TestPackerHelloWorldExample 2023-12-16T09:32:08Z logger.go:66: 1702719128,,ui,say,==> docker.ubuntu-docker: Using docker communicator to connect: 172.17.0.2
TestPackerHelloWorldExample 2023-12-16T09:32:08Z logger.go:66: 1702719128,,ui,say,==> docker.ubuntu-docker: Provisioning with shell script: /var/folders/0n/w2gfg1v92bj732s73hd5c6m00000gn/T/packer-shell636294514
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,==> docker.ubuntu-docker: Committing the container
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,message,    docker.ubuntu-docker: Image ID: sha256:738ae00b08b339037181c1242556080f47526059269e68b5277276c2b1f7ac5b
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,==> docker.ubuntu-docker: Killing the container: b5bc559729f30bbc6d9e2d058846eed857991b598270aa719e8ee21d82aca929
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,==> docker.ubuntu-docker: Running post-processor:  (type docker-tag)
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,==> docker.ubuntu-docker (docker-tag): Deprecation warning: "tag" option has been replaced with "tags". In future versions of Packer%!(PACKER_COMMA) this configuration may not work. Please call `packer fix` on your template to update.
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,message,    docker.ubuntu-docker (docker-tag): Tagging image: sha256:738ae00b08b339037181c1242556080f47526059269e68b5277276c2b1f7ac5b
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,message,    docker.ubuntu-docker (docker-tag): Repository: gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,Build 'docker.ubuntu-docker' finished after 2 seconds 823 milliseconds.
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,\n==> Wait completed after 2 seconds 823 milliseconds
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,\n==> Builds finished. The artifacts of successful builds are:
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact-count,2
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,0,builder-id,packer.post-processor.docker-import
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,0,id,sha256:738ae00b08b339037181c1242556080f47526059269e68b5277276c2b1f7ac5b
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,0,string,Imported Docker image: sha256:738ae00b08b339037181c1242556080f47526059269e68b5277276c2b1f7ac5b
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,0,files-count,0
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,0,end
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,--> docker.ubuntu-docker: Imported Docker image: sha256:738ae00b08b339037181c1242556080f47526059269e68b5277276c2b1f7ac5b
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,1,builder-id,packer.post-processor.docker-tag
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,1,id,gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,1,string,Imported Docker image: gruntwork/packer-hello-world-example:latest with tags gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,1,files-count,0
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,docker.ubuntu-docker,artifact,1,end
TestPackerHelloWorldExample 2023-12-16T09:32:09Z logger.go:66: 1702719129,,ui,say,--> docker.ubuntu-docker: Imported Docker image: gruntwork/packer-hello-world-example:latest with tags gruntwork/packer-hello-world-example:latest
TestPackerHelloWorldExample 2023-12-16T09:32:10Z logger.go:66: Running 'docker run' on image 'gruntwork/packer-hello-world-example'
TestPackerHelloWorldExample 2023-12-16T09:32:10Z logger.go:66: Running command docker with args [run gruntwork/packer-hello-world-example cat /test.txt]
TestPackerHelloWorldExample 2023-12-16T09:32:10Z logger.go:66: Hello, World!
--- PASS: TestPackerHelloWorldExample (6.04s)
PASS
ok  	command-line-arguments	6.123s

TODOs

Read the Gruntwork contribution guidelines.

  • [ ] Update the docs. N/A
  • [X] Run the relevant tests successfully, including pre-commit checks.
  • [ ] Include release notes. If this PR is backward incompatible, include a migration guide. N/A

Release Notes (draft)

fix: handle updated version output from Packer 1.10

batinicaz avatar Dec 16 '23 09:12 batinicaz

I think will be helpful to update packer version in integration tests https://github.com/gruntwork-io/terratest/blob/master/.circleci/config.yml#L7 To see how it will be handled in tests

denis256 avatar Dec 26 '23 18:12 denis256

Hm, noticed failing tests:

TestPackerDockerExampleLocal 2024-01-01T17:20:31Z logger.go:66: 1704129631,,ui,error,Error: Unknown source type docker\n\n  on ../examples/packer-docker-example/build.pkr.hcl line 54:\n  (source code not available)\n\nThe source docker is unknown by Packer%!(PACKER_COMMA) and is likely part of a plugin that is\nnot installed.\nYou may find the needed plugin along with installation instructions documented\non the Packer integrations page.\n\nhttps://developer.hashicorp.com/packer/integrations?filter=docker\n\nError: Unknown post-processor type "docker-tag"\n\n  on ../examples/packer-docker-example/build.pkr.hcl line 71:\n  (source code not available)\n\nThe post-processor docker-tag is unknown by Packer%!(PACKER_COMMA) and is likely part of a\nplugin that is not installed.\nYou may find the needed plugin along with installation instructions documented\non the Packer integrations page.\n\nhttps://developer.hashicorp.com/packer/integrations?filter=docker\n\n

denis256 avatar Jan 01 '24 17:01 denis256

I'm not able to see the build in Circle CI, is there a way to get access? Curious if the packer init ran or not.

Also, is there information on running the integration tests locally? Guessing it must be doing something different to the go test I ran previously

batinicaz avatar Jan 01 '24 17:01 batinicaz

go test -v -run TestPackerDockerExampleLocal


=== RUN   TestPackerDockerExampleLocal
=== PAUSE TestPackerDockerExampleLocal
=== CONT  TestPackerDockerExampleLocal
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Running Packer to generate a custom artifact for template ../examples/packer-docker-example/build.pkr.hcl
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Creating a temporary directory for Packer plugins
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Running command packer with args [-version]
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Packer v1.10.0
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z retry.go:91: Running Packer init
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Running command packer with args [init ../examples/packer-docker-example/build.pkr.hcl]
TestPackerDockerExampleLocal 2024-01-02T18:52:24Z logger.go:66: Installed plugin github.com/hashicorp/amazon v1.2.9 in "/tmp/terratest-packer-3965364191/github.com/hashicorp/amazon/packer-plugin-amazon_v1.2.9_x5.0_linux_amd64"
TestPackerDockerExampleLocal 2024-01-02T18:52:24Z retry.go:91: packer [build -machine-readable -only=docker.ubuntu-docker ../examples/packer-docker-example/build.pkr.hcl]
TestPackerDockerExampleLocal 2024-01-02T18:52:24Z logger.go:66: Running command packer with args [build -machine-readable -only=docker.ubuntu-docker ../examples/packer-docker-example/build.pkr.hcl]
TestPackerDockerExampleLocal 2024-01-02T18:52:26Z logger.go:66: 1704221546,,ui,error,Error: Unknown source type docker\n\n  on ../examples/packer-docker-example/build.pkr.hcl line 54:\n  (source code not available)\n\nThe source docker is unknown by Packer%!(PACKER_COMMA) and is likely part of a plugin that is\nnot installed.\nYou may find the needed plugin along with installation instructions documented\non the Packer integrations page.\n\nhttps://developer.hashicorp.com/packer/integrations?filter=docker\n\nError: Unknown post-processor type "docker-tag"\n\n  on ../examples/packer-docker-example/build.pkr.hcl line 71:\n  (source code not available)\n\nThe post-processor docker-tag is unknown by Packer%!(PACKER_COMMA) and is likely part of a\nplugin that is not installed.\nYou may find the needed plugin along with installation instructions documented\non the Packer integrations page.\n\nhttps://developer.hashicorp.com/packer/integrations?filter=docker\n\n
TestPackerDockerExampleLocal 2024-01-02T18:52:26Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; }
    packer.go:92: FatalError{Underlying: error while running command: exit status 1; }
--- FAIL: TestPackerDockerExampleLocal (4.47s)
FAIL
exit status 1
FAIL	github.com/gruntwork-io/terratest/test	5.265s

Local run of TestPackerDockerExampleLocal is passing?

denis256 avatar Jan 02 '24 18:01 denis256

go test -v -run TestPackerDockerExampleLocal


=== RUN   TestPackerDockerExampleLocal
=== PAUSE TestPackerDockerExampleLocal
=== CONT  TestPackerDockerExampleLocal
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Running Packer to generate a custom artifact for template ../examples/packer-docker-example/build.pkr.hcl
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Creating a temporary directory for Packer plugins
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Running command packer with args [-version]
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Packer v1.10.0
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z retry.go:91: Running Packer init
TestPackerDockerExampleLocal 2024-01-02T18:52:22Z logger.go:66: Running command packer with args [init ../examples/packer-docker-example/build.pkr.hcl]
TestPackerDockerExampleLocal 2024-01-02T18:52:24Z logger.go:66: Installed plugin github.com/hashicorp/amazon v1.2.9 in "/tmp/terratest-packer-3965364191/github.com/hashicorp/amazon/packer-plugin-amazon_v1.2.9_x5.0_linux_amd64"
TestPackerDockerExampleLocal 2024-01-02T18:52:24Z retry.go:91: packer [build -machine-readable -only=docker.ubuntu-docker ../examples/packer-docker-example/build.pkr.hcl]
TestPackerDockerExampleLocal 2024-01-02T18:52:24Z logger.go:66: Running command packer with args [build -machine-readable -only=docker.ubuntu-docker ../examples/packer-docker-example/build.pkr.hcl]
TestPackerDockerExampleLocal 2024-01-02T18:52:26Z logger.go:66: 1704221546,,ui,error,Error: Unknown source type docker\n\n  on ../examples/packer-docker-example/build.pkr.hcl line 54:\n  (source code not available)\n\nThe source docker is unknown by Packer%!(PACKER_COMMA) and is likely part of a plugin that is\nnot installed.\nYou may find the needed plugin along with installation instructions documented\non the Packer integrations page.\n\nhttps://developer.hashicorp.com/packer/integrations?filter=docker\n\nError: Unknown post-processor type "docker-tag"\n\n  on ../examples/packer-docker-example/build.pkr.hcl line 71:\n  (source code not available)\n\nThe post-processor docker-tag is unknown by Packer%!(PACKER_COMMA) and is likely part of a\nplugin that is not installed.\nYou may find the needed plugin along with installation instructions documented\non the Packer integrations page.\n\nhttps://developer.hashicorp.com/packer/integrations?filter=docker\n\n
TestPackerDockerExampleLocal 2024-01-02T18:52:26Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; }
    packer.go:92: FatalError{Underlying: error while running command: exit status 1; }
--- FAIL: TestPackerDockerExampleLocal (4.47s)
FAIL
exit status 1
FAIL	github.com/gruntwork-io/terratest/test	5.265s

Local run of TestPackerDockerExampleLocal is passing?

Apologies I was talking about the TestPackerHelloWorldExample, I missed it was TestPackerDockerExampleLocal. It's because the plugin requirement is missing from the hcl and 1.10 removes the plugins from core packer so its no longer available by default. I've updated the hcl config to fix that

batinicaz avatar Jan 04 '24 19:01 batinicaz

Hm, noticed that the test still fail with:

$ go test -v -run TestPackerBasicExample
=== NAME  TestPackerBasicExample
    packer_basic_example_test.go:228: OperationNotPermitted: You can’t publicly share this image because block public access for AMIs is enabled for this account. To publicly share the image, you must call the DisableImageBlockPublicAccess API.

denis256 avatar Jan 08 '24 16:01 denis256

Hm, noticed that the test still fail with:

$ go test -v -run TestPackerBasicExample
=== NAME  TestPackerBasicExample
    packer_basic_example_test.go:228: OperationNotPermitted: You can’t publicly share this image because block public access for AMIs is enabled for this account. To publicly share the image, you must call the DisableImageBlockPublicAccess API.

This feels unrelated to the PR and more to do with the AWS account where the test is being run.

Does this test run frequently?

Even on master it is set to always make the AMI public: https://github.com/gruntwork-io/terratest/blob/master/test/packer_basic_example_test.go#L79 / https://github.com/gruntwork-io/terratest/blob/master/test/packer_basic_example_test.go#L215-L230

So if it is running regularly against an account that has the block public access feature enabled it should be failing constantly.

Happy to adjust the test if needed but looking for some guidance on the intent here 🙂

batinicaz avatar Jan 08 '24 19:01 batinicaz

This test is executed on each PR, release, and on the master branch, intention is to validate that example is working correctly, since on master it is not failing - I suspect that it is related to this PR. I think this should be fixed in this PR to continue tracking that examples are working correctly.

denis256 avatar Jan 16 '24 16:01 denis256

This test is executed on each PR, release, and on the master branch, intention is to validate that example is working correctly, since on master it is not failing - I suspect that it is related to this PR. T think should be fixed in this PR to continue tracking that examples are working correctly.

When you say the tests are running on master without failing, does that mean this test is actually being executed or is the test being skipped if the most recent commit did not modify the template?

My confusion is that the error is originating from an AWS account setting so it has nothing to do with the code being run and everything to do with the configuration of the account.

I can modify the tests as part of this e.g. do not create a public AMI or call the API to disable the account level setting before the run but both of these feel like fairly substantial changes for a PR that is essentially doing some string handling so want to be clear on your desired intent. What is it that you would like me to do here?

batinicaz avatar Jan 16 '24 16:01 batinicaz

@batinicaz can you rebase the master and see whether it passes the test? It's blocking user from using Packer 1.10.0

walbertus avatar Jan 30 '24 15:01 walbertus

Rebased vs master

batinicaz avatar Jan 30 '24 17:01 batinicaz

Any chance to get this merged? The issue is preventing me from upgrading Packer.

LKummer avatar May 21 '24 10:05 LKummer

Happy to make changes here to get it working, but this was blocked from merging due to a failing test.

The test was failing due to an AWS account setting. Given that's a Gruntwork owned account, modifying account wide settings from the code does not seem appropriate.

To work around that, I could update the code to prevent setting the AMI to be public, but that felt like a sizeable change for a fix that is just string handling.

So before doing that I wanted to get confirmation of the desired change, but @denis256 has yet to confirm their preference

batinicaz avatar May 21 '24 13:05 batinicaz