hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
72 stars 110 forks source link

Unable to set volume size on amazon-ebs #443

Open lsq-ablair opened 9 months ago

lsq-ablair commented 9 months ago

May relate to https://github.com/hashicorp/packer-plugin-amazon/issues/122.

When specifying an amazon-ebs builder, I'm trying to set the boot volume size with launch_block_device_mappings. By the above bug, I should set this to "xvda" for Windows root devices.

However, with the hcl code,

data "amazon-ami" "windows_server_2022" {
  filters = {
    name                = "Windows_Server-2022-English-Full-Base-*"
    root-device-type    = "ebs"
    virtualization-type = "hvm"
  }
  most_recent = true
  owners = ["801119661308"] # Amazon Official
  region = "us-east-1"
}

source "amazon-ebs" "this" {
  ami_name = "Test"
  ami_virtualization_type = "hvm"
  instance_type = "m3.xlarge"
  launch_block_device_mappings {
    # The C drive
    delete_on_termination = true
    device_name           = "xvda" #"/dev/xvda"
    volume_size           = 50
  }
  launch_block_device_mappings {
    delete_on_termination = true
    device_name           = "xvdb"
    volume_size           = 100
    volume_type           = "gp3"
  }
  region = "us-east-1"
  source_ami        = data.amazon-ami.windows_server_2022.id
  subnet_id         = var.subnet_id
  user_data      = templatefile(var.user_data_file, {winrm_password = data.external-raw.random_pass.result})
communicator     = "winrm"
  winrm_insecure = true
  winrm_port     = 5986
  winrm_use_ssl  = true
}

I get three volumes. The goal is to increase /dev/sda1 from 30 -> 50GB, but instead I get a new volume:

device_name = "/dev/xvda"
vol-006f0d5xxxx /dev/sda1 30 Attached 2023/12/15
vol-07130xxx /dev/xvda 50 Attached 2023/12/15
vol-0a14a96xxx xvdb 100 Attached
device_name = "xvda"
vol-0279fxxx /dev/sda1 30 Attached 2023/12/15
vol-03214xxx xvda 50 Attached 2023/12/15
vol-0111xxx xvdb 100 Attached

The two xvdX volumes are kept separate and neither applies to the root volume. However, when I specify either /dev/sda or sda, I get an error:

  launch_block_device_mappings {
    # The C drive
    delete_on_termination = true
    device_name           = "/dev/sda"
    volume_size           = 50
  }

==> amazon-ebs.this: Error launching source instance: InvalidBlockDeviceMapping: Invalid 
==> amazon-ebs.this:    device name /dev/sda
==> amazon-ebs.this:    status code: 400, request id: cc529xxx-xxx

I believe this is a bug or regression. Or is there something wrong with the builder config?