mirror of https://github.com/hashicorp/packer
parent
de973fba0e
commit
1281f28f6d
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Deregister the test image with
|
||||
aws ec2 deregister-image --image-id $(aws ec2 describe-images --output text --filters "Name=name,Values=packer-test-packer-test-dereg" --query 'Images[*].{ID:ImageId}')
|
||||
*/
|
||||
package bsusurrogate
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
builderT "github.com/hashicorp/packer/helper/builder/testing"
|
||||
)
|
||||
|
||||
func TestBuilderAcc_basic(t *testing.T) {
|
||||
builderT.Test(t, builderT.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Builder: &Builder{},
|
||||
Template: testBuilderAccBasic,
|
||||
})
|
||||
}
|
||||
|
||||
func testAccPreCheck(t *testing.T) {
|
||||
}
|
||||
|
||||
const testBuilderAccBasic = `
|
||||
{
|
||||
"builders": [{
|
||||
"type": "test",
|
||||
"region": "eu-west-2",
|
||||
"vm_type": "m3.medium",
|
||||
"source_omi": "ami-76b2a71e",
|
||||
"ssh_username": "ubuntu",
|
||||
"omi_name": "packer-test {{timestamp}}",
|
||||
"omi_virtualization_type": "hvm",
|
||||
"launch_block_device_mappings" : [
|
||||
{
|
||||
"volume_type" : "gp2",
|
||||
"device_name" : "/dev/sda1",
|
||||
"delete_on_vm_deletion" : false,
|
||||
"volume_size" : 10
|
||||
}
|
||||
],
|
||||
"omi_root_device":{
|
||||
"source_device_name": "/dev/sda1",
|
||||
"device_name": "/dev/sda2",
|
||||
"delete_on_vm_deletion": true,
|
||||
"volume_size": 16,
|
||||
"volume_type": "gp2"
|
||||
}
|
||||
|
||||
}]
|
||||
}
|
||||
`
|
||||
@ -0,0 +1,51 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/outscale/osc-go/oapi"
|
||||
)
|
||||
|
||||
// StepPreValidate provides an opportunity to pre-validate any configuration for
|
||||
// the build before actually doing any time consuming work
|
||||
//
|
||||
type StepPreValidate struct {
|
||||
DestOmiName string
|
||||
ForceDeregister bool
|
||||
}
|
||||
|
||||
func (s *StepPreValidate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
if s.ForceDeregister {
|
||||
ui.Say("Force Deregister flag found, skipping prevalidating OMI Name")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
oapiconn := state.Get("oapi").(*oapi.Client)
|
||||
|
||||
ui.Say(fmt.Sprintf("Prevalidating OMI Name: %s", s.DestOmiName))
|
||||
resp, err := oapiconn.POST_ReadImages(oapi.ReadImagesRequest{
|
||||
Filters: oapi.FiltersImage{ImageNames: []string{s.DestOmiName}},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error querying OMI: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
if len(resp.OK.Images) > 0 {
|
||||
err := fmt.Errorf("Error: name conflicts with an existing OMI: %s", resp.OK.Images[0].ImageId)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *StepPreValidate) Cleanup(multistep.StateBag) {}
|
||||
Loading…
Reference in new issue