diff --git a/README.md b/README.md index 310a093..42f17e0 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,16 @@ PACKER_ACC=1 go test -count 1 -v ./... -timeout=120m This will run the acceptance tests for all plugins in this set. +> [!CAUTION] +> +> Please make sure the acceptance tests are running against the local version by deleting all previously installed +> versions under `$HOME/. config/packer/plugins` directory. Otherwise, the tests will pick up the old released version +> if they were installed before. Deleting `github.com/QubitPi/hashicorp-aws`, for example, would be +> +> ```console +> rm -rf ~/.config/packer/plugins/github.com/QubitPi/hashicorp-aws +> ``` + ## Registering Plugin as Packer Integration Partner and community plugins can be hard to find if a user doesn't know what diff --git a/provisioner/basic-provisioner/basic-provisioner.go b/provisioner/basic-provisioner/basic-provisioner.go new file mode 100644 index 0000000..b0fbc8d --- /dev/null +++ b/provisioner/basic-provisioner/basic-provisioner.go @@ -0,0 +1,24 @@ +// Copyright (c) Jiaqi Liu +// SPDX-License-Identifier: MPL-2.0 + +// This package implements a provisioner for Packer that executes a specified list of shell commands within the remote +// machine +package basicProvisioner + +import ( + "context" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" +) + +func Provision(ctx context.Context, ui packersdk.Ui, communicator packersdk.Communicator, amiConfigCommands []string) error { + if len(amiConfigCommands) > 0 { + for _, command := range amiConfigCommands { + err := (&packersdk.RemoteCmd{Command: command}).RunWithUi(ctx, communicator, ui) + if err != nil { + return err + } + } + } + + return nil +} diff --git a/provisioner/ssl-provisioner/ssl-provisioner.go b/provisioner/ssl-provisioner/ssl-provisioner.go index 3527506..421fe06 100644 --- a/provisioner/ssl-provisioner/ssl-provisioner.go +++ b/provisioner/ssl-provisioner/ssl-provisioner.go @@ -7,6 +7,7 @@ import ( "context" "encoding/base64" "fmt" + basicProvisioner "github.com/QubitPi/packer-plugin-hashicorp-aws/provisioner/basic-provisioner" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer-plugin-sdk/template/interpolate" "github.com/hashicorp/packer-plugin-sdk/tmp" @@ -135,17 +136,7 @@ func Provision(ctx context.Context, interCtx interpolate.Context, ui packersdk.U } } - if len(amiConfigCommands) > 0 { - for _, command := range amiConfigCommands { - err := (&packersdk.RemoteCmd{Command: command}).RunWithUi(ctx, communicator, ui) - if err != nil { - os.Exit(1) // async termination - // return err - } - } - } - - return nil + return basicProvisioner.Provision(ctx, ui, communicator, amiConfigCommands) } // Decodes a base64-encoded string and returns the string representation of it