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

[vagrant-cloud post-processor] Add option to overwrite existing version #15

Open
ghost opened this issue Jun 1, 2021 · 0 comments
Open

Comments

@ghost
Copy link

ghost commented Jun 1, 2021

This issue was originally opened by @adriananeci as hashicorp/packer#9492. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Feature Description

When using vagrant-cloud post-processor to upload a freshly generated box into vagrant cloud, we are getting an exception if the version already exists.

==> vagrant: Running post-processor: vagrant-cloud
==> vagrant (vagrant-cloud): Verifying box is accessible: hlesey/k8s-base
    vagrant (vagrant-cloud): Box accessible and matches tag
==> vagrant (vagrant-cloud): Creating version: 1.18.2.2
    vagrant (vagrant-cloud): Version exists, skipping creation
==> vagrant (vagrant-cloud): Creating provider: virtualbox
==> vagrant (vagrant-cloud): Cleaning up provider
    vagrant (vagrant-cloud): Provider was not created, not deleting
Build 'vagrant' errored: 1 error(s) occurred:

* Post-processor failed: Error creating provider: Metadata provider must be unique for version

With debug enabled I've got

2020/06/27 13:00:22 packer-post-processor-vagrant-cloud plugin: Post-Processor Vagrant Cloud API POST: https://vagrantcloud.com/api/v1/box/hlesey/k8s-base/version/1.18.2.1/providers.
2020/06/27 13:00:22 packer-post-processor-vagrant-cloud plugin:
2020/06/27 13:00:22 packer-post-processor-vagrant-cloud plugin:  Body: {"provider":{"name":"virtualbox"}}
2020/06/27 13:00:22 packer-post-processor-vagrant-cloud plugin: Post-Processor Vagrant Cloud API Response:
2020/06/27 13:00:22 packer-post-processor-vagrant-cloud plugin:
2020/06/27 13:00:22 packer-post-processor-vagrant-cloud plugin: &{Status:422 Unprocessable Entity StatusCode:422 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Cache-Control:[no-cache] Connection:[keep-alive] Content-Type:[application/json; charset=utf-8] Date:[Sat, 27 Jun 2020 10:00:21 GMT] Referrer-Policy:[strict-origin-when-cross-origin] Server:[Cowboy] Set-Cookie:[_atlas_session_data=aFRxUkhQcnYzV2tvem5YbnJtQ0NjZ0VxanEwcHBIODNlYURYcDBkQ0pWMzZrcjlOeUdVNE0yVlB2N2l2S0VBUTlJOGQ1YThCZWhFUmpsblpSUlc0TlE9PS0tcEgwSFlFb3FYQVhXQ2Y2cVpjN0ZvUT09--0ad671fa052e76fbb10ceb6866cab4e379ad7143; path=/; expires=Mon, 27 Jul 2020 10:00:22 GMT; secure; HttpOnly] Strict-Transport-Security:[max-age=31536000; includeSubDomains; preload] Via:[1.1 vegur] X-Content-Type-Options:[nosniff] X-Download-Options:[noopen] X-Frame-Options:[SAMEORIGIN] X-Permitted-Cross-Domain-Policies:[none] X-Request-Id:[1f0a23a5-7c4c-4a2a-bdec-1902e591f57c] X-Runtime:[0.132013] X-Vagrantcloud-Rate-Limit:[98/100] X-Xss-Protection:[1; mode=block]] Body:0xc00038e4c0 ContentLength:-1 TransferEncoding:[chunked] Close:false Uncompressed:false Trailer:map[] Request:0xc0000c6600 TLS:0xc0004e3550}

One way to mitigate it is to manually remove the provider for this version from vagrantcloud UI and retry the packer build.
Another way to avoid such exceptions is to increase the version when uploading the new box. In this case we have to announce everyone that consumes this box that a new version is available and they have to adjust their config.

It would be nice to have a new parameter for vagrant-cloud post-processor, something like replace_if_exists defaulting to false.

Sample config

{
  "variables": {
    "cloud_token": "{{ env `VAGRANT_CLOUD_TOKEN` }}",
    "output_path": "./output"
  },
  "builders": [
    {
      "type": "vagrant",
      "source_path": "ubuntu/bionic64",
      "communicator": "ssh",
      "add_force": true,
      "provider": "virtualbox",
      "output_dir": "{{user `output_path`}}"
    }
  ],
  "post-processors": [
    [
      {
        "type": "vagrant-cloud",
        "box_tag": "hlesey/k8s-base",
        "version": "{{user `version`}}",
        "access_token": "{{user `cloud_token`}}",
        "replace_if_exists": true
      }
    ]
  ]
}

vagrant cli already support replacing existing version, vagrant cloud provider upload ORGANIZATION/BOX-NAME PROVIDER-NAME VERSION BOX-FILE

Use Case(s)

As a packer user, I want to be able to replace an existing box version when using vagrant-cloud post-processor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants