ec2launcher 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.1.2
2
+
3
+ * Added support for specifying an IAM Instance Profile through the environment and/or application.
4
+
1
5
  ## 1.1.1
2
6
 
3
7
  * Change to calling Bash directly in startup script, instead of running Bash in sh compatibility mode.
@@ -41,6 +41,7 @@ module EC2Launcher
41
41
  dsl_accessor :availability_zone
42
42
  dsl_accessor :basename
43
43
  dsl_accessor :inherit
44
+ dsl_accessor :iam_profile
44
45
  dsl_accessor :instance_type
45
46
  dsl_accessor :name_suffix
46
47
  dsl_accessor :subnet
@@ -157,6 +158,7 @@ module EC2Launcher
157
158
  other_server.elb.keys.each {|env_name| @elb[env_name] = other_server.elb[env_name] }
158
159
  end
159
160
 
161
+ @iam_profile = other_server.iam_profile unless other_server.iam_profile.nil?
160
162
  @instance_type = other_server.instance_type unless other_server.instance_type.nil?
161
163
  @name_suffix = other_server.name_suffix unless other_server.name_suffix.nil?
162
164
 
@@ -22,6 +22,7 @@ module EC2Launcher
22
22
  dsl_accessor :chef_validation_pem_url
23
23
  dsl_accessor :domain_name
24
24
  dsl_accessor :gem_path
25
+ dsl_accessor :iam_profile
25
26
  dsl_accessor :inherit
26
27
  dsl_accessor :key_name
27
28
  dsl_accessor :knife_path
@@ -89,6 +90,7 @@ module EC2Launcher
89
90
  @domain_name = other_env.domain_name unless other_env.domain_name.nil?
90
91
  @email_notifications = other_env.email_notifications unless other_env.email_notifications.nil?
91
92
  @gem_path = other_env.gem_path unless other_env.gem_path.nil?
93
+ @iam_profile = other_env.iam_profile unless other_env.iam_profile.nil?
92
94
  @key_name = other_env.key_name unless other_env.key_name.nil?
93
95
  @knife_path = other_env.knife_path unless other_env.knife_path.nil?
94
96
  @ruby_path = other_env.ruby_path unless other_env.ruby_path.nil?
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.1.1"
5
+ VERSION = "1.1.2"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -169,6 +169,12 @@ module EC2Launcher
169
169
  exit 3
170
170
  end
171
171
 
172
+ ##############################
173
+ # IAM PROFILE
174
+ ##############################
175
+ iam_profile = @environment.iam_profile
176
+ iam_profile ||= @application.iam_profile
177
+
172
178
  ##############################
173
179
  # INSTANCE TYPE
174
180
  ##############################
@@ -280,6 +286,7 @@ module EC2Launcher
280
286
  @log.info "Availability zone: #{availability_zone}"
281
287
  @log.info "Key name : #{key_name}"
282
288
  @log.info "Security groups : " + security_groups.collect {|name| "#{name} (#{sg_map[name].security_group_id})"}.join(", ")
289
+ @log.info "IAM profile : #{iam_profile}" if iam_profile
283
290
  @log.info "Instance type : #{instance_type}"
284
291
  @log.info "Architecture : #{instance_architecture}"
285
292
  @log.info "AMI name : #{ami.ami_name}"
@@ -339,7 +346,7 @@ module EC2Launcher
339
346
  block_device_tags = block_device_builder.generate_device_tags(fqdn_names[i], short_hostnames[i], @environment.name, @application.block_devices)
340
347
  user_data = build_launch_command(fqdn_names[i], short_hostnames[i], roles, chef_validation_pem_url, aws_keyfile, gems, packages, email_notifications)
341
348
 
342
- instance = launch_instance(fqdn_names[i], ami.ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
349
+ instance = launch_instance(fqdn_names[i], ami.ami_id, availability_zone, key_name, security_group_ids, iam_profile, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
343
350
  instances << instance
344
351
 
345
352
  public_dns_name = get_instance_dns(instance, true)
@@ -504,6 +511,7 @@ module EC2Launcher
504
511
  # @param [String] availability_zone EC2 availability zone to use
505
512
  # @param [String] key_name EC2 SSH key to use.
506
513
  # @param [Array<String>] security_group_ids list of security groups ids
514
+ # @param [String, nil] iam_profile The name or ARN of an IAM instance profile. May be nil.
507
515
  # @param [String] instance_type EC2 instance type.
508
516
  # @param [String] user_data command data to store pass to the instance in the EC2 user-data field.
509
517
  # @param [Hash<String,Hash<String, String>, nil] block_device_mappings mapping of device names to block device details.
@@ -511,32 +519,26 @@ module EC2Launcher
511
519
  # @param [Hash<String,Hash<String, String>>, nil] block_device_tags mapping of device names to hash objects with tags for the new EBS block devices.
512
520
  #
513
521
  # @return [AWS::EC2::Instance] newly created EC2 instance or nil if the launch failed.
514
- def launch_instance(hostname, ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings = nil, block_device_tags = nil, vpc_subnet = nil)
522
+ def launch_instance(hostname, ami_id, availability_zone, key_name, security_group_ids, iam_profile, instance_type, user_data, block_device_mappings = nil, block_device_tags = nil, vpc_subnet = nil)
515
523
  @log.warn "Launching instance... #{hostname}"
516
524
  new_instance = nil
517
525
  run_with_backoff(30, 1, "launching instance") do
518
- if block_device_mappings.nil? || block_device_mappings.keys.empty?
519
- new_instance = @ec2.instances.create(
526
+ launch_mapping = {
520
527
  :image_id => ami_id,
521
528
  :availability_zone => availability_zone,
522
529
  :key_name => key_name,
523
530
  :security_group_ids => security_group_ids,
524
531
  :user_data => user_data,
525
- :instance_type => instance_type,
526
- :subnet => vpc_subnet
527
- )
528
- else
529
- new_instance = @ec2.instances.create(
530
- :image_id => ami_id,
531
- :availability_zone => availability_zone,
532
- :key_name => key_name,
533
- :security_group_ids => security_group_ids,
534
- :user_data => user_data,
535
- :instance_type => instance_type,
536
- :block_device_mappings => block_device_mappings,
537
- :subnet => vpc_subnet
538
- )
532
+ :instance_type => instance_type
533
+ }
534
+ unless block_device_mappings.nil? || block_device_mappings.keys.empty?
535
+ launch_mapping[:block_device_mappings] = block_device_mappings
539
536
  end
537
+
538
+ launch_mapping[:iam_profile] = iam_profile if iam_profile
539
+ launch_mapping[:subnet] = vpc_subnet if vpc_subnet
540
+
541
+ new_instance = @ec2.instances.create(launch_mapping)
540
542
  end
541
543
  sleep 5
542
544
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -107,4 +107,3 @@ signing_key:
107
107
  specification_version: 3
108
108
  summary: Tool to launch EC2 instances.
109
109
  test_files: []
110
- has_rdoc: