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",