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

Allow AMI block device mapping to be created without snapshot #5290

Closed
otterley opened this issue Aug 28, 2017 · 8 comments
Closed

Allow AMI block device mapping to be created without snapshot #5290

otterley opened this issue Aug 28, 2017 · 8 comments

Comments

@otterley
Copy link

I have a use case where I have two launch_block_device_mappings, /dev/sda1 (root device) and /dev/sdb (data device). The data device exists during the build phase to satisfy some build-time prerequisites, but the actual volume content can be discarded at the the end of the build. The device can also be quite small.

Meanwhile, there are two ami_block_device_mappings of the same device names, /dev/sda1 and /dev/sdb. I'd like /dev/sdb NOT to be associated with a snapshot, since at launch time the instance should have a fresh volume. But Packer seems to always associate it with a snapshot because the device was mapped at launch time. Setting snapshot_id to "" seems to have no effect.

@SwampDragons
Copy link
Contributor

Maybe I'm misunderstanding your use case -- does delete_on_termination not work for you?

@otterley
Copy link
Author

otterley commented Aug 28, 2017

No, it doesn't. It sets the flag on the attachment, but doesn't change the snapshot ID associated with it.

As a hack, I tried to create a temporary attachment to /dev/sdf in launch_block_device_mappings and then add /dev/sdb to ami_block_device_mappings. So my mappings looked like this:

    "launch_block_device_mappings": [{
      "device_name": "/dev/sda1",
      "delete_on_termination": true,
      "encrypted": false,
      "volume_size": "100",
      "volume_type": "gp2"
    },
    {
      "device_name": "/dev/sdf",
      "delete_on_termination": true,
      "encrypted": false,
      "volume_size": "100",
      "volume_type": "gp2"
    }],
    "ami_block_device_mappings": [{
      "device_name": "/dev/sda1",
      "delete_on_termination": true,
      "encrypted": false,
      "volume_size": "100",
      "volume_type": "gp2"
    },
    {
      "device_name": "/dev/sdb",
      "delete_on_termination": false,
      "encrypted": true,
      "volume_size": "1000",
      "volume_type": "gp2"
    }]
  }]

This created the /dev/sdb mapping without a snapshot, but /dev/sdf remained associated with the AMI as a block device mapping, even though I didn't specify it (and don't want it).

@tomelliff
Copy link
Contributor

This confused me as well because the docs state (emphasis mine):

launch_block_device_mappings (array of block device mappings) - Add one or more block devices before the Packer build starts. These are not necessarily preserved when booting from the AMI built with Packer. See ami_block_device_mappings, above, for details.

I'm not sure I understand what that emphasised comment means if the launch volumes are associated with the snapshot?

In my case I want to create an AMI that has some application data stored on a separate EBS volume and is bootstrapped when the application is installed. I want to discard this application data and then I will use Terraform to attach the persistent volume to a new instance in its place. Either a user data script or a Terraform remote provisioner would then execute a mount -a to mount the persistent volume.

@riponbanik
Copy link

riponbanik commented May 10, 2018

I have got a wired issue recently, a ghost ephemeral device is getting attached, even though it was not created with launch_block_device_mappings and launch_block_device_mappings when launching via terraform.

"ebs_block_device.4241468425.device_name": "xvdco",
"ebs_block_device.4241468425.encrypted": "true",
"ebs_block_device.4241468425.iops": "300",
"ebs_block_device.4241468425.snapshot_id": "",
"ebs_block_device.4241468425.volume_size": "100",
"ebs_block_device.4241468

My block device mapping is below -

"launch_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_type": "gp2",
"volume_size": 100,
"delete_on_termination": true
},
{
"device_name": "/dev/sde",
"delete_on_termination": true,
"volume_size": "80",
"volume_type": "gp2"
},
{
"device_name": "/dev/sdf",
"delete_on_termination": true,
"volume_size": "100",
"volume_type": "gp2"
},
{
"device_name": "/dev/sdg",
"delete_on_termination": true,
"volume_size": "100",
"volume_type": "gp2"
},
{
"device_name": "/dev/sdi",
"delete_on_termination": true,
"volume_size": "100",
"volume_type": "gp2"
}
],
"ami_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_type": "gp2",
"volume_size": 100,
"delete_on_termination": true
},
{
"device_name": "/dev/sde",
"delete_on_termination": true,
"volume_size": "80",
"volume_type": "gp2"
},
{
"device_name": "/dev/sdf",
"delete_on_termination": true,
"volume_size": "100",
"volume_type": "gp2"
},
{
"device_name": "/dev/sdg",
"delete_on_termination": true,
"volume_size": "100",
"volume_type": "gp2"
},
{
"device_name": "/dev/sdi",
"delete_on_termination": true,
"volume_size": "100",
"volume_type": "gp2"
}
]

@jbouse
Copy link

jbouse commented Aug 20, 2019

What is the status of this? I'm trying to build a custom AMI built off a source AMI that has a 2nd EBS volume that does not use/require a snapshot but when Packer builds my custom AMI following the template the 2nd EBS volume now has a snapshot that I can't seem to get rid of.

@rickard-von-essen
Copy link
Collaborator

@ghost
Copy link

ghost commented Mar 29, 2021

This issue has been automatically migrated to hashicorp/packer-plugin-amazon#19 because it looks like an issue with that plugin. If you believe this is not an issue with the plugin, please reply to hashicorp/packer-plugin-amazon#19.

@ghost ghost closed this as completed Mar 29, 2021
@ghost
Copy link

ghost commented Apr 29, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants