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

add option to associate public ip with instance #42

Closed
wants to merge 5 commits into from
Closed
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
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ For specific default values, please consult [amis.json][amis_json].

## <a name="config"></a> Configuration

### <a name="config-associate-public-ip"></a> associate\_public\_ip

AWS does not automatically allocate public IP addresses for instances created
within non-default [subnets][subnet_docs]. Set this option to `true` to force
allocation of a public IP and associate it with the launched instance.

If you set this option to `false` when launching into a non-default
[subnet][subnet_docs], Test Kitchen will be unable to communicate with the
instance unless you have a VPN connection to your
[Virtual Private Cloud][vpc_docs].

The default is `true` if you have configured a [subnet_id](#config-subnet-id),
or `false` otherwise.

### <a name="config-az"></a> availability\_zone

**Required** The AWS [availability zone][region_docs] to use.
Expand Down Expand Up @@ -145,7 +159,6 @@ The place from which to derive the hostname for communicating with the instance.

The default is unset.


### <a name="config-region"></a> region

**Required** The AWS [region][region_docs] to use.
Expand Down Expand Up @@ -290,3 +303,4 @@ Apache 2.0 (see [LICENSE][license])
[kitchenci]: http://kitchen.ci/
[region_docs]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
[subnet_docs]: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
[vpc_docs]: http://docs.aws.amazon.com/AmazonVPC/latest/GettingStartedGuide/ExerciseOverview.html
10 changes: 10 additions & 0 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class Ec2 < Kitchen::Driver::SSHBase

default_config :interface, nil

default_config :associate_public_ip do |driver|
driver.default_public_ip_association
end

required_config :aws_access_key_id
required_config :aws_secret_access_key
required_config :aws_ssh_key_id
Expand Down Expand Up @@ -101,6 +105,10 @@ def default_username
amis['usernames'][instance.platform.name] || 'root'
end

def default_public_ip_association
!!config[:subnet_id]
end

private

def connection
Expand All @@ -127,6 +135,7 @@ def create_server
:key_name => config[:aws_ssh_key_id],
:subnet_id => config[:subnet_id],
:iam_instance_profile_name => config[:iam_profile_name],
:associate_public_ip => config[:associate_public_ip]
)
end

Expand All @@ -141,6 +150,7 @@ def debug_server_config
debug("ec2:key_name '#{config[:aws_ssh_key_id]}'")
debug("ec2:subnet_id '#{config[:subnet_id]}'")
debug("ec2:iam_profile_name '#{config[:iam_profile_name]}'")
debug("ec2:associate_public_ip '#{config[:associate_public_ip]}'")
end

def amis
Expand Down