Class: Kitchen::Driver::Aws::InstanceGenerator
- Inherits:
-
Object
- Object
- Kitchen::Driver::Aws::InstanceGenerator
- Defined in:
- lib/kitchen/driver/aws/instance_generator.rb
Overview
A class for encapsulating the instance payload logic
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#ec2 ⇒ Object
readonly
Returns the value of attribute ec2.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#ec2_instance_data ⇒ Object
Transform the provided config into the hash to send to AWS.
-
#initialize(config, ec2, logger) ⇒ InstanceGenerator
constructor
A new instance of InstanceGenerator.
- #prepared_user_data ⇒ Object
Constructor Details
#initialize(config, ec2, logger) ⇒ InstanceGenerator
Returns a new instance of InstanceGenerator.
34 35 36 37 38 |
# File 'lib/kitchen/driver/aws/instance_generator.rb', line 34 def initialize(config, ec2, logger) @config = config @ec2 = ec2 @logger = logger end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
32 33 34 |
# File 'lib/kitchen/driver/aws/instance_generator.rb', line 32 def config @config end |
#ec2 ⇒ Object (readonly)
Returns the value of attribute ec2.
32 33 34 |
# File 'lib/kitchen/driver/aws/instance_generator.rb', line 32 def ec2 @ec2 end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
32 33 34 |
# File 'lib/kitchen/driver/aws/instance_generator.rb', line 32 def logger @logger end |
Instance Method Details
#ec2_instance_data ⇒ Object
Transform the provided config into the hash to send to AWS. Some fields can be passed in null, others need to be ommitted if they are null
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kitchen/driver/aws/instance_generator.rb', line 42 def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize i = { :instance_type => config[:instance_type], :ebs_optimized => config[:ebs_optimized], :image_id => config[:image_id], :key_name => config[:aws_ssh_key_id], :subnet_id => config[:subnet_id], :private_ip_address => config[:private_ip_address] } availability_zone = config[:availability_zone] if availability_zone if availability_zone =~ /^[a-z]$/i availability_zone = "#{config[:region]}#{availability_zone}" end i[:placement] = { :availability_zone => availability_zone.downcase } end unless config[:block_device_mappings].nil? || config[:block_device_mappings].empty? i[:block_device_mappings] = config[:block_device_mappings] end i[:security_group_ids] = Array(config[:security_group_ids]) if config[:security_group_ids] i[:user_data] = prepared_user_data if prepared_user_data if config[:iam_profile_name] i[:iam_instance_profile] = { :name => config[:iam_profile_name] } end if !config.fetch(:associate_public_ip, nil).nil? i[:network_interfaces] = [{ :device_index => 0, :associate_public_ip_address => config[:associate_public_ip], :delete_on_termination => true }] # If specifying `:network_interfaces` in the request, you must specify # network specific configs in the network_interfaces block and not at # the top level if config[:subnet_id] i[:network_interfaces][0][:subnet_id] = i.delete(:subnet_id) end if config[:private_ip_address] i[:network_interfaces][0][:private_ip_address] = i.delete(:private_ip_address) end if config[:security_group_ids] i[:network_interfaces][0][:groups] = i.delete(:security_group_ids) end end i end |
#prepared_user_data ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kitchen/driver/aws/instance_generator.rb', line 90 def prepared_user_data # If user_data is a file reference, lets read it as such return nil if config[:user_data].nil? @user_data ||= begin if File.file?(config[:user_data]) @user_data = File.read(config[:user_data]) else @user_data = config[:user_data] end @user_data = Base64.encode64(@user_data) end end |