diff --git a/lib/fog/compute/requests/aws/delete_tags.rb b/lib/fog/compute/requests/aws/delete_tags.rb index 43cf622b2..ed795d78c 100644 --- a/lib/fog/compute/requests/aws/delete_tags.rb +++ b/lib/fog/compute/requests/aws/delete_tags.rb @@ -8,8 +8,8 @@ module Fog # Remove tags from resources # # ==== Parameters - # * resources<~String> - One or more resources to tag - # * tags<~String> - hash of key value tag pairs to assign + # * resources<~String> - One or more resources to remove tags from + # * tags<~String> - hash of key value tag pairs to remove # # ==== Returns # * response<~Excon::Response>: @@ -18,15 +18,18 @@ module Fog # * 'return'<~Boolean> - success? def delete_tags(resources, tags) resources = [*resources] - for key, value in tags - if value.nil? - tags[key] = '' - end - end params = {} params.merge!(AWS.indexed_param('ResourceId', resources)) - params.merge!(AWS.indexed_param('Tag.%d.Key', tags.keys)) - params.merge!(AWS.indexed_param('Tag.%d.Value', tags.values)) + + # can not rely on indexed_param because nil values should be omitted + tags.keys.each_with_index do |key, index| + index += 1 # should start at 1 instead of 0 + params.merge!("Tag.#{index}.Key" => key) + unless tags[key].nil? + params.merge("Tag.#{index}.Value" => tags[key]) + end + end + request({ 'Action' => 'DeleteTags', :parser => Fog::Parsers::AWS::Compute::Basic.new diff --git a/tests/compute/requests/aws/tag_tests.rb b/tests/compute/requests/aws/tag_tests.rb index 444c16c30..7b9ca69c2 100644 --- a/tests/compute/requests/aws/tag_tests.rb +++ b/tests/compute/requests/aws/tag_tests.rb @@ -29,6 +29,11 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do AWS[:compute].delete_tags(@volume.identity, 'foo' => 'bar').body end + tests("#delete_tags('vol-00000000', 'baz' => 'qux')").succeeds do + pending if Fog.mocking? + AWS[:compute].delete_tags('vol-00000000', 'baz' => 'qux') + end + end tests('failure') do @@ -37,11 +42,6 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do AWS[:compute].create_tags('vol-00000000', 'baz' => 'qux') end - tests("#delete_tags('vol-00000000', 'baz' => 'qux')").raises(Fog::Service::NotFound) do - pending if Fog.mocking? - AWS[:compute].delete_tags('vol-00000000', 'baz' => 'qux') - end - end @volume.destroy