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 var steps []multistep.Step
if b.config.PersistentVolumeSize > 0 { if b.config.PersistentVolumeSize > 0 {
steps = []multistep.Step{ steps = []multistep.Step{
// TODO: make volume names UUIDs
&stepCreatePersistentVolume{ &stepCreatePersistentVolume{
volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize), volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize),
volumeName: fmt.Sprintf("master-storage_%s", runID), volumeName: fmt.Sprintf("master-storage_%s", runID),

View File

@ -31,8 +31,13 @@ type Config struct {
// Image // Image
// PersistentVolumeSize lets us control the volume size by using persistent boot storage // PersistentVolumeSize lets us control the volume size by using persistent boot storage
PersistentVolumeSize int `mapstructure:"persistent_volume_size"` PersistentVolumeSize int `mapstructure:"persistent_volume_size"`
//TODO /* TODO:
// builder image 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"` ImageName string `mapstructure:"image_name"`
Shape string `mapstructure:"shape"` Shape string `mapstructure:"shape"`

View File

@ -3,6 +3,7 @@ package classic
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"github.com/hashicorp/go-oracle-terraform/compute" "github.com/hashicorp/go-oracle-terraform/compute"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
@ -48,10 +49,6 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
Volume: s.builderVolumeName, Volume: s.builderVolumeName,
Index: 2, Index: 2,
}, },
{
Volume: s.masterVolumeName,
Index: 3,
},
}, },
BootOrder: []int{1}, BootOrder: []int{1},
Attributes: config.attribs, Attributes: config.attribs,
@ -65,6 +62,20 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt 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_info", instanceInfo)
state.Put("builder_instance_id", instanceInfo.ID) state.Put("builder_instance_id", instanceInfo.ID)