* Add a bunch of hard coded values for testing on port 8081; ssh configs are set to localhost and 8081 * Add a base drive for communicating with the session manager plugin * Update step for creating tunnel to actually create SSM session tunnel via driver
51 lines
1000 B
Go
51 lines
1000 B
Go
package common
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
"sync"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
"github.com/hashicorp/packer/template/interpolate"
|
|
)
|
|
|
|
type SSMDriver struct {
|
|
Ui packer.Ui
|
|
Ctx *interpolate.Context
|
|
|
|
l sync.Mutex
|
|
}
|
|
|
|
// sessJson, region, "StartSession", profile, paramJson, endpoint
|
|
func (s *SSMDriver) StartSession(sessionData, region, profile, params, endpoint string) error {
|
|
var stdout bytes.Buffer
|
|
var stderr bytes.Buffer
|
|
|
|
args := []string{
|
|
sessionData,
|
|
region,
|
|
"StartSession",
|
|
profile,
|
|
params,
|
|
endpoint,
|
|
}
|
|
|
|
// Remove log statement
|
|
log.Printf("Attempting to start session with the following args: %v", args)
|
|
cmd := exec.Command("session-manager-plugin", args...)
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
err = fmt.Errorf("Error committing container: %s\nStderr: %s", err, stderr.String())
|
|
s.Ui.Error(err.Error())
|
|
return err
|
|
}
|
|
log.Println(stdout.String())
|
|
log.Println(stderr.String())
|
|
|
|
return nil
|
|
}
|