Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle updated packer version output from 1.10 #1380

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

batinicaz
Copy link
Contributor

Description

Fixes #1379.

Minimal fix to handle the version output Packer introduced in hashicorp/packer#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
  • 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

@denis256
Copy link
Member

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
Copy link
Member

denis256 commented Jan 1, 2024

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

@batinicaz
Copy link
Contributor Author

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

@denis256
Copy link
Member

denis256 commented Jan 2, 2024

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?

@batinicaz
Copy link
Contributor Author

batinicaz commented Jan 4, 2024

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

@denis256
Copy link
Member

denis256 commented Jan 8, 2024

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.

@batinicaz
Copy link
Contributor Author

batinicaz commented Jan 8, 2024

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 🙂

@denis256
Copy link
Member

denis256 commented Jan 16, 2024

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.

@batinicaz
Copy link
Contributor Author

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?

@walbertus
Copy link

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

@batinicaz batinicaz force-pushed the bug/packer-version-check-1379 branch from ab01246 to d3af93b Compare January 30, 2024 17:42
@batinicaz
Copy link
Contributor Author

Rebased vs master

@LKummer
Copy link

LKummer commented May 21, 2024

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

@batinicaz
Copy link
Contributor Author

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

@denis256 denis256 mentioned this pull request May 23, 2024
4 tasks
@denis256 denis256 merged commit 076e7b7 into gruntwork-io:master Jul 12, 2024
1 of 2 checks passed
LKummer added a commit to SneakyBugs/Kubernetes-Image-Builder that referenced this pull request Sep 1, 2024
Currently only works with Packer 1.9 or older. Packer 1.10 broke
something with Terratest and it needs this PR merged:
gruntwork-io/terratest#1380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Packer init fails on packer 1.10
4 participants