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

Implementation of Atomic tagging #414

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cache: bundler
sudo: false
branches:
only:
- master
- atomic-tags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, also never do this in a FOSS project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, I was just running through travis for my local branch and forgot to revert it.

rvm:
- 2.3.7
- 2.4.4
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ The Hash of EC tag name/value pairs which will be applied to the instance.

The default is `{ "created-by" => "test-kitchen" }`.

Tags are applied post creation, if tags should be added during instance creation then set `create_instance_with_tags` to `true`

#### `user_data`

The user_data script or the path to a script to feed the instance.
Expand Down
2 changes: 1 addition & 1 deletion kitchen-ec2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
gem.add_dependency "test-kitchen", "~> 1.4", ">= 1.4.1"
gem.add_dependency "excon"
gem.add_dependency "multi_json"
gem.add_dependency "aws-sdk", "~> 2"
gem.add_dependency "aws-sdk", "~> 3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be x-ref'd with ChefDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChefDK is using ~> 2, I am going to change it back.

gem.add_dependency "retryable", "~> 2.0"

gem.add_development_dependency "rspec", "~> 3.2"
Expand Down
11 changes: 11 additions & 0 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,17 @@ def submit_server
end
instance_data[:min_count] = 1
instance_data[:max_count] = 1
if config[:create_instance_with_tags] && config[:tags] && !config[:tags].empty?
tags = config[:tags].map do |k, v|
# we convert the value to a string because
# nils should be passed as an empty String
# and Integers need to be represented as Strings
{ :key => k, :value => v.to_s }
end
instance_tag_spec = { :resource_type => "instance", :tags => tags }
volume_tag_spec = { :resource_type => "volume", :tags => tags }
instance_data[:tag_specifications] = [instance_tag_spec, volume_tag_spec]
end
ec2.create_instance(instance_data)
end

Expand Down
13 changes: 13 additions & 0 deletions spec/kitchen/driver/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,19 @@
end
end

describe "#create_instance_with_tags" do
before do
config[:create_instance_with_tags] = true
expect(driver).to receive(:instance).at_least(:once).and_return(instance)
end

it "submits the server request" do
expect(generator).to receive(:ec2_instance_data).and_return({})
expect(client).to receive(:create_instance).with(:min_count => 1, :max_count => 1, :tag_specifications => anything)
driver.submit_server
end
end

describe "#create" do
let(:server) { double("aws server object", :id => id, :image_id => "ami-3f807145") }
let(:id) { "i-12345" }
Expand Down