From d426cce1115ca6b903d654adfff4d7c0fc2fa0cb Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Fri, 23 Aug 2024 08:59:26 +0000 Subject: [PATCH 1/3] Update go module --- go.mod | 10 +++++----- go.sum | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index c8bdee1..070854b 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,13 @@ go 1.21.0 toolchain go1.22.0 require ( - github.com/aws/aws-sdk-go v1.54.6 + github.com/aws/aws-sdk-go v1.55.5 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/hcl/v2 v2.21.0 github.com/hashicorp/packer-plugin-sdk v0.5.4 github.com/mitchellh/mapstructure v1.5.0 - github.com/outscale/osc-sdk-go/v2 v2.21.0 - github.com/zclconf/go-cty v1.14.4 + github.com/outscale/osc-sdk-go/v2 v2.23.0 + github.com/zclconf/go-cty v1.15.0 golang.org/x/sys v0.21.0 ) @@ -53,7 +53,7 @@ require ( github.com/hashicorp/go-getter/v2 v2.2.2 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect - github.com/hashicorp/go-retryablehttp v0.7.6 // indirect + github.com/hashicorp/go-retryablehttp v0.7.7 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect @@ -104,7 +104,7 @@ require ( golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/term v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect diff --git a/go.sum b/go.sum index 83ceaae..e5dff39 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go v1.44.103/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= -github.com/aws/aws-sdk-go v1.54.6 h1:HEYUib3yTt8E6vxjMWM3yAq5b+qjj/6aKA62mkgux9g= -github.com/aws/aws-sdk-go v1.54.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= +github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -170,8 +170,8 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= -github.com/hashicorp/go-retryablehttp v0.7.6 h1:TwRYfx2z2C4cLbXmT8I5PgP/xmuqASDyiVuGYfs9GZM= -github.com/hashicorp/go-retryablehttp v0.7.6/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= +github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= +github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo= @@ -292,8 +292,8 @@ github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/ github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/nywilken/go-cty v1.13.3 h1:03U99oXf3j3g9xgqAE3YGpixCjM8Mg09KZ0Ji9LzX0o= github.com/nywilken/go-cty v1.13.3/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= -github.com/outscale/osc-sdk-go/v2 v2.21.0 h1:8MqhexV+ALG76CvY8EpuQlr0+hC5VFrWQY4fHqdT358= -github.com/outscale/osc-sdk-go/v2 v2.21.0/go.mod h1:kzhtUErCzKYl87bZ+kDMphDafmnwbsyFJY9iHF7NgNE= +github.com/outscale/osc-sdk-go/v2 v2.23.0 h1:Ib134+ThQHmMtURcMTD9eTiAKeF1gSufbH3RdYa9+bY= +github.com/outscale/osc-sdk-go/v2 v2.23.0/go.mod h1:kzhtUErCzKYl87bZ+kDMphDafmnwbsyFJY9iHF7NgNE= github.com/packer-community/winrmcp v0.0.0-20221126162354-6e900dd2c68f h1:sWm3fnjG6kxvDuGiQf46Io5xCTj3QJfNJIeICJ4g1kw= github.com/packer-community/winrmcp v0.0.0-20221126162354-6e900dd2c68f/go.mod h1:f6Izs6JvFTdnRbziASagjZ2vmf55NSIkC/weStxCHqk= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -408,8 +408,8 @@ golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= From ec33255ad5b6eaeae8a4bbccf0070a1d67982680 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Tue, 17 Sep 2024 11:57:38 +0000 Subject: [PATCH 2/3] Fix bsu builder --- builder/bsu/builder.hcl2spec.go | 2 + builder/bsu/step_create_omi.go | 29 +++++-- builder/bsusurrogate/builder.hcl2spec.go | 2 + builder/bsusurrogate/step_register_omi.go | 3 +- builder/chroot/builder.hcl2spec.go | 4 +- builder/common/block_device.go | 95 ++++++++--------------- builder/common/omi_config.go | 1 + builder/common/step_update_omi.go | 6 +- 8 files changed, 65 insertions(+), 77 deletions(-) diff --git a/builder/bsu/builder.hcl2spec.go b/builder/bsu/builder.hcl2spec.go index 38a76d3..ffc99a2 100644 --- a/builder/bsu/builder.hcl2spec.go +++ b/builder/bsu/builder.hcl2spec.go @@ -44,6 +44,7 @@ type FlatConfig struct { SnapshotAccountIDs []string `mapstructure:"snapshot_account_ids" cty:"snapshot_account_ids" hcl:"snapshot_account_ids"` GlobalPermission *bool `mapstructure:"global_permission" cty:"global_permission" hcl:"global_permission"` ProductCodes []string `mapstructure:"product_codes" cty:"product_codes" hcl:"product_codes"` + RootDeviceName *string `mapstructure:"root_device_name" cty:"root_device_name" hcl:"root_device_name"` OMIMappings []common.FlatBlockDevice `mapstructure:"omi_block_device_mappings" cty:"omi_block_device_mappings" hcl:"omi_block_device_mappings"` LaunchMappings []common.FlatBlockDevice `mapstructure:"launch_block_device_mappings" cty:"launch_block_device_mappings" hcl:"launch_block_device_mappings"` AssociatePublicIpAddress *bool `mapstructure:"associate_public_ip_address" cty:"associate_public_ip_address" hcl:"associate_public_ip_address"` @@ -168,6 +169,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "snapshot_account_ids": &hcldec.AttrSpec{Name: "snapshot_account_ids", Type: cty.List(cty.String), Required: false}, "global_permission": &hcldec.AttrSpec{Name: "global_permission", Type: cty.Bool, Required: false}, "product_codes": &hcldec.AttrSpec{Name: "product_codes", Type: cty.List(cty.String), Required: false}, + "root_device_name": &hcldec.AttrSpec{Name: "root_device_name", Type: cty.String, Required: false}, "omi_block_device_mappings": &hcldec.BlockListSpec{TypeName: "omi_block_device_mappings", Nested: hcldec.ObjectSpec((*common.FlatBlockDevice)(nil).HCL2Spec())}, "launch_block_device_mappings": &hcldec.BlockListSpec{TypeName: "launch_block_device_mappings", Nested: hcldec.ObjectSpec((*common.FlatBlockDevice)(nil).HCL2Spec())}, "associate_public_ip_address": &hcldec.AttrSpec{Name: "associate_public_ip_address", Type: cty.Bool, Required: false}, diff --git a/builder/bsu/step_create_omi.go b/builder/bsu/step_create_omi.go index 2a78dc3..1503aed 100644 --- a/builder/bsu/step_create_omi.go +++ b/builder/bsu/step_create_omi.go @@ -29,15 +29,30 @@ func (s *stepCreateOMI) Run(ctx context.Context, state multistep.StateBag) multi ui.Say(fmt.Sprintf("Creating OMI %s from vm %s", omiName, vm.GetVmId())) blockDeviceMapping := config.BlockDevices.BuildOscOMIDevices() createOpts := oscgo.CreateImageRequest{ - VmId: vm.VmId, - ImageName: &omiName, - BlockDeviceMappings: &blockDeviceMapping, + ImageName: &omiName, } - if config.OMIDescription != "" { - createOpts.Description = &config.OMIDescription + if len(blockDeviceMapping) == 0 { + createOpts.SetVmId(vm.GetVmId()) + } else { + createOpts.SetBlockDeviceMappings(blockDeviceMapping) + if rootDName := config.RootDeviceName; rootDName != "" { + createOpts.SetRootDeviceName(rootDName) + } else { + err := fmt.Errorf("Error: MissingParameter: You must provide 'RootDeviceName' when creating omi with 'omi_block_device_mappings'.") + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + if prodCode := config.ProductCodes; prodCode != nil { + createOpts.SetProductCodes(prodCode) + } + + if description := config.OMIDescription; description != "" { + createOpts.SetDescription(description) } - if config.ProductCodes != nil { - createOpts.ProductCodes = &config.ProductCodes + if prodCode := config.ProductCodes; prodCode != nil { + createOpts.SetProductCodes(prodCode) } resp, _, err := oscconn.Api.ImageApi.CreateImage(oscconn.Auth).CreateImageRequest(createOpts).Execute() diff --git a/builder/bsusurrogate/builder.hcl2spec.go b/builder/bsusurrogate/builder.hcl2spec.go index e8d36c7..826e000 100644 --- a/builder/bsusurrogate/builder.hcl2spec.go +++ b/builder/bsusurrogate/builder.hcl2spec.go @@ -119,6 +119,7 @@ type FlatConfig struct { SnapshotAccountIDs []string `mapstructure:"snapshot_account_ids" cty:"snapshot_account_ids" hcl:"snapshot_account_ids"` GlobalPermission *bool `mapstructure:"global_permission" cty:"global_permission" hcl:"global_permission"` ProductCodes []string `mapstructure:"product_codes" cty:"product_codes" hcl:"product_codes"` + RootDeviceName *string `mapstructure:"root_device_name" cty:"root_device_name" hcl:"root_device_name"` RootDevice *FlatRootBlockDevice `mapstructure:"omi_root_device" cty:"omi_root_device" hcl:"omi_root_device"` VolumeRunTags common.TagMap `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` } @@ -243,6 +244,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "snapshot_account_ids": &hcldec.AttrSpec{Name: "snapshot_account_ids", Type: cty.List(cty.String), Required: false}, "global_permission": &hcldec.AttrSpec{Name: "global_permission", Type: cty.Bool, Required: false}, "product_codes": &hcldec.AttrSpec{Name: "product_codes", Type: cty.List(cty.String), Required: false}, + "root_device_name": &hcldec.AttrSpec{Name: "root_device_name", Type: cty.String, Required: false}, "omi_root_device": &hcldec.BlockSpec{TypeName: "omi_root_device", Nested: hcldec.ObjectSpec((*FlatRootBlockDevice)(nil).HCL2Spec())}, "run_volume_tags": &hcldec.AttrSpec{Name: "run_volume_tags", Type: cty.Map(cty.String), Required: false}, } diff --git a/builder/bsusurrogate/step_register_omi.go b/builder/bsusurrogate/step_register_omi.go index 42317d5..79da21c 100644 --- a/builder/bsusurrogate/step_register_omi.go +++ b/builder/bsusurrogate/step_register_omi.go @@ -153,8 +153,7 @@ func (s *StepRegisterOMI) combineDevices(snapshotIDs map[string]string) []oscgo. func copyToDeviceMappingImage(device osc.BlockDeviceMappingVmCreation) oscgo.BlockDeviceMappingImage { log.Printf("Copy device mapping image ") deviceImage := oscgo.BlockDeviceMappingImage{ - DeviceName: device.DeviceName, - VirtualDeviceName: device.VirtualDeviceName, + DeviceName: device.DeviceName, Bsu: &oscgo.BsuToCreate{ DeleteOnVmDeletion: device.Bsu.DeleteOnVmDeletion, Iops: device.Bsu.Iops, diff --git a/builder/chroot/builder.hcl2spec.go b/builder/chroot/builder.hcl2spec.go index 8c7a0fb..c22be80 100644 --- a/builder/chroot/builder.hcl2spec.go +++ b/builder/chroot/builder.hcl2spec.go @@ -34,6 +34,7 @@ type FlatConfig struct { SnapshotAccountIDs []string `mapstructure:"snapshot_account_ids" cty:"snapshot_account_ids" hcl:"snapshot_account_ids"` GlobalPermission *bool `mapstructure:"global_permission" cty:"global_permission" hcl:"global_permission"` ProductCodes []string `mapstructure:"product_codes" cty:"product_codes" hcl:"product_codes"` + RootDeviceName *string `mapstructure:"root_device_name" cty:"root_device_name" hcl:"root_device_name"` AccessKey *string `mapstructure:"access_key" cty:"access_key" hcl:"access_key"` CustomEndpointOAPI *string `mapstructure:"custom_endpoint_oapi" cty:"custom_endpoint_oapi" hcl:"custom_endpoint_oapi"` InsecureSkipTLSVerify *bool `mapstructure:"insecure_skip_tls_verify" cty:"insecure_skip_tls_verify" hcl:"insecure_skip_tls_verify"` @@ -56,7 +57,6 @@ type FlatConfig struct { MountPath *string `mapstructure:"mount_path" cty:"mount_path" hcl:"mount_path"` PostMountCommands []string `mapstructure:"post_mount_commands" cty:"post_mount_commands" hcl:"post_mount_commands"` PreMountCommands []string `mapstructure:"pre_mount_commands" cty:"pre_mount_commands" hcl:"pre_mount_commands"` - RootDeviceName *string `mapstructure:"root_device_name" cty:"root_device_name" hcl:"root_device_name"` RootVolumeSize *int64 `mapstructure:"root_volume_size" cty:"root_volume_size" hcl:"root_volume_size"` RootVolumeType *string `mapstructure:"root_volume_type" cty:"root_volume_type" hcl:"root_volume_type"` SourceOMI *string `mapstructure:"source_omi" cty:"source_omi" hcl:"source_omi"` @@ -99,6 +99,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "snapshot_account_ids": &hcldec.AttrSpec{Name: "snapshot_account_ids", Type: cty.List(cty.String), Required: false}, "global_permission": &hcldec.AttrSpec{Name: "global_permission", Type: cty.Bool, Required: false}, "product_codes": &hcldec.AttrSpec{Name: "product_codes", Type: cty.List(cty.String), Required: false}, + "root_device_name": &hcldec.AttrSpec{Name: "root_device_name", Type: cty.String, Required: false}, "access_key": &hcldec.AttrSpec{Name: "access_key", Type: cty.String, Required: false}, "custom_endpoint_oapi": &hcldec.AttrSpec{Name: "custom_endpoint_oapi", Type: cty.String, Required: false}, "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, @@ -121,7 +122,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "mount_path": &hcldec.AttrSpec{Name: "mount_path", Type: cty.String, Required: false}, "post_mount_commands": &hcldec.AttrSpec{Name: "post_mount_commands", Type: cty.List(cty.String), Required: false}, "pre_mount_commands": &hcldec.AttrSpec{Name: "pre_mount_commands", Type: cty.List(cty.String), Required: false}, - "root_device_name": &hcldec.AttrSpec{Name: "root_device_name", Type: cty.String, Required: false}, "root_volume_size": &hcldec.AttrSpec{Name: "root_volume_size", Type: cty.Number, Required: false}, "root_volume_type": &hcldec.AttrSpec{Name: "root_volume_type", Type: cty.String, Required: false}, "source_omi": &hcldec.AttrSpec{Name: "source_omi", Type: cty.String, Required: false}, diff --git a/builder/common/block_device.go b/builder/common/block_device.go index 4c37de6..fc3da06 100644 --- a/builder/common/block_device.go +++ b/builder/common/block_device.go @@ -2,8 +2,6 @@ package common import ( "fmt" - "log" - "strings" "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/packer-plugin-sdk/template/interpolate" @@ -35,43 +33,39 @@ type LaunchBlockDevices struct { LaunchMappings []BlockDevice `mapstructure:"launch_block_device_mappings"` } -func buildOscBlockDevicesImage(b []BlockDevice) []oscgo.BlockDeviceMappingImage { - var blockDevices []oscgo.BlockDeviceMappingImage - - for _, blockDevice := range b { - mapping := oscgo.BlockDeviceMappingImage{ - DeviceName: &blockDevice.DeviceName, - } - - if blockDevice.VirtualName != "" { - if strings.HasPrefix(blockDevice.VirtualName, "ephemeral") { - mapping.VirtualDeviceName = &blockDevice.VirtualName - } - } else { - bsu := oscgo.BsuToCreate{ - DeleteOnVmDeletion: &blockDevice.DeleteOnVmDeletion, - } +func setBsuToCreate(blockDevice BlockDevice) oscgo.BsuToCreate { + bsu := oscgo.NewBsuToCreate() - if blockDevice.VolumeType != "" { - bsu.VolumeType = &blockDevice.VolumeType - } + if deleteOnVmDeletion := blockDevice.DeleteOnVmDeletion; !deleteOnVmDeletion { + bsu.SetDeleteOnVmDeletion(deleteOnVmDeletion) + } + if volType := blockDevice.VolumeType; volType != "" { + bsu.SetVolumeType(volType) + } + if volSize := blockDevice.VolumeSize; volSize > 0 { + bsu.SetVolumeSize(int32(blockDevice.VolumeSize)) - if blockDevice.VolumeSize > 0 { - bsu.VolumeSize = oscgo.PtrInt32(int32(blockDevice.VolumeSize)) - } + } + // IOPS is only valid for io1 type + if blockDevice.VolumeType == "io1" { + bsu.SetIops(int32(blockDevice.IOPS)) + } + if snapId := blockDevice.SnapshotId; snapId != "" { + bsu.SetSnapshotId(snapId) + } - // IOPS is only valid for io1 type - if blockDevice.VolumeType == "io1" { - bsu.Iops = oscgo.PtrInt32(int32(blockDevice.IOPS)) - } + return *bsu +} - if blockDevice.SnapshotId != "" { - bsu.SnapshotId = &blockDevice.SnapshotId - } +func buildOscBlockDevicesImage(b []BlockDevice) []oscgo.BlockDeviceMappingImage { + var blockDevices []oscgo.BlockDeviceMappingImage + for _, blockDevice := range b { + mapping := oscgo.BlockDeviceMappingImage{} - mapping.Bsu = &bsu + if deviceName := blockDevice.DeviceName; deviceName != "" { + mapping.SetDeviceName(deviceName) } - + mapping.SetBsu(setBsuToCreate(blockDevice)) blockDevices = append(blockDevices, mapping) } return blockDevices @@ -83,41 +77,16 @@ func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingV var blockDevices []oscgo.BlockDeviceMappingVmCreation for _, blockDevice := range b { - mapping := oscgo.BlockDeviceMappingVmCreation{ - DeviceName: &blockDevice.DeviceName, + mapping := oscgo.BlockDeviceMappingVmCreation{} + + if deviceName := blockDevice.DeviceName; deviceName != "" { + mapping.SetDeviceName(deviceName) } if blockDevice.NoDevice { mapping.NoDevice = aws.String("") - //blockDevices = mapping[0] - } else if blockDevice.VirtualName != "" { - if strings.HasPrefix(blockDevice.VirtualName, "ephemeral") { - mapping.VirtualDeviceName = &blockDevice.VirtualName - } } else { - bsu := oscgo.BsuToCreate{ - DeleteOnVmDeletion: &blockDevice.DeleteOnVmDeletion, - } - - if blockDevice.VolumeType != "" { - bsu.VolumeType = &blockDevice.VolumeType - } - - if blockDevice.VolumeSize > 0 { - bsu.VolumeSize = oscgo.PtrInt32(int32(blockDevice.VolumeSize)) - - } - - // IOPS is only valid for io1 type - if blockDevice.VolumeType == "io1" { - bsu.Iops = oscgo.PtrInt32(int32(blockDevice.IOPS)) - } - - if blockDevice.SnapshotId != "" { - bsu.SnapshotId = &blockDevice.SnapshotId - } - - mapping.Bsu = &bsu + mapping.SetBsu(setBsuToCreate(blockDevice)) } log.Printf("block device mapping") diff --git a/builder/common/omi_config.go b/builder/common/omi_config.go index 596f109..ec4b3bf 100644 --- a/builder/common/omi_config.go +++ b/builder/common/omi_config.go @@ -23,6 +23,7 @@ type OMIConfig struct { SnapshotAccountIDs []string `mapstructure:"snapshot_account_ids"` GlobalPermission bool `mapstructure:"global_permission"` ProductCodes []string `mapstructure:"product_codes"` + RootDeviceName string `mapstructure:"root_device_name"` } func (c *OMIConfig) Prepare(accessConfig *AccessConfig, ctx *interpolate.Context) []error { diff --git a/builder/common/step_update_omi.go b/builder/common/step_update_omi.go index e655e3d..325b82b 100644 --- a/builder/common/step_update_omi.go +++ b/builder/common/step_update_omi.go @@ -32,8 +32,8 @@ func (s *StepUpdateOMIAttributes) Run(_ context.Context, state multistep.StateBa // Determine if there is any work to do. valid := false - valid = valid || (s.AccountIds != nil && len(s.AccountIds) > 0) - valid = valid || (s.SnapshotAccountIds != nil && len(s.SnapshotAccountIds) > 0) + valid = valid || (len(s.AccountIds) > 0) + valid = valid || (len(s.SnapshotAccountIds) > 0) valid = valid || s.GlobalPermission == true if !valid { return multistep.ActionContinue @@ -74,7 +74,7 @@ func (s *StepUpdateOMIAttributes) Run(_ context.Context, state multistep.StateBa } } - if s.AccountIds == nil || len(s.AccountIds) == 0 { + if len(s.AccountIds) == 0 { return multistep.ActionContinue } From f6ad723be81f85bce0610f97410bf32f0c18c780 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Tue, 17 Sep 2024 12:10:43 +0000 Subject: [PATCH 3/3] Update documentation and add hcl example --- .web-docs/components/builder/bsu/README.md | 118 +++++++++++++++++- .../components/builder/bsusurrogate/README.md | 85 ++++++++++--- builder/bsu/builder_acc_test.go | 2 +- builder/bsusurrogate/step_register_omi.go | 2 +- builder/bsuvolume/builder.hcl2spec.go | 2 - builder/chroot/builder.go | 1 - builder/common/block_device.go | 7 -- builder/common/block_device_test.go | 33 ----- builder/common/omi_config_test.go | 3 +- builder/common/run_config.hcl2spec.go | 2 - docs/builders/bsu.mdx | 118 +++++++++++++++++- docs/builders/bsusurrogate.mdx | 85 ++++++++++--- 12 files changed, 369 insertions(+), 89 deletions(-) diff --git a/.web-docs/components/builder/bsu/README.md b/.web-docs/components/builder/bsu/README.md index 299979d..15c1e6a 100644 --- a/.web-docs/components/builder/bsu/README.md +++ b/.web-docs/components/builder/bsu/README.md @@ -62,8 +62,6 @@ builder. - `snapshot_id` (string) - The ID of the snapshot - - `virtual_name` (string) - The virtual device name. See the documentation on [Block Device Mapping](https://docs.outscale.com/en/userguide/Defining-Block-Device-Mappings.html) for more information - - `volume_size` (number) - The size of the volume, in GiB. Required if not specifying a `snapshot_id` - `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD) volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic volumes @@ -167,7 +165,19 @@ builder. - `owners` (array of strings) - Filters the images by their owner. You may specify one or more Outscale account IDs, "self" (which will use the account whose credentials you are using to run Packer). This option is required for security reasons. Example: + #### HCL + ```hcl + source_omi_filter { + filters = { + image-name = "image-name-in-account" + root-device-type = "ebs" # or "bsu" + virtualization-type = "hvm" + } + owners = ["339215505907"] + } + ``` + #### JSON ```json { "source_omi_filter": { @@ -250,7 +260,19 @@ builder. ## Basic Example Here is a basic example. You will need to provide access keys, and may need to change the OMIS IDs according to what images exist at the time the template is run: +#### HCL +```hcl +source "outscale-bsu" "basic-example" { + region = "us-east-1" + vm_type = "t2.micro" + source_omi = "ami-abcfd0283" + omi_name = "packer_osc_{{timestamp}}" + ssh_username = "outscale" + ssh_interface = "public_ip" +} +``` +#### JSON ```json { "variables": { @@ -290,9 +312,91 @@ You can use this information to access the VM as it is running. Here is an example using the optional OMIS block device mappings. Our configuration of `launch_block_device_mappings` will expand the root volume (`/dev/sda`) to 40gb during the build (up from the default of 8gb). With -`ami_block_device_mappings` Outscale will attach additional volumes `/dev/sdb` and +`omi_block_device_mappings` Outscale will attach additional volumes `/dev/sdb` and `/dev/sdc` when we boot a new VM of our OMI. +#### HCL +##### with `launch_block_device_mappings` +```hcl +// export osc_access_key=$YOURKEY +variable "osc_access_key" { + type = string + // default = "hardcoded_key" +} + +// export osc_secret_key=$YOURSECRETKEY +variable "osc_secret_key" { + type = string + // default = "hardcoded_secret_key" +} + +source "outscale-bsu" "basic-example" { + region = "us-east-1" + vm_type = "t2.micro" + source_omi = "ami-abcfd0283" + omi_name = "packer_osc_{{timestamp}}" + ssh_username = "outscale" + ssh_interface = "public_ip" + + launch_block_device_mappings { + delete_on_vm_deletion = false + device_name = "/dev/sda1" + volume_size = 40 + volume_type = "gp2" + } + launch_block_device_mappings { + device_name = "/dev/sdc" + volume_size = 50 + volume_type = "gp2" + } + launch_block_device_mappings { + device_name = "/dev/sdc" + volume_size = 100 + volume_type = "gp2" + } +} + +``` +##### with `omi_block_device_mappings` +```hcl +// export osc_access_key=$YOURKEY +variable "aws_access_key" { + type = string + // default = "hardcoded_key" +} + +// export osc_secret_key=$YOURSECRETKEY +variable "aws_secret_key" { + type = string + // default = "hardcoded_secret_key" +} + +source "outscale-bsu" "basic-example" { + region = "us-east-1" + vm_type = "t2.micro" + source_omi = "ami-abcfd0283" + omi_name = "packer_osc_{{timestamp}}" + root_device_name = "/dev/sda1" + ssh_username = "outscale" + ssh_interface = "public_ip" + + omi_block_device_mappings { + delete_on_vm_deletion = false + device_name = "/dev/sda1" + snapshot_id = "snap-792fce69" + volume_size = 40 + volume_type = "gp2" + } + omi_block_device_mappings { + device_name = "/dev/sdc" + snapshot_id = "snap-792fce69" + volume_size = 50 + volume_type = "gp2" + } +} + +``` + ```json { "type": "outscale-bsu", @@ -311,14 +415,16 @@ configuration of `launch_block_device_mappings` will expand the root volume "delete_on_vm_deletion": true } ], - "omi_block_device_mappings": [ + "launch_block_device_mappings": [ { "device_name": "/dev/sdb", - "virtual_name": "ephemeral0" + "volume_size": 50, + "volume_type": "gp2" }, { "device_name": "/dev/sdc", - "virtual_name": "ephemeral1" + "volume_size": 100, + "volume_type": "gp2" } ] } diff --git a/.web-docs/components/builder/bsusurrogate/README.md b/.web-docs/components/builder/bsusurrogate/README.md index 7f29bec..199dddb 100644 --- a/.web-docs/components/builder/bsusurrogate/README.md +++ b/.web-docs/components/builder/bsusurrogate/README.md @@ -62,8 +62,6 @@ builder. - `snapshot_id` (string) - The ID of the snapshot - - `virtual_name` (string) - The virtual device name. See the documentation on [Block Device Mapping](https://docs.outscale.com/en/userguide/Defining-Block-Device-Mappings.html) for more information. - - `volume_size` (number) - The size of the volume, in GiB. Required if not specifying a `snapshot_id` - `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD) volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic volumes @@ -182,18 +180,31 @@ builder. Example: - ```json - { - "source_omi_filter": { - "filters": { - "virtualization-type": "hvm", - "image-name": "image-name", - "root-device-type": "ebs" - }, - "owners": ["099720109477"] - } - } - ``` +#### HCL +```hcl +source_omi_filter { + filters = { + image-name = "image-name" + root-device-type = "ebs" + virtualization-type = "hvm" + } + owners = ["099720109477"] +} +``` + +#### JSON +```json +{ + "source_omi_filter": { + "filters": { + "virtualization-type": "hvm", + "image-name": "image-name", + "root-device-type": "ebs" + }, + "owners": ["099720109477"] + } +} +``` This selects an Ubuntu 16.04 HVM BSU OMIS from Canonical. NOTE: This will fail unless _exactly_ one OMIS is returned. In the above example, @@ -245,6 +256,52 @@ builder. ## Basic Example +#### HCL +```hcl +// export osc_access_key=$YOURKEY +variable "osc_access_key" { + type = string + // default = "hardcoded_key" +} + +// export osc_secret_key=$YOURSECRETKEY +variable "osc_secret_key" { + type = string + // default = "hardcoded_secret_key" +} + +source "outscale-bsusurrogate" "example-bsusurrogate" { + launch_block_device_mappings { + delete_on_vm_deletion = true + device_name = "/dev/xvdf" + iops = 3000 + volume_size = 200 + volume_type = "io1" + } + source_omi_filter { + filters = { + image-name = "image-name" + root-device-type = "ebs" + virtualization-type = "hvm" + } + owners = ["099720109477"] + } + omi_root_device { + delete_on_vm_deletion = true + device_name = "/dev/sda1" + source_device_name = "/dev/xvdf" + volume_size = 50 + volume_type = "standard" + } + omi_name = "packer_osc_{{timestamp}}" + source_omi = "ami-bcfc34e0" + ssh_interface = "public_ip" + ssh_username = "outscale" + vm_type = "t2.medium" + region = "eu-west-2" +} +``` +#### JSON ```json { "type": "outscale-bsusurrogate", diff --git a/builder/bsu/builder_acc_test.go b/builder/bsu/builder_acc_test.go index cc7ea2c..857da44 100644 --- a/builder/bsu/builder_acc_test.go +++ b/builder/bsu/builder_acc_test.go @@ -65,7 +65,7 @@ const testBuilderAccWithGoodProductCode = ` "source_omi": "ami-68ed4301", "ssh_username": "outscale", "omi_name": "packer-test", - "product_codes": ["pty-2ffc33dc"], + "product_codes": ["0001"], "associate_public_ip_address": true, "force_deregister": true }] diff --git a/builder/bsusurrogate/step_register_omi.go b/builder/bsusurrogate/step_register_omi.go index 79da21c..23fc24c 100644 --- a/builder/bsusurrogate/step_register_omi.go +++ b/builder/bsusurrogate/step_register_omi.go @@ -123,7 +123,7 @@ func (s *StepRegisterOMI) combineDevices(snapshotIDs map[string]string) []oscgo. // Devices in launch_block_device_mappings override any with // the same name in ami_block_device_mappings, except for the - // one designated as the root device in ami_root_device + // one designated as the root device in omi_root_device for _, device := range s.LaunchDevices { snapshotID, ok := snapshotIDs[device.GetDeviceName()] if ok && snapshotID != "" { diff --git a/builder/bsuvolume/builder.hcl2spec.go b/builder/bsuvolume/builder.hcl2spec.go index 5e1c987..d13f066 100644 --- a/builder/bsuvolume/builder.hcl2spec.go +++ b/builder/bsuvolume/builder.hcl2spec.go @@ -16,7 +16,6 @@ type FlatBlockDevice struct { IOPS *int64 `mapstructure:"iops" cty:"iops" hcl:"iops"` NoDevice *bool `mapstructure:"no_device" cty:"no_device" hcl:"no_device"` SnapshotId *string `mapstructure:"snapshot_id" cty:"snapshot_id" hcl:"snapshot_id"` - VirtualName *string `mapstructure:"virtual_name" cty:"virtual_name" hcl:"virtual_name"` VolumeType *string `mapstructure:"volume_type" cty:"volume_type" hcl:"volume_type"` VolumeSize *int64 `mapstructure:"volume_size" cty:"volume_size" hcl:"volume_size"` Tags common.TagMap `mapstructure:"tags" cty:"tags" hcl:"tags"` @@ -39,7 +38,6 @@ func (*FlatBlockDevice) HCL2Spec() map[string]hcldec.Spec { "iops": &hcldec.AttrSpec{Name: "iops", Type: cty.Number, Required: false}, "no_device": &hcldec.AttrSpec{Name: "no_device", Type: cty.Bool, Required: false}, "snapshot_id": &hcldec.AttrSpec{Name: "snapshot_id", Type: cty.String, Required: false}, - "virtual_name": &hcldec.AttrSpec{Name: "virtual_name", Type: cty.String, Required: false}, "volume_type": &hcldec.AttrSpec{Name: "volume_type", Type: cty.String, Required: false}, "volume_size": &hcldec.AttrSpec{Name: "volume_size", Type: cty.Number, Required: false}, "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.Map(cty.String), Required: false}, diff --git a/builder/chroot/builder.go b/builder/chroot/builder.go index 271a5ec..ba3956a 100644 --- a/builder/chroot/builder.go +++ b/builder/chroot/builder.go @@ -43,7 +43,6 @@ type Config struct { MountPath string `mapstructure:"mount_path"` PostMountCommands []string `mapstructure:"post_mount_commands"` PreMountCommands []string `mapstructure:"pre_mount_commands"` - RootDeviceName string `mapstructure:"root_device_name"` RootVolumeSize int64 `mapstructure:"root_volume_size"` RootVolumeType string `mapstructure:"root_volume_type"` SourceOMI string `mapstructure:"source_omi"` diff --git a/builder/common/block_device.go b/builder/common/block_device.go index fc3da06..21fe4b8 100644 --- a/builder/common/block_device.go +++ b/builder/common/block_device.go @@ -15,7 +15,6 @@ type BlockDevice struct { IOPS int64 `mapstructure:"iops"` NoDevice bool `mapstructure:"no_device"` SnapshotId string `mapstructure:"snapshot_id"` - VirtualName string `mapstructure:"virtual_name"` VolumeType string `mapstructure:"volume_type"` VolumeSize int64 `mapstructure:"volume_size"` } @@ -72,10 +71,7 @@ func buildOscBlockDevicesImage(b []BlockDevice) []oscgo.BlockDeviceMappingImage } func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingVmCreation { - log.Printf("[DEBUG] Launch Block Device %#v", b) - var blockDevices []oscgo.BlockDeviceMappingVmCreation - for _, blockDevice := range b { mapping := oscgo.BlockDeviceMappingVmCreation{} @@ -88,9 +84,6 @@ func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingV } else { mapping.SetBsu(setBsuToCreate(blockDevice)) } - - log.Printf("block device mapping") - blockDevices = append(blockDevices, mapping) } return blockDevices diff --git a/builder/common/block_device_test.go b/builder/common/block_device_test.go index faabc5b..fe779b5 100644 --- a/builder/common/block_device_test.go +++ b/builder/common/block_device_test.go @@ -113,28 +113,6 @@ func TestBlockDevice_LaunchDevices(t *testing.T) { }, }, }, - { - Config: &BlockDevice{ - DeviceName: "/dev/sdb", - VirtualName: "ephemeral0", - }, - - Result: oscgo.BlockDeviceMappingVmCreation{ - DeviceName: oscgo.PtrString("/dev/sdb"), - VirtualDeviceName: oscgo.PtrString("ephemeral0"), - }, - }, - { - Config: &BlockDevice{ - DeviceName: "/dev/sdb", - NoDevice: true, - }, - - Result: oscgo.BlockDeviceMappingVmCreation{ - DeviceName: oscgo.PtrString("/dev/sdb"), - NoDevice: oscgo.PtrString(""), - }, - }, } for _, tc := range cases { @@ -260,17 +238,6 @@ func TestBlockDevice_OMI(t *testing.T) { }, }, }, - { - Config: &BlockDevice{ - DeviceName: "/dev/sdb", - VirtualName: "ephemeral0", - }, - - Result: oscgo.BlockDeviceMappingImage{ - DeviceName: oscgo.PtrString("/dev/sdb"), - VirtualDeviceName: oscgo.PtrString("ephemeral0"), - }, - }, } for i, tc := range cases { diff --git a/builder/common/omi_config_test.go b/builder/common/omi_config_test.go index 61754a4..10a8ac3 100644 --- a/builder/common/omi_config_test.go +++ b/builder/common/omi_config_test.go @@ -1,7 +1,6 @@ package common import ( - "fmt" "reflect" "testing" ) @@ -66,7 +65,7 @@ func TestOMIConfigPrepare_regions(t *testing.T) { c.OMIRegions = []string{"us-east-1", "us-east-2", "us-west-1"} if errs = c.prepareRegions(accessConf); len(errs) > 0 { - t.Fatalf(fmt.Sprintf("shouldn't have error: %s", errs[0])) + t.Fatalf("shouldn't have error: %s", errs[0]) } c.OMIRegions = []string{"us-east-1", "us-east-2", "us-west-1"} diff --git a/builder/common/run_config.hcl2spec.go b/builder/common/run_config.hcl2spec.go index 3cdbde3..4ccf6b9 100644 --- a/builder/common/run_config.hcl2spec.go +++ b/builder/common/run_config.hcl2spec.go @@ -16,7 +16,6 @@ type FlatBlockDevice struct { IOPS *int64 `mapstructure:"iops" cty:"iops" hcl:"iops"` NoDevice *bool `mapstructure:"no_device" cty:"no_device" hcl:"no_device"` SnapshotId *string `mapstructure:"snapshot_id" cty:"snapshot_id" hcl:"snapshot_id"` - VirtualName *string `mapstructure:"virtual_name" cty:"virtual_name" hcl:"virtual_name"` VolumeType *string `mapstructure:"volume_type" cty:"volume_type" hcl:"volume_type"` VolumeSize *int64 `mapstructure:"volume_size" cty:"volume_size" hcl:"volume_size"` } @@ -38,7 +37,6 @@ func (*FlatBlockDevice) HCL2Spec() map[string]hcldec.Spec { "iops": &hcldec.AttrSpec{Name: "iops", Type: cty.Number, Required: false}, "no_device": &hcldec.AttrSpec{Name: "no_device", Type: cty.Bool, Required: false}, "snapshot_id": &hcldec.AttrSpec{Name: "snapshot_id", Type: cty.String, Required: false}, - "virtual_name": &hcldec.AttrSpec{Name: "virtual_name", Type: cty.String, Required: false}, "volume_type": &hcldec.AttrSpec{Name: "volume_type", Type: cty.String, Required: false}, "volume_size": &hcldec.AttrSpec{Name: "volume_size", Type: cty.Number, Required: false}, } diff --git a/docs/builders/bsu.mdx b/docs/builders/bsu.mdx index 875694b..9c9eeeb 100644 --- a/docs/builders/bsu.mdx +++ b/docs/builders/bsu.mdx @@ -76,8 +76,6 @@ builder. - `snapshot_id` (string) - The ID of the snapshot - - `virtual_name` (string) - The virtual device name. See the documentation on [Block Device Mapping](https://docs.outscale.com/en/userguide/Defining-Block-Device-Mappings.html) for more information - - `volume_size` (number) - The size of the volume, in GiB. Required if not specifying a `snapshot_id` - `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD) volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic volumes @@ -181,7 +179,19 @@ builder. - `owners` (array of strings) - Filters the images by their owner. You may specify one or more Outscale account IDs, "self" (which will use the account whose credentials you are using to run Packer). This option is required for security reasons. Example: + #### HCL + ```hcl + source_omi_filter { + filters = { + image-name = "image-name-in-account" + root-device-type = "ebs" # or "bsu" + virtualization-type = "hvm" + } + owners = ["339215505907"] + } + ``` + #### JSON ```json { "source_omi_filter": { @@ -248,7 +258,19 @@ builder. ## Basic Example Here is a basic example. You will need to provide access keys, and may need to change the OMIS IDs according to what images exist at the time the template is run: +#### HCL +```hcl +source "outscale-bsu" "basic-example" { + region = "us-east-1" + vm_type = "t2.micro" + source_omi = "ami-abcfd0283" + omi_name = "packer_osc_{{timestamp}}" + ssh_username = "outscale" + ssh_interface = "public_ip" +} +``` +#### JSON ```json { "variables": { @@ -288,9 +310,91 @@ You can use this information to access the VM as it is running. Here is an example using the optional OMIS block device mappings. Our configuration of `launch_block_device_mappings` will expand the root volume (`/dev/sda`) to 40gb during the build (up from the default of 8gb). With -`ami_block_device_mappings` Outscale will attach additional volumes `/dev/sdb` and +`omi_block_device_mappings` Outscale will attach additional volumes `/dev/sdb` and `/dev/sdc` when we boot a new VM of our OMI. +#### HCL +##### with `launch_block_device_mappings` +```hcl +// export osc_access_key=$YOURKEY +variable "osc_access_key" { + type = string + // default = "hardcoded_key" +} + +// export osc_secret_key=$YOURSECRETKEY +variable "osc_secret_key" { + type = string + // default = "hardcoded_secret_key" +} + +source "outscale-bsu" "basic-example" { + region = "us-east-1" + vm_type = "t2.micro" + source_omi = "ami-abcfd0283" + omi_name = "packer_osc_{{timestamp}}" + ssh_username = "outscale" + ssh_interface = "public_ip" + + launch_block_device_mappings { + delete_on_vm_deletion = false + device_name = "/dev/sda1" + volume_size = 40 + volume_type = "gp2" + } + launch_block_device_mappings { + device_name = "/dev/sdc" + volume_size = 50 + volume_type = "gp2" + } + launch_block_device_mappings { + device_name = "/dev/sdc" + volume_size = 100 + volume_type = "gp2" + } +} + +``` +##### with `omi_block_device_mappings` +```hcl +// export osc_access_key=$YOURKEY +variable "aws_access_key" { + type = string + // default = "hardcoded_key" +} + +// export osc_secret_key=$YOURSECRETKEY +variable "aws_secret_key" { + type = string + // default = "hardcoded_secret_key" +} + +source "outscale-bsu" "basic-example" { + region = "us-east-1" + vm_type = "t2.micro" + source_omi = "ami-abcfd0283" + omi_name = "packer_osc_{{timestamp}}" + root_device_name = "/dev/sda1" + ssh_username = "outscale" + ssh_interface = "public_ip" + + omi_block_device_mappings { + delete_on_vm_deletion = false + device_name = "/dev/sda1" + snapshot_id = "snap-792fce69" + volume_size = 40 + volume_type = "gp2" + } + omi_block_device_mappings { + device_name = "/dev/sdc" + snapshot_id = "snap-792fce69" + volume_size = 50 + volume_type = "gp2" + } +} + +``` + ```json { "type": "outscale-bsu", @@ -309,14 +413,16 @@ configuration of `launch_block_device_mappings` will expand the root volume "delete_on_vm_deletion": true } ], - "omi_block_device_mappings": [ + "launch_block_device_mappings": [ { "device_name": "/dev/sdb", - "virtual_name": "ephemeral0" + "volume_size": 50, + "volume_type": "gp2" }, { "device_name": "/dev/sdc", - "virtual_name": "ephemeral1" + "volume_size": 100, + "volume_type": "gp2" } ] } diff --git a/docs/builders/bsusurrogate.mdx b/docs/builders/bsusurrogate.mdx index 58e1df9..3cc1617 100644 --- a/docs/builders/bsusurrogate.mdx +++ b/docs/builders/bsusurrogate.mdx @@ -72,8 +72,6 @@ builder. - `snapshot_id` (string) - The ID of the snapshot - - `virtual_name` (string) - The virtual device name. See the documentation on [Block Device Mapping](https://docs.outscale.com/en/userguide/Defining-Block-Device-Mappings.html) for more information. - - `volume_size` (number) - The size of the volume, in GiB. Required if not specifying a `snapshot_id` - `volume_type` (string) - The volume type. `gp2` for General Purpose (SSD) volumes, `io1` for Provisioned IOPS (SSD) volumes, and `standard` for Magnetic volumes @@ -192,18 +190,31 @@ builder. Example: - ```json - { - "source_omi_filter": { - "filters": { - "virtualization-type": "hvm", - "image-name": "image-name", - "root-device-type": "ebs" - }, - "owners": ["099720109477"] - } - } - ``` +#### HCL +```hcl +source_omi_filter { + filters = { + image-name = "image-name" + root-device-type = "ebs" + virtualization-type = "hvm" + } + owners = ["099720109477"] +} +``` + +#### JSON +```json +{ + "source_omi_filter": { + "filters": { + "virtualization-type": "hvm", + "image-name": "image-name", + "root-device-type": "ebs" + }, + "owners": ["099720109477"] + } +} +``` This selects an Ubuntu 16.04 HVM BSU OMIS from Canonical. NOTE: This will fail unless _exactly_ one OMIS is returned. In the above example, @@ -255,6 +266,52 @@ builder. ## Basic Example +#### HCL +```hcl +// export osc_access_key=$YOURKEY +variable "osc_access_key" { + type = string + // default = "hardcoded_key" +} + +// export osc_secret_key=$YOURSECRETKEY +variable "osc_secret_key" { + type = string + // default = "hardcoded_secret_key" +} + +source "outscale-bsusurrogate" "example-bsusurrogate" { + launch_block_device_mappings { + delete_on_vm_deletion = true + device_name = "/dev/xvdf" + iops = 3000 + volume_size = 200 + volume_type = "io1" + } + source_omi_filter { + filters = { + image-name = "image-name" + root-device-type = "ebs" + virtualization-type = "hvm" + } + owners = ["099720109477"] + } + omi_root_device { + delete_on_vm_deletion = true + device_name = "/dev/sda1" + source_device_name = "/dev/xvdf" + volume_size = 50 + volume_type = "standard" + } + omi_name = "packer_osc_{{timestamp}}" + source_omi = "ami-bcfc34e0" + ssh_interface = "public_ip" + ssh_username = "outscale" + vm_type = "t2.medium" + region = "eu-west-2" +} +``` +#### JSON ```json { "type": "outscale-bsusurrogate",