From 2febfa2c7d21e9c542a80ebcda080f1a4331a916 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 7 Sep 2018 14:42:22 -0700 Subject: [PATCH] attach volume after instance booted --- builder/oracle/classic/builder.go | 1 - builder/oracle/classic/config.go | 9 +++++++-- .../oracle/classic/step_create_pv_builder.go | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index d1dde8293..79f5f4d50 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -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), diff --git a/builder/oracle/classic/config.go b/builder/oracle/classic/config.go index a7250b4f8..a4d43691b 100644 --- a/builder/oracle/classic/config.go +++ b/builder/oracle/classic/config.go @@ -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"` diff --git a/builder/oracle/classic/step_create_pv_builder.go b/builder/oracle/classic/step_create_pv_builder.go index a0b044a89..6fdbbb202 100644 --- a/builder/oracle/classic/step_create_pv_builder.go +++ b/builder/oracle/classic/step_create_pv_builder.go @@ -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)