Skip to content

Commit

Permalink
Add support for mac instances (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
thheinen authored Dec 4, 2022
1 parent b5c1770 commit c474342
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/kitchen/driver/aws/standard_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Aws
# rhel
# fedora
# freebsd
# macos
# ubuntu
# windows
#
Expand Down
51 changes: 51 additions & 0 deletions lib/kitchen/driver/aws/standard_platform/macos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright:: 2016-2018, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative "../standard_platform"

module Kitchen
module Driver
class Aws
class StandardPlatform
class MacOS < StandardPlatform
StandardPlatform.platforms["macos"] = self

# default username for this platform's ami
# @return [String]
def username
"ec2-user"
end

def image_search
search = {
"owner-id" => "100343932686",
"name" => version ? "amzn-ec2-macos-#{version}*" : "amzn2-ec2-macos-*",
}
search["architecture"] = architecture if architecture
search["architecture"] = "arm64_mac" if architecture == "arm64"
search
end

def self.from_image(driver, image)
if /amzn-ec2-macos/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+[\.\d])?)/i
new(driver, "macos", (Regexp.last_match || [])[1], image.architecture)
end
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
require_relative "aws/standard_platform/rhel"
require_relative "aws/standard_platform/fedora"
require_relative "aws/standard_platform/freebsd"
require_relative "aws/standard_platform/macos"
require_relative "aws/standard_platform/ubuntu"
require_relative "aws/standard_platform/windows"
require "aws-sdk-ec2"
Expand Down
10 changes: 10 additions & 0 deletions spec/kitchen/driver/aws/image_selection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ def new_instance(platform_name: "blarghle")
{ name: "architecture", values: %w{x86_64} },
],

"macos-12.5" => [
{ name: "owner-id", values: %w{100343932686} },
{ name: "name", values: %w{amzn-ec2-macos-12.5*} },
],
"macos-12.6-arm64" => [
{ name: "owner-id", values: %w{100343932686} },
{ name: "name", values: %w{amzn-ec2-macos-12.6*} },
{ name: "architecture", values: %w{arm64_mac} },
],

"ubuntu" => [
{ name: "owner-id", values: %w{099720109477} },
{ name: "name", values: %w{ubuntu/images/*/ubuntu-*-*} },
Expand Down

0 comments on commit c474342

Please sign in to comment.