diff --git a/builder/osc/chroot/step_mount_device.go b/builder/osc/chroot/step_mount_device.go index 32f2e08..2b23999 100644 --- a/builder/osc/chroot/step_mount_device.go +++ b/builder/osc/chroot/step_mount_device.go @@ -71,38 +71,7 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi return multistep.ActionHalt } - //Check the symbolic link for the device to get the real device name - cmd := ShellCommand(fmt.Sprintf("lsblk -no pkname $(readlink -f %s)", device)) - - realDeviceName, err := cmd.Output() - if err != nil { - err := fmt.Errorf( - "Error retrieving the symlink of the device %s.\n", device) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt - } - - log.Printf("[DEBUG] RealDeviceName: %s", realDeviceName) - - realDeviceNameSplitted := strings.Split(string(realDeviceName), "\n") - log.Printf("[DEBUG] RealDeviceName Splitted %+v", realDeviceNameSplitted) - log.Printf("[DEBUG] RealDeviceName Splitted Length %d", len(realDeviceNameSplitted)) - log.Printf("[DEBUG] RealDeviceName Splitted [0] %s", realDeviceNameSplitted[0]) - log.Printf("[DEBUG] RealDeviceName Splitted [1] %s", realDeviceNameSplitted[1]) - - realDeviceNameStr := realDeviceNameSplitted[0] - if realDeviceNameStr == "" { - realDeviceNameStr = realDeviceNameSplitted[1] - } - - deviceMount := fmt.Sprintf("/dev/%s", strings.Replace(realDeviceNameStr, "\n", "", -1)) - - log.Printf("[DEBUG] s.MountPartition = %s", s.MountPartition) - log.Printf("[DEBUG ] DeviceMount: %s", deviceMount) - - state.Put("deviceMount", deviceMount) - + state.Put("deviceMount", device) ui.Say("Mounting the root device...") stderr := new(bytes.Buffer) @@ -113,7 +82,7 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi opts = "-o " + strings.Join(s.MountOptions, " -o ") } mountCommand, err := wrappedCommand( - fmt.Sprintf("mount %s %s %s", opts, deviceMount, mountPath)) + fmt.Sprintf("mount %s %s %s", opts, device, mountPath)) if err != nil { err := fmt.Errorf("Error creating mount command: %s", err) state.Put("error", err) @@ -121,7 +90,7 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi return multistep.ActionHalt } log.Printf("[DEBUG] (step mount) mount command is %s", mountCommand) - cmd = ShellCommand(mountCommand) + cmd := ShellCommand(mountCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil { err := fmt.Errorf( diff --git a/builder/osc/common/block_device.go b/builder/osc/common/block_device.go index e006b01..899acfa 100644 --- a/builder/osc/common/block_device.go +++ b/builder/osc/common/block_device.go @@ -5,7 +5,6 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/packer-plugin-sdk/template/interpolate" oscgo "github.com/outscale/osc-sdk-go/v2" ) @@ -69,7 +68,7 @@ func buildOscBlockDevicesImage(b []BlockDevice) []oscgo.BlockDeviceMappingImage bsu.SnapshotId = &blockDevice.SnapshotId } - mapping.Bsu = &bsu + mapping.SetBsu(bsu) } blockDevices = append(blockDevices, mapping) @@ -88,7 +87,7 @@ func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingV } if blockDevice.NoDevice { - mapping.NoDevice = aws.String("") + mapping.NoDevice = oscgo.PtrString("") //blockDevices = mapping[0] } else if blockDevice.VirtualName != "" { if strings.HasPrefix(blockDevice.VirtualName, "ephemeral") { @@ -117,7 +116,7 @@ func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingV bsu.SnapshotId = &blockDevice.SnapshotId } - mapping.Bsu = &bsu + mapping.SetBsu(bsu) } blockDevices = append(blockDevices, mapping) diff --git a/example/osc-chroot.pkr.hcl b/example/osc-chroot.pkr.hcl index fc20686..a7acd14 100644 --- a/example/osc-chroot.pkr.hcl +++ b/example/osc-chroot.pkr.hcl @@ -7,6 +7,7 @@ variable "osc_secret_key" { type = string default = "${env("OSC_SECRET_KEY")}" } + packer { required_plugins { outscale = { @@ -23,12 +24,15 @@ source "outscale-chroot" "windows" { from_scratch = true pre_mount_commands = [ "parted {{.Device}} mklabel msdos mkpart primary 1M 100% set 1 boot on print", - "mkfs.ext4 {{.Device}}1" + "fdisk {{.Device}}", + "sleep 1", + "mkfs -t xfs -f {{.Device}}" ] root_volume_size = 15 - root_device_name = "xvdf" + root_device_name = "xvda" omi_block_device_mappings { - device_name = "xvdf" + delete_on_vm_deletion = false + device_name = "xvda" volume_type = "gp2" } }