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

Add a config parameter to specify whether public IP is assigned #219

Merged
merged 1 commit into from
Apr 19, 2014
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ This provider exposes quite a few provider-specific configuration options:
* `iam_instance_profile_name` - The name of the IAM Instance Profile to associate
with the instance
* `subnet_id` - The subnet to boot the instance into, for VPC.
* `associate_public_ip` - If true, will associate a public IP address to an instance in a VPC.
* `tags` - A hash of tags to set on the machine.
* `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
for credentials.
Expand Down
5 changes: 4 additions & 1 deletion lib/vagrant-aws/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def call(env)
iam_instance_profile_name = region_config.iam_instance_profile_name
monitoring = region_config.monitoring
ebs_optimized = region_config.ebs_optimized
associate_public_ip = region_config.associate_public_ip

# If there is no keypair then warn the user
if !keypair
Expand Down Expand Up @@ -72,6 +73,7 @@ def call(env)
env[:ui].info(" -- Terminate On Shutdown: #{terminate_on_shutdown}")
env[:ui].info(" -- Monitoring: #{monitoring}")
env[:ui].info(" -- EBS optimized: #{ebs_optimized}")
env[:ui].info(" -- Assigning a public IP address in a VPC: #{associate_public_ip}")

options = {
:availability_zone => availability_zone,
Expand All @@ -87,7 +89,8 @@ def call(env)
:block_device_mapping => block_device_mapping,
:instance_initiated_shutdown_behavior => terminate_on_shutdown == true ? "terminate" : nil,
:monitoring => monitoring,
:ebs_optimized => ebs_optimized
:ebs_optimized => ebs_optimized,
:associate_public_ip => associate_public_ip
}
if !security_groups.empty?
security_group_key = options[:subnet_id].nil? ? :groups : :security_group_ids
Expand Down
13 changes: 13 additions & 0 deletions lib/vagrant-aws/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class Config < Vagrant.plugin("2", :config)
# @return [Boolean]
attr_accessor :ebs_optimized

# Assigning a public IP address in a VPC
#
# @return [Boolean]
attr_accessor :associate_public_ip

def initialize(region_specific=false)
@access_key_id = UNSET_VALUE
@ami = UNSET_VALUE
Expand All @@ -158,6 +163,7 @@ def initialize(region_specific=false)
@ssh_host_attribute = UNSET_VALUE
@monitoring = UNSET_VALUE
@ebs_optimized = UNSET_VALUE
@associate_public_ip = UNSET_VALUE

# Internal state (prefix with __ so they aren't automatically
# merged)
Expand Down Expand Up @@ -296,6 +302,9 @@ def finalize!
# default false
@ebs_optimized = false if @ebs_optimized == UNSET_VALUE

# default false
@associate_public_ip = false if @associate_public_ip == UNSET_VALUE

# Compile our region specific configurations only within
# NON-REGION-SPECIFIC configurations.
if !@__region_specific
Expand Down Expand Up @@ -338,6 +347,10 @@ def validate(machine)
config.secret_access_key.nil?
end

if config.associate_public_ip && !subnet_id
errors << I18n.t("vagrant_aws.config.subnet_id_required_with_public_ip")
end

errors << I18n.interpolate("vagrant_aws.config.ami_required", :region => @region) if config.ami.nil?
end

Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ en:
A region must be specified via "region"
secret_access_key_required: |-
A secret access key is required via "secret_access_key"
subnet_id_required_with_public_ip: |-
If you assign a public IP address to an instance in a VPC, a subnet must be specifed via "subnet_id"

errors:
fog_error: |-
Expand Down
3 changes: 2 additions & 1 deletion spec/vagrant-aws/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
its("ssh_host_attribute") { should be_nil }
its("monitoring") { should == false }
its("ebs_optimized") { should == false }
its("associate_public_ip") { should == false }
end

describe "overriding defaults" do
Expand All @@ -46,7 +47,7 @@
# and asserts the proper result comes back out.
[:access_key_id, :ami, :availability_zone, :instance_ready_timeout,
:instance_type, :keypair_name, :ssh_host_attribute, :ebs_optimized,
:region, :secret_access_key, :monitoring,
:region, :secret_access_key, :monitoring, :associate_public_ip,
:subnet_id, :tags, :elastic_ip, :terminate_on_shutdown,
:iam_instance_profile_arn, :iam_instance_profile_name,
:use_iam_profile, :user_data, :block_device_mapping].each do |attribute|
Expand Down