lib/kitchen/driver/ec2.rb in kitchen-ec2-1.1.0 vs lib/kitchen/driver/ec2.rb in kitchen-ec2-1.2.0

- old
+ new

@@ -31,10 +31,12 @@ require_relative "aws/standard_platform/ubuntu" require_relative "aws/standard_platform/windows" require "aws-sdk-core/waiters/errors" require "retryable" +Aws.eager_autoload! + module Kitchen module Driver # Amazon EC2 driver for Test Kitchen. @@ -77,13 +79,12 @@ default_config :username, nil default_config :associate_public_ip, nil default_config :interface, nil default_config :http_proxy, ENV["HTTPS_PROXY"] || ENV["HTTP_PROXY"] default_config :retry_limit, 3 + default_config :instance_initiated_shutdown_behavior, nil - required_config :aws_ssh_key_id - def initialize(*args, &block) super # AWS Ruby SDK loading isn't thread safe, so as soon as we know we're # going to use EC2, autoload it. Seems to have been fixed in Ruby 2.3+ ::Aws.eager_autoload! unless RUBY_VERSION.to_f >= 2.3 @@ -155,10 +156,16 @@ raise "#{attr} is no longer valid, please use " \ "ENV['AWS_SESSION_TOKEN'] or ~/.aws/credentials. See " \ "the README for more details" end end + validations[:instance_initiated_shutdown_behavior] = lambda do |attr, val, _driver| + unless [nil, "stop", "terminate"].include?(val) + raise "'#{val}' is an invalid value for option '#{attr}'. " \ + "Valid values are 'stop' or 'terminate'" + end + end def create(state) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength return if state[:server_id] update_username(state) @@ -508,9 +515,11 @@ # Returning the fully constructed PowerShell script to user_data Kitchen::Util.outdent!(<<-EOH) <powershell> $logfile="C:\\Program Files\\Amazon\\Ec2ConfigService\\Logs\\kitchen-ec2.log" + # Allow script execution + Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force #PS Remoting and & winrm.cmd basic config Enable-PSRemoting -Force -SkipNetworkProfileCheck & winrm.cmd set winrm/config '@{MaxTimeoutms="1800000"}' >> $logfile & winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile & winrm.cmd set winrm/config/winrs '@{MaxShellsPerUser="50"}' >> $logfile