Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bsu and update doc #205

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 112 additions & 6 deletions .web-docs/components/builder/bsu/README.md
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
85 changes: 71 additions & 14 deletions .web-docs/components/builder/bsusurrogate/README.md
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 2 additions & 0 deletions builder/bsu/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion builder/bsu/builder_acc_test.go
Original file line number Diff line number Diff line change
@@ -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
}]
29 changes: 22 additions & 7 deletions builder/bsu/step_create_omi.go
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions builder/bsusurrogate/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions builder/bsusurrogate/step_register_omi.go
Original file line number Diff line number Diff line change
@@ -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 != "" {
@@ -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,
2 changes: 0 additions & 2 deletions builder/bsuvolume/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion builder/chroot/builder.go
Original file line number Diff line number Diff line change
@@ -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"`
Loading
Loading