attach volume after instance booted

This commit is contained in:
Matthew Hooker 2018-09-07 14:42:22 -07:00
parent b68f214ca4
commit 2febfa2c7d
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 22 additions and 7 deletions

View File

@ -75,7 +75,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
var steps []multistep.Step
if b.config.PersistentVolumeSize > 0 {
steps = []multistep.Step{
// TODO: make volume names UUIDs
&stepCreatePersistentVolume{
volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize),
volumeName: fmt.Sprintf("master-storage_%s", runID),

View File

@ -31,8 +31,13 @@ type Config struct {
// Image
// PersistentVolumeSize lets us control the volume size by using persistent boot storage
PersistentVolumeSize int `mapstructure:"persistent_volume_size"`
//TODO
// builder image
/* TODO:
builder image list
default to OL image
make sure if set then PVS is above
some way to choose which connection to use for master
possible ignore everything for builder and always use SSH keys
*/
ImageName string `mapstructure:"image_name"`
Shape string `mapstructure:"shape"`

View File

@ -3,6 +3,7 @@ package classic
import (
"context"
"fmt"
"log"
"github.com/hashicorp/go-oracle-terraform/compute"
"github.com/hashicorp/packer/helper/multistep"
@ -48,10 +49,6 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
Volume: s.builderVolumeName,
Index: 2,
},
{
Volume: s.masterVolumeName,
Index: 3,
},
},
BootOrder: []int{1},
Attributes: config.attribs,
@ -65,6 +62,20 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
state.Put("error", err)
return multistep.ActionHalt
}
log.Printf("Created instance %s", instanceInfo.Name)
saClient := client.StorageAttachments()
saInput := &compute.CreateStorageAttachmentInput{
Index: 3,
InstanceName: s.name,
StorageVolumeName: s.masterVolumeName,
}
if _, err := saClient.CreateStorageAttachment(saInput); err != nil {
err = fmt.Errorf("Problem attaching master volume: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
state.Put("builder_instance_info", instanceInfo)
state.Put("builder_instance_id", instanceInfo.ID)