Skip to content

Commit

Permalink
Abstract away custom command execution (QubitPi#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Jul 2, 2024
1 parent 2d94f19 commit 50df1be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions provisioner/basic-provisioner/basic-provisioner.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 2 additions & 11 deletions provisioner/ssl-provisioner/ssl-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50df1be

Please sign in to comment.