hashicorp / packer-plugin-amazon

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

Allow setting LicenseSpecifications, aiding auto-allocation of dedicated hosts #132

Open travisby opened 2 years ago

travisby commented 2 years ago

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

The AWS sdk supports LicenseSpecifications as part of the RunInstancesInput.

It would be great if - as part of amazon-ebs I was able to configure the said license specification.

Specifying a license will allow you to pick a customer managed license that is backed by a host-resource-group, which in turn has the ability to auto-allocate EC2 hosts. By using this, it would be possible for packer to create (and let AWS finally destroy) dedicated metal instances for the use of image building.

Use Case(s)

Today, my team uses packer to build OSX images in AWS. This requires the mac1.metal instance type, which today requires us to manually aws ec2 allocate-host before we run packer. I believe with the above feature it could all happen automatically

Potential configuration

source "amazon-ebs" "mac-packer-example" {
  license_config = [
    "arn:aws:license-manager:us-west-2:90XXXXXXX930:license-configuration:lic-18ba608184961fd50ad6b405ffb6a5b5"
  ] 
  ami_name      = "${var.ami_name}-${local.timestamp}"
  ami_virtualization_type = "hvm"
  ssh_username = "ec2-user"
  ssh_timeout = "2h"
  tenancy = "host"
  ebs_optimized = true
  instance_type = "mac1.metal"
  region        = "${var.region}"
  subnet_id = "${var.subnet_id}"
  ssh_interface = "session_manager"
  aws_polling {
    delay_seconds = 60
    max_attempts = 60
  }
  launch_block_device_mappings {
    device_name = "/dev/sda1"
    volume_size = "${var.root_volume_size_gb}"
    volume_type = "gp3"
    iops = 3000
    throughput = 125
    delete_on_termination = true
  }
  source_ami_filter {
    filters = {
      name                = "amzn-ec2-macos-11.2.*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["amazon"]
  }
}

Potential References

KhrisRichardson-BO commented 2 years ago

I've had PR https://github.com/hashicorp/packer-plugin-amazon/pull/109 open to do just as you requested, but have yet to get any feedback.

azhurbilo commented 1 year ago

@KhrisRichardson-BO thnx a lot for PR! Maybe you know how it's possible to setup AWS Macos machine building?

because "dedicated" doesn't work for mac2.metal or mac1.metal we received error

Error launching source instance: InvalidParameterValue: Value (mac2.metal) for parameter instanceType is invalid. Instance type ‘mac2.metal’ cannot be launched with tenancy ‘dedicated’

and we again need manually create dedicated host and then build macos image with tenancy = "host"

the same as described here https://aws.amazon.com/blogs/compute/building-amazon-machine-images-amis-for-ec2-mac-instances-with-packer/

expected behaviour:

joneskoo commented 1 year ago

This was implemented in #109 and should me marked done.

To use it you need in source:

  instance_type = "mac1.metal"
  license_specifications {
    license_configuration_request {
      license_configuration_arn = "arn:..."
    }
  }
  placement {
    tenancy = "host"
  }

And license needs to be added into host resource group.

Note the documentation has wrong syntax for above.