From 693d19a69069d974459563dc7688f29e8864e9ed Mon Sep 17 00:00:00 2001 From: Thomas Heinen Date: Sat, 3 Dec 2022 00:02:07 +0100 Subject: [PATCH] Add support for mac instances Signed-off-by: Thomas Heinen --- lib/kitchen/driver/aws/standard_platform.rb | 1 + .../driver/aws/standard_platform/macos.rb | 51 +++++++++++++++++++ lib/kitchen/driver/ec2.rb | 1 + .../driver/aws/image_selection_spec.rb | 10 ++++ 4 files changed, 63 insertions(+) create mode 100644 lib/kitchen/driver/aws/standard_platform/macos.rb diff --git a/lib/kitchen/driver/aws/standard_platform.rb b/lib/kitchen/driver/aws/standard_platform.rb index e301c960..200a3439 100644 --- a/lib/kitchen/driver/aws/standard_platform.rb +++ b/lib/kitchen/driver/aws/standard_platform.rb @@ -27,6 +27,7 @@ class Aws # rhel # fedora # freebsd + # macos # ubuntu # windows # diff --git a/lib/kitchen/driver/aws/standard_platform/macos.rb b/lib/kitchen/driver/aws/standard_platform/macos.rb new file mode 100644 index 00000000..a9d03e30 --- /dev/null +++ b/lib/kitchen/driver/aws/standard_platform/macos.rb @@ -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 diff --git a/lib/kitchen/driver/ec2.rb b/lib/kitchen/driver/ec2.rb index 4b24f6da..0b7834bd 100644 --- a/lib/kitchen/driver/ec2.rb +++ b/lib/kitchen/driver/ec2.rb @@ -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" diff --git a/spec/kitchen/driver/aws/image_selection_spec.rb b/spec/kitchen/driver/aws/image_selection_spec.rb index 3f54b456..992ace19 100644 --- a/spec/kitchen/driver/aws/image_selection_spec.rb +++ b/spec/kitchen/driver/aws/image_selection_spec.rb @@ -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-*-*} },