exporting EC2 instances to OVF after packer provisions

177 views
Skip to first unread message

Kevin Milner

unread,
Sep 21, 2018, 12:34:46 PM9/21/18
to Packer
I'm trying to export an ovf from an EC2 instance on AWS and I have a question about the post-processor. 
I would THINK the post-processor would execute before the instance is terminated. My plan was to call a script to use aws cli to export the instance as an ovf (which then saves the ovf to a bucket in s3. 
The problem seems to be that the aws command is to create the ovf from an INSTANCE (see https://docs.aws.amazon.com/cli/latest/reference/ec2/create-instance-export-task.html) but by the time the post-processor gets to it, packer has already terminated the instance on AWS and all I'm left with is an AMI. I would like to avoid spinning the AMI back up into an instance, then exporting the instance if I can avoid it.
Is there some way I can tell packer to keep the instance up (or at least not terminated and deleted) until I can export the OVF?
Another question I have is about the builder itself. Is there some way I can get the instance ID from the builder? It displaces the instance id when first building, and that would be useful since I need it for the export command. All I know how to get is the ami id (aws ec2 describe-images --<stuff>).

Rickard von Essen

unread,
Sep 22, 2018, 2:21:55 AM9/22/18
to packe...@googlegroups.com
I would THINK the post-processor would execute before the instance is terminated.
No, the post+processor run on the artifact of the builder, which in this case is the AMI.

Instead I suggest that you as your last provisioner runs a shell provisioner which runs the AWS cli on the instance.
It can use the metadata service 1) to get the instance id and iam_instance_profile 2) to allow it to export it self.

To no finishing up by snapshoting the EBS and creating the AMI (which you don't want) you can exit the script with a non zero value. To differentiate this from another failure you can just before that use file provisioner with download to pass a marker file to the packer host to mark success.



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/077d6b3b-901a-4f3a-86d8-e496a8732b2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Milner

unread,
Sep 24, 2018, 9:23:12 AM9/24/18
to Packer
awesome thanks!
Reply all
Reply to author
Forward
0 new messages