hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.04k stars 3.32k forks source link

Plugins installed via `packer plugins install` are not loaded without a required_plugins block #11697

Closed nywilken closed 2 years ago

nywilken commented 2 years ago

Plugins installed via packer plugins install are not loaded without a required_plugins block

Upon installing a plugin via packer plugins install it was found that the plugin is usable for HCL2 template builds only if the required plugins block is specified in the HCL build template.Since the plugins command can be used for installing external plugins I would expect the plugin to be found regardless of the build template type.

Reproduction Steps

  1. Run packer plugins install github.com/sylviamoss/comment
  2. Run packer build source.json

Build Template: source.json.pkr.hcl

source "null" "autogenerated_1" {
  communicator = "none"
}

build {
  sources = ["source.null.autogenerated_1"]

  provisioner "comment" {
    bubble_text = true
    comment     = "Begin"
    ui          = true
  }

  provisioner "shell-local" {
    inline = ["echo \"This is a shell script\""]
  }

  provisioner "comment" {
    comment = "In the middle of Provisioning run"
    ui      = true
  }

  provisioner "shell-local" {
    inline = ["echo \"This is another shell script\""]
  }

  provisioner "comment" {
    comment = "this comment is invisible and won't go to the UI"
  }

  provisioner "comment" {
    bubble_text = true
    comment     = "End"
    ui          = true
  }

}

Expected Results

~>  packer build source.json.pkr.hcl
null: output will be in this color.

==> null:   ____                   _
==> null:  | __ )    ___    __ _  (_)  _ __
==> null:  |  _ \   / _ \  / _` | | | | '_ \
==> null:  | |_) | |  __/ | (_| | | | | | | |
==> null:  |____/   \___|  \__, | |_| |_| |_|
==> null:                  |___/
==> null:
==> null: Running local shell script: /var/folders/vz/rv7bk6v15211jxg8q801f7kw0000gq/T/packer-shell1166603649
    null: This is a shell script
==> null: In the middle of Provisioning run
==> null: Running local shell script: /var/folders/vz/rv7bk6v15211jxg8q801f7kw0000gq/T/packer-shell4281157345
    null: This is another shell script
==> null:   _____               _
==> null:  | ____|  _ __     __| |
==> null:  |  _|   | '_ \   / _` |
==> null:  | |___  | | | | | (_| |
==> null:  |_____| |_| |_|  \__,_|
==> null:
Build 'null' finished after 201 milliseconds 504 microseconds.

==> Wait completed after 201 milliseconds 551 microseconds

==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder

Actual Results

Error: Unknown provisioner type "comment"

  on source.json.pkr.hcl line 8:
  (source code not available)

known provisioners: [azure-dtlartifact windows-restart chef-client shell
puppet-masterless converge puppet-server salt-masterless windows-shell sleep
ansible chef-solo powershell inspec ansible-local breakpoint file shell-local]

Error: Unknown provisioner type "comment"

  on source.json.pkr.hcl line 18:
  (source code not available)

known provisioners: [inspec sleep ansible chef-solo powershell ansible-local
breakpoint file shell-local puppet-masterless converge puppet-server
azure-dtlartifact windows-restart chef-client shell salt-masterless
windows-shell]

Error: Unknown provisioner type "comment"

  on source.json.pkr.hcl line 27:
  (source code not available)

known provisioners: [salt-masterless windows-shell sleep ansible chef-solo
powershell inspec ansible-local breakpoint file shell-local azure-dtlartifact
windows-restart chef-client shell puppet-masterless converge puppet-server]

Error: Unknown provisioner type "comment"

  on source.json.pkr.hcl line 31:
  (source code not available)

known provisioners: [ansible-local breakpoint file shell-local puppet-masterless
converge puppet-server azure-dtlartifact windows-restart chef-client shell
salt-masterless windows-shell inspec sleep ansible chef-solo powershell]

Adding a required plugin block for the comment provisioner fixes issue.

packer  {
  required_plugins {
    comment = {
      source = "github.com/sylviamoss/comment"
      version = ">= 0.2.24"
    }
  }
}

source "null" "autogenerated_1" {
  communicator = "none"
}

build {
  sources = ["source.null.autogenerated_1"]

  provisioner "comment" {
    bubble_text = true
    comment     = "Begin"
    ui          = true
  }

  provisioner "shell-local" {
    inline = ["echo \"This is a shell script\""]
  }

  provisioner "comment" {
    comment = "In the middle of Provisioning run"
    ui      = true
  }

  provisioner "shell-local" {
    inline = ["echo \"This is another shell script\""]
  }

  provisioner "comment" {
    comment = "this comment is invisible and won't go to the UI"
  }

  provisioner "comment" {
    bubble_text = true
    comment     = "End"
    ui          = true
  }

}
github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.