Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Allow package command to just take a snapshot #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ This provider exposes quite a few provider-specific configuration options:
* `tenancy` - When running in a VPC configure the tenancy of the instance. Supports 'default' and 'dedicated'.
* `tags` - A hash of tags to set on the machine.
* `package_tags` - A hash of tags to set on the ami generated during the package operation.
* `package_only_snapshot` - A boolean that indicates whether the package command should only
create an AMI snapshot and not create a vagrant box. Defaults to false.
* `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
for credentials.
* `block_device_mapping` - Amazon EC2 Block Device Mapping Property
Expand Down
44 changes: 24 additions & 20 deletions lib/vagrant-aws/action/package_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,30 @@ def call(env)
raise Errors::FogError, :message => e.message
end

# Handles inclusions from --include and --vagrantfile options
setup_package_files(env)

# Setup the temporary directory for the tarball files
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
env["export.temp_dir"] = @temp_dir
FileUtils.mkpath(env["export.temp_dir"])

# Create the Vagrantfile and metadata.json files from templates to go in the box
create_vagrantfile(env)
create_metadata_file(env)

# Just match up a couple environmental variables so that
# the superclass will do the right thing. Then, call the
# superclass to actually create the tarball (.box file)
env["package.directory"] = env["export.temp_dir"]
general_call(env)

# Always call recover to clean up the temp dir
clean_temp_dir
region=env[:machine].provider_config.region
region_config=env[:machine].provider_config.get_region_config(region)
if !region_config.package_only_snapshot
# Handles inclusions from --include and --vagrantfile options
setup_package_files(env)

# Setup the temporary directory for the tarball files
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
env["export.temp_dir"] = @temp_dir
FileUtils.mkpath(env["export.temp_dir"])

# Create the Vagrantfile and metadata.json files from templates to go in the box
create_vagrantfile(env)
create_metadata_file(env)

# Just match up a couple environmental variables so that
# the superclass will do the right thing. Then, call the
# superclass to actually create the tarball (.box file)
env["package.directory"] = env["export.temp_dir"]
general_call(env)

# Always call recover to clean up the temp dir
clean_temp_dir
end
end

protected
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-aws/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ class Config < Vagrant.plugin("2", :config)
# @return [Hash<String, String>]
attr_accessor :package_tags

# Whether to create a vagrant package or just take a snapshot when running
# the package subcommand.
#
# @return [Boolean]
attr_accessor :package_only_snapshot

# Use IAM Instance Role for authentication to AWS instead of an
# explicit access_id and secret_access_key
#
Expand Down Expand Up @@ -215,6 +221,7 @@ def initialize(region_specific=false)
@subnet_id = UNSET_VALUE
@tags = {}
@package_tags = {}
@package_only_snapshot = false
@user_data = UNSET_VALUE
@use_iam_profile = UNSET_VALUE
@block_device_mapping = []
Expand Down
1 change: 1 addition & 0 deletions spec/vagrant-aws/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
its("iam_instance_profile_name") { should be_nil }
its("tags") { should == {} }
its("package_tags") { should == {} }
its("package_only_snapshot") { should == false }
its("user_data") { should be_nil }
its("use_iam_profile") { should be false }
its("block_device_mapping") {should == [] }
Expand Down