chef-provisioning-aws 3.0.4 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -5
  3. data/Rakefile +15 -6
  4. data/chef-provisioning-aws.gemspec +17 -17
  5. data/lib/chef/provider/aws_auto_scaling_group.rb +5 -6
  6. data/lib/chef/provider/aws_cache_cluster.rb +21 -15
  7. data/lib/chef/provider/aws_cache_replication_group.rb +12 -8
  8. data/lib/chef/provider/aws_cache_subnet_group.rb +3 -3
  9. data/lib/chef/provider/aws_cloudsearch_domain.rb +9 -13
  10. data/lib/chef/provider/aws_cloudwatch_alarm.rb +10 -12
  11. data/lib/chef/provider/aws_dhcp_options.rb +18 -21
  12. data/lib/chef/provider/aws_ebs_volume.rb +24 -26
  13. data/lib/chef/provider/aws_eip_address.rb +10 -13
  14. data/lib/chef/provider/aws_elasticsearch_domain.rb +19 -18
  15. data/lib/chef/provider/aws_iam_instance_profile.rb +5 -7
  16. data/lib/chef/provider/aws_iam_role.rb +14 -17
  17. data/lib/chef/provider/aws_image.rb +6 -6
  18. data/lib/chef/provider/aws_instance.rb +5 -5
  19. data/lib/chef/provider/aws_internet_gateway.rb +8 -11
  20. data/lib/chef/provider/aws_key_pair.rb +15 -17
  21. data/lib/chef/provider/aws_launch_configuration.rb +11 -14
  22. data/lib/chef/provider/aws_load_balancer.rb +1 -2
  23. data/lib/chef/provider/aws_nat_gateway.rb +6 -7
  24. data/lib/chef/provider/aws_network_acl.rb +28 -29
  25. data/lib/chef/provider/aws_network_interface.rb +25 -27
  26. data/lib/chef/provider/aws_rds_instance.rb +12 -13
  27. data/lib/chef/provider/aws_rds_parameter_group.rb +8 -8
  28. data/lib/chef/provider/aws_rds_subnet_group.rb +8 -9
  29. data/lib/chef/provider/aws_route_table.rb +19 -20
  30. data/lib/chef/provider/aws_s3_bucket.rb +22 -25
  31. data/lib/chef/provider/aws_security_group.rb +268 -285
  32. data/lib/chef/provider/aws_server_certificate.rb +6 -5
  33. data/lib/chef/provider/aws_sns_topic.rb +4 -6
  34. data/lib/chef/provider/aws_sqs_queue.rb +3 -4
  35. data/lib/chef/provider/aws_subnet.rb +29 -34
  36. data/lib/chef/provider/aws_vpc.rb +108 -116
  37. data/lib/chef/provider/aws_vpc_peering_connection.rb +11 -11
  38. data/lib/chef/provisioning/aws_driver.rb +4 -2
  39. data/lib/chef/provisioning/aws_driver/aws_provider.rb +234 -241
  40. data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +5 -7
  41. data/lib/chef/provisioning/aws_driver/aws_resource.rb +182 -185
  42. data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +17 -17
  43. data/lib/chef/provisioning/aws_driver/aws_taggable.rb +13 -15
  44. data/lib/chef/provisioning/aws_driver/aws_tagger.rb +47 -48
  45. data/lib/chef/provisioning/aws_driver/credentials.rb +96 -100
  46. data/lib/chef/provisioning/aws_driver/credentials2.rb +42 -45
  47. data/lib/chef/provisioning/aws_driver/driver.rb +1349 -1362
  48. data/lib/chef/provisioning/aws_driver/exceptions.rb +10 -12
  49. data/lib/chef/provisioning/aws_driver/super_lwrp.rb +60 -60
  50. data/lib/chef/provisioning/aws_driver/tagging_strategy/auto_scaling.rb +49 -50
  51. data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +37 -38
  52. data/lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb +14 -15
  53. data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +29 -31
  54. data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +39 -40
  55. data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -43
  56. data/lib/chef/provisioning/aws_driver/version.rb +5 -5
  57. data/lib/chef/provisioning/driver_init/aws.rb +2 -2
  58. data/lib/chef/resource/aws_auto_scaling_group.rb +1 -1
  59. data/lib/chef/resource/aws_cache_cluster.rb +9 -12
  60. data/lib/chef/resource/aws_cache_replication_group.rb +9 -11
  61. data/lib/chef/resource/aws_cache_subnet_group.rb +8 -10
  62. data/lib/chef/resource/aws_cloudsearch_domain.rb +4 -5
  63. data/lib/chef/resource/aws_cloudwatch_alarm.rb +17 -18
  64. data/lib/chef/resource/aws_dhcp_options.rb +2 -2
  65. data/lib/chef/resource/aws_ebs_volume.rb +10 -10
  66. data/lib/chef/resource/aws_eip_address.rb +5 -5
  67. data/lib/chef/resource/aws_elasticsearch_domain.rb +4 -4
  68. data/lib/chef/resource/aws_iam_instance_profile.rb +4 -5
  69. data/lib/chef/resource/aws_iam_role.rb +2 -3
  70. data/lib/chef/resource/aws_image.rb +3 -3
  71. data/lib/chef/resource/aws_instance.rb +4 -4
  72. data/lib/chef/resource/aws_internet_gateway.rb +3 -3
  73. data/lib/chef/resource/aws_key_pair.rb +7 -7
  74. data/lib/chef/resource/aws_launch_configuration.rb +4 -4
  75. data/lib/chef/resource/aws_load_balancer.rb +7 -7
  76. data/lib/chef/resource/aws_nat_gateway.rb +11 -11
  77. data/lib/chef/resource/aws_network_acl.rb +7 -8
  78. data/lib/chef/resource/aws_network_interface.rb +9 -9
  79. data/lib/chef/resource/aws_rds_instance.rb +4 -4
  80. data/lib/chef/resource/aws_rds_parameter_group.rb +3 -3
  81. data/lib/chef/resource/aws_rds_subnet_group.rb +4 -4
  82. data/lib/chef/resource/aws_route53_hosted_zone.rb +37 -40
  83. data/lib/chef/resource/aws_route53_record_set.rb +22 -24
  84. data/lib/chef/resource/aws_route_table.rb +7 -7
  85. data/lib/chef/resource/aws_s3_bucket.rb +7 -7
  86. data/lib/chef/resource/aws_security_group.rb +10 -10
  87. data/lib/chef/resource/aws_server_certificate.rb +6 -8
  88. data/lib/chef/resource/aws_sns_topic.rb +2 -2
  89. data/lib/chef/resource/aws_sqs_queue.rb +5 -7
  90. data/lib/chef/resource/aws_subnet.rb +9 -9
  91. data/lib/chef/resource/aws_vpc.rb +11 -11
  92. data/lib/chef/resource/aws_vpc_peering_connection.rb +4 -4
  93. data/spec/aws_support.rb +44 -45
  94. data/spec/aws_support/aws_resource_run_wrapper.rb +2 -2
  95. data/spec/aws_support/deep_matcher.rb +2 -3
  96. data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +6 -9
  97. data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +30 -37
  98. data/spec/aws_support/deep_matcher/matchable_array.rb +0 -1
  99. data/spec/aws_support/deep_matcher/matchable_object.rb +1 -2
  100. data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +4 -4
  101. data/spec/aws_support/delayed_stream.rb +2 -2
  102. data/spec/aws_support/matchers/create_an_aws_object.rb +6 -6
  103. data/spec/aws_support/matchers/destroy_an_aws_object.rb +6 -6
  104. data/spec/aws_support/matchers/have_aws_object_tags.rb +4 -5
  105. data/spec/aws_support/matchers/match_an_aws_object.rb +5 -6
  106. data/spec/aws_support/matchers/update_an_aws_object.rb +6 -7
  107. data/spec/integration/aws_auto_scaling_group_spec.rb +56 -64
  108. data/spec/integration/aws_cache_cluster_spec.rb +70 -71
  109. data/spec/integration/aws_cache_subnet_group_spec.rb +13 -14
  110. data/spec/integration/aws_cloudsearch_domain_spec.rb +6 -8
  111. data/spec/integration/aws_cloudwatch_alarm_spec.rb +200 -208
  112. data/spec/integration/aws_dhcp_options_spec.rb +32 -43
  113. data/spec/integration/aws_ebs_volume_spec.rb +52 -73
  114. data/spec/integration/aws_eip_address_spec.rb +24 -31
  115. data/spec/integration/aws_elasticsearch_domain_spec.rb +31 -33
  116. data/spec/integration/aws_iam_instance_profile_spec.rb +36 -45
  117. data/spec/integration/aws_iam_role_spec.rb +39 -46
  118. data/spec/integration/aws_internet_gateway_spec.rb +64 -75
  119. data/spec/integration/aws_key_pair_spec.rb +6 -6
  120. data/spec/integration/aws_launch_configuration_spec.rb +17 -18
  121. data/spec/integration/aws_nat_gateway_spec.rb +21 -24
  122. data/spec/integration/aws_network_acl_spec.rb +81 -95
  123. data/spec/integration/aws_network_interface_spec.rb +28 -43
  124. data/spec/integration/aws_rds_instance_spec.rb +29 -40
  125. data/spec/integration/aws_rds_parameter_group_spec.rb +32 -35
  126. data/spec/integration/aws_rds_subnet_group_spec.rb +30 -40
  127. data/spec/integration/aws_route53_hosted_zone_spec.rb +205 -205
  128. data/spec/integration/aws_route_table_spec.rb +118 -136
  129. data/spec/integration/aws_s3_bucket_spec.rb +19 -27
  130. data/spec/integration/aws_security_group_spec.rb +369 -388
  131. data/spec/integration/aws_server_certificate_spec.rb +16 -18
  132. data/spec/integration/aws_subnet_spec.rb +44 -58
  133. data/spec/integration/aws_vpc_peering_connection_spec.rb +43 -50
  134. data/spec/integration/aws_vpc_spec.rb +99 -115
  135. data/spec/integration/load_balancer_spec.rb +169 -183
  136. data/spec/integration/machine_batch_spec.rb +24 -31
  137. data/spec/integration/machine_image_spec.rb +54 -66
  138. data/spec/integration/machine_spec.rb +216 -237
  139. data/spec/persistence_file.txt +219 -0
  140. data/spec/spec_helper.rb +16 -17
  141. data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +67 -74
  142. data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +29 -29
  143. data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +13 -15
  144. metadata +4 -3
@@ -1,11 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Chef::Resource::MachineBatch do
4
4
  extend AWSSupport
5
5
 
6
- when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
6
+ when_the_chef_12_server "exists", organization: "foo", server_scope: :context do
7
7
  with_aws "with a VPC and a public subnet" do
8
-
9
8
  before :all do
10
9
  chef_config[:log_level] = :warn
11
10
  end
@@ -14,62 +13,56 @@ describe Chef::Resource::MachineBatch do
14
13
  setup_public_vpc
15
14
 
16
15
  azs = []
17
- driver.ec2.availability_zones.each {|az| azs << az }
16
+ driver.ec2.availability_zones.each { |az| azs << az }
18
17
  az = azs[1].name
19
- aws_subnet 'test_subnet2' do
20
- vpc 'test_vpc'
21
- cidr_block '10.0.1.0/24'
18
+ aws_subnet "test_subnet2" do
19
+ vpc "test_vpc"
20
+ cidr_block "10.0.1.0/24"
22
21
  availability_zone az
23
22
  map_public_ip_on_launch true
24
23
  end
25
24
 
26
25
  it "machine_batch creates multiple machines", :super_slow do
27
- expect_recipe {
28
- machine_batch 'test_machines' do
26
+ expect_recipe do
27
+ machine_batch "test_machines" do
29
28
  action :allocate
30
29
  (1..3).each do |i|
31
30
  machine "test_machine#{i}" do
32
31
  machine_options bootstrap_options: {
33
- subnet_id: 'test_public_subnet',
34
- key_name: 'test_key_pair'
32
+ subnet_id: "test_public_subnet",
33
+ key_name: "test_key_pair"
35
34
  }, source_dest_check: false
36
35
  end
37
36
  end
38
37
  action :allocate
39
38
  end
40
- }.to create_an_aws_instance('test_machine1',
41
- source_dest_check: false
42
- ).and create_an_aws_instance('test_machine2',
43
- source_dest_check: false
44
- ).and create_an_aws_instance('test_machine3',
45
- source_dest_check: false
46
- ).and be_idempotent
39
+ end.to create_an_aws_instance("test_machine1",
40
+ source_dest_check: false).and create_an_aws_instance("test_machine2",
41
+ source_dest_check: false).and create_an_aws_instance("test_machine3",
42
+ source_dest_check: false).and be_idempotent
47
43
  end
48
44
 
49
45
  it "machine_batch supports runtime machine_options", :super_slow do
50
- expect_recipe {
51
- subnets = %w(test_public_subnet test_subnet2)
46
+ expect_recipe do
47
+ subnets = %w{test_public_subnet test_subnet2}
52
48
 
53
- machine_batch 'test_machines' do
49
+ machine_batch "test_machines" do
54
50
  action :allocate
55
51
  (1..2).each do |i|
56
52
  machine "test_machine#{i}" do
57
53
  machine_options bootstrap_options: {
58
- subnet_id: subnets[i-1],
59
- key_name: 'test_key_pair'
54
+ subnet_id: subnets[i - 1],
55
+ key_name: "test_key_pair"
60
56
  }, source_dest_check: (i == 1)
61
57
  end
62
58
  end
63
59
  end
64
- }.to create_an_aws_instance('test_machine1',
65
- subnet_id: test_public_subnet.aws_object.id,
66
- source_dest_check: true
67
- ).and create_an_aws_instance('test_machine2',
68
- subnet_id: test_subnet2.aws_object.id,
69
- source_dest_check: false
70
- ).and be_idempotent
60
+ end.to create_an_aws_instance("test_machine1",
61
+ subnet_id: test_public_subnet.aws_object.id,
62
+ source_dest_check: true).and create_an_aws_instance("test_machine2",
63
+ subnet_id: test_subnet2.aws_object.id,
64
+ source_dest_check: false).and be_idempotent
71
65
  end
72
66
  end
73
-
74
67
  end
75
68
  end
@@ -1,9 +1,9 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Chef::Resource::MachineImage do
4
4
  extend AWSSupport
5
5
 
6
- when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
6
+ when_the_chef_12_server "exists", organization: "foo", server_scope: :context do
7
7
  with_aws "with a VPC and a public subnet" do
8
8
  before :all do
9
9
  chef_config[:log_level] = :warn
@@ -16,117 +16,105 @@ describe Chef::Resource::MachineImage do
16
16
  setup_public_vpc
17
17
 
18
18
  it "machine_image can create an image in the VPC", :super_slow do
19
- expect_recipe {
20
- machine_image 'test_machine_image' do
19
+ expect_recipe do
20
+ machine_image "test_machine_image" do
21
21
  machine_options bootstrap_options: {
22
- subnet_id: 'test_public_subnet',
23
- key_name: 'test_key_pair',
24
- instance_type: 'm3.medium'
22
+ subnet_id: "test_public_subnet",
23
+ key_name: "test_key_pair",
24
+ instance_type: "m3.medium"
25
25
  },
26
- ssh_options: {
27
- timeout: 60
28
- }
26
+ ssh_options: {
27
+ timeout: 60
28
+ }
29
29
  end
30
- }.to create_an_aws_image('test_machine_image',
31
- name: 'test_machine_image'
32
- ).and be_idempotent
30
+ end.to create_an_aws_image("test_machine_image",
31
+ name: "test_machine_image").and be_idempotent
33
32
  end
34
33
 
35
- describe 'action :destroy', :super_slow do
34
+ describe "action :destroy", :super_slow do
36
35
  # with_converge does a before(:each)
37
- with_converge {
38
- machine_image 'test_machine_image' do
36
+ with_converge do
37
+ machine_image "test_machine_image" do
39
38
  machine_options bootstrap_options: {
40
- subnet_id: 'test_public_subnet',
41
- key_name: 'test_key_pair',
42
- instance_type: 'm3.medium'
39
+ subnet_id: "test_public_subnet",
40
+ key_name: "test_key_pair",
41
+ instance_type: "m3.medium"
43
42
  },
44
- ssh_options: {
45
- timeout: 60
46
- }
43
+ ssh_options: {
44
+ timeout: 60
45
+ }
47
46
  end
48
- }
47
+ end
49
48
 
50
49
  it "destroys the image" do
51
- r = recipe {
50
+ r = recipe do
52
51
  machine_image "test_machine_image" do
53
52
  action :destroy
54
53
  end
55
- }
56
- expect(r).to destroy_an_aws_image('test_machine_image'
57
- ).and be_idempotent
54
+ end
55
+ expect(r).to destroy_an_aws_image("test_machine_image").and be_idempotent
58
56
  end
59
57
 
60
58
  it "destroys the image if instance is gone long time ago" do
61
- image = driver.ec2_resource.images({filters: [ { name: "name", values: ["test_machine_image"] }]}).first
62
- image.create_tags(tags: [{key: "from-instance", value: "i-12345678"}])
59
+ image = driver.ec2_resource.images(filters: [{ name: "name", values: ["test_machine_image"] }]).first
60
+ image.create_tags(tags: [{ key: "from-instance", value: "i-12345678" }])
63
61
 
64
- r = recipe {
62
+ r = recipe do
65
63
  machine_image "test_machine_image" do
66
64
  action :destroy
67
65
  end
68
- }
69
- expect(r).to destroy_an_aws_image('test_machine_image'
70
- ).and be_idempotent
66
+ end
67
+ expect(r).to destroy_an_aws_image("test_machine_image").and be_idempotent
71
68
  end
72
69
  end
73
70
 
74
71
  it "creates aws_image tags", :super_slow do
75
- expect_recipe {
76
- machine_image 'test_machine_image' do
72
+ expect_recipe do
73
+ machine_image "test_machine_image" do
77
74
  machine_options bootstrap_options: {
78
- key_name: 'test_key_pair',
79
- instance_type: 'm3.medium'
75
+ key_name: "test_key_pair",
76
+ instance_type: "m3.medium"
80
77
  },
81
- ssh_options: {
82
- timeout: 60
83
- }
78
+ ssh_options: {
79
+ timeout: 60
80
+ }
84
81
  aws_tags key1: "value"
85
82
  end
86
- }.to create_an_aws_image('test_machine_image'
87
- ).and have_aws_image_tags('test_machine_image',
88
- {
89
- 'key1' => 'value'
90
- }
91
- ).and be_idempotent
83
+ end.to create_an_aws_image("test_machine_image").and have_aws_image_tags("test_machine_image",
84
+ "key1" => "value").and be_idempotent
92
85
  end
93
86
 
94
87
  context "with existing tags" do
95
- machine_image 'test_machine_image' do
88
+ machine_image "test_machine_image" do
96
89
  machine_options bootstrap_options: {
97
- key_name: 'test_key_pair',
98
- instance_type: 'm3.medium'
90
+ key_name: "test_key_pair",
91
+ instance_type: "m3.medium"
99
92
  },
100
- ssh_options: {
101
- timeout: 60
102
- }
93
+ ssh_options: {
94
+ timeout: 60
95
+ }
103
96
  aws_tags key1: "value"
104
97
  end
105
98
 
106
99
  it "updates aws_image tags", :super_slow do
107
- expect_recipe {
108
- machine_image 'test_machine_image' do
100
+ expect_recipe do
101
+ machine_image "test_machine_image" do
109
102
  aws_tags key1: "value2", key2: nil
110
103
  end
111
- }.to have_aws_image_tags('test_machine_image',
112
- {
113
- 'key1' => 'value2',
114
- 'key2' => ''
115
- }
116
- ).and be_idempotent
104
+ end.to have_aws_image_tags("test_machine_image",
105
+ "key1" => "value2",
106
+ "key2" => "").and be_idempotent
117
107
  end
118
108
 
119
109
  it "removes all aws_image tags", :super_slow do
120
- expect_recipe {
121
- machine_image 'test_machine_image' do
110
+ expect_recipe do
111
+ machine_image "test_machine_image" do
122
112
  aws_tags({})
123
113
  end
124
- }.to have_aws_image_tags('test_machine_image',
125
- {}
126
- ).and be_idempotent
114
+ end.to have_aws_image_tags("test_machine_image",
115
+ {}).and be_idempotent
127
116
  end
128
117
  end
129
-
130
118
  end
131
119
  end
132
120
  end
@@ -1,12 +1,11 @@
1
- require 'spec_helper'
2
- require 'openssl'
1
+ require "spec_helper"
2
+ require "openssl"
3
3
 
4
4
  describe Chef::Resource::Machine do
5
5
  extend AWSSupport
6
6
 
7
- when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ when_the_chef_12_server "exists", organization: "foo", server_scope: :context do
8
8
  with_aws "with a VPC and a public subnet" do
9
-
10
9
  before :all do
11
10
  chef_config[:log_level] = :warn
12
11
  end
@@ -15,34 +14,32 @@ describe Chef::Resource::Machine do
15
14
  setup_public_vpc
16
15
 
17
16
  it "machine with no options creates an machine", :super_slow do
18
- expect_recipe {
19
- machine 'test_machine' do
17
+ expect_recipe do
18
+ machine "test_machine" do
20
19
  action :allocate
21
20
  end
22
- }.to create_an_aws_instance('test_machine'
23
- ).and be_idempotent
21
+ end.to create_an_aws_instance("test_machine").and be_idempotent
24
22
  end
25
23
 
26
24
  it "machine with few options allocates a machine", :super_slow do
27
- expect_recipe {
28
- machine 'test_machine' do
25
+ expect_recipe do
26
+ machine "test_machine" do
29
27
  machine_options bootstrap_options: {
30
- subnet_id: 'test_public_subnet',
31
- key_name: 'test_key_pair'
28
+ subnet_id: "test_public_subnet",
29
+ key_name: "test_key_pair"
32
30
  }
33
31
  action :allocate
34
32
  end
35
- }.to create_an_aws_instance('test_machine'
36
- ).and be_idempotent
33
+ end.to create_an_aws_instance("test_machine").and be_idempotent
37
34
  end
38
35
 
39
36
  it "machine with options specified as node options allocates a machine", :super_slow do
40
- expect_recipe {
41
- machine 'test_machine' do
42
- node.default['aws_options'] = {
37
+ expect_recipe do
38
+ machine "test_machine" do
39
+ node.default["aws_options"] = {
43
40
  bootstrap_options: {
44
- key_name: 'test_key_pair',
45
- instance_type: 'm3.medium',
41
+ key_name: "test_key_pair",
42
+ instance_type: "m3.medium",
46
43
  # Need an array of hashes to test out a bug fix
47
44
  network_interfaces: [
48
45
  {
@@ -51,104 +48,99 @@ describe Chef::Resource::Machine do
51
48
  device_index: 0,
52
49
  subnet_id: test_public_subnet.aws_object.id,
53
50
  delete_on_termination: true,
54
- groups: [test_security_group.aws_object.id],
51
+ groups: [test_security_group.aws_object.id]
55
52
  }
56
53
  ]
57
54
  }
58
55
  }
59
- machine_options node['aws_options']
56
+ machine_options node["aws_options"]
60
57
  action :allocate
61
58
  end
62
- }.to create_an_aws_instance('test_machine'
63
- ).and be_idempotent
59
+ end.to create_an_aws_instance("test_machine").and be_idempotent
64
60
  end
65
61
 
66
62
  it "machine with few options converges a machine", :super_slow do
67
- expect_recipe {
68
- machine 'test_machine' do
63
+ expect_recipe do
64
+ machine "test_machine" do
69
65
  machine_options bootstrap_options: {
70
- subnet_id: 'test_public_subnet',
71
- key_name: 'test_key_pair'
66
+ subnet_id: "test_public_subnet",
67
+ key_name: "test_key_pair"
72
68
  },
73
- convergence_options: {
74
- chef_version: "12.5.1"
75
- }
69
+ convergence_options: {
70
+ chef_version: "12.5.1"
71
+ }
76
72
  end
77
- }.to create_an_aws_instance('test_machine'
78
- )#.and be_idempotent
73
+ end.to create_an_aws_instance("test_machine") # .and be_idempotent
79
74
  # Bug - machine resource with :converge action isn't idempotent
80
75
  # The non-idempotence is that it runs chef again, not that it unecessarily modifies the aws_object
81
76
  end
82
77
 
83
78
  it "successfully converges a machine with custom ssh options", :super_slow do
84
- expect_recipe {
85
- machine 'test_machine' do
79
+ expect_recipe do
80
+ machine "test_machine" do
86
81
  machine_options bootstrap_options: {
87
- subnet_id: 'test_public_subnet',
88
- key_name: 'test_key_pair'
82
+ subnet_id: "test_public_subnet",
83
+ key_name: "test_key_pair"
89
84
  },
90
- ssh_username: "ubuntu", # Username to use for ssh and WinRM
91
- ssh_options: { # a list of options to Net::SSH.start
92
- :auth_methods => [ 'publickey' ], # DEFAULT
93
- :keys_only => true, # DEFAULT
94
- :forward_agent => true, # you may want your ssh-agent to be available on your provisioned machines
95
- :remote_forwards => [
96
- # Give remote host access to private git server
97
- {:remote_port => 2222, :local_host => 'git.example.com', :local_port => 22,},
98
- ],
99
- # You can send net-ssh log info to the Chef::Log if you are having
100
- # trouble with ssh.
101
- :logger => Chef::Log,
102
- }
85
+ ssh_username: "ubuntu", # Username to use for ssh and WinRM
86
+ ssh_options: { # a list of options to Net::SSH.start
87
+ auth_methods: ["publickey"], # DEFAULT
88
+ keys_only: true, # DEFAULT
89
+ forward_agent: true, # you may want your ssh-agent to be available on your provisioned machines
90
+ remote_forwards: [
91
+ # Give remote host access to private git server
92
+ { remote_port: 2222, local_host: "git.example.com", local_port: 22 }
93
+ ],
94
+ # You can send net-ssh log info to the Chef::Log if you are having
95
+ # trouble with ssh.
96
+ logger: Chef::Log
97
+ }
103
98
  end
104
- }.to create_an_aws_instance('test_machine'
105
- )#.and be_idempotent
99
+ end.to create_an_aws_instance("test_machine") # .and be_idempotent
106
100
  # Bug - machine resource with :converge action isn't idempotent
107
101
  # The non-idempotence is that it runs chef again, not that it unecessarily modifies the aws_object
108
102
  end
109
103
 
110
104
  it "machine with source_dest_check false creates a machine with no source dest check", :super_slow do
111
- expect_recipe {
112
- machine 'test_machine' do
105
+ expect_recipe do
106
+ machine "test_machine" do
113
107
  machine_options bootstrap_options: {
114
- subnet_id: 'test_public_subnet',
115
- key_name: 'test_key_pair'
108
+ subnet_id: "test_public_subnet",
109
+ key_name: "test_key_pair"
116
110
  }, source_dest_check: false
117
111
  action :allocate
118
112
  end
119
- }.to create_an_aws_instance('test_machine',
120
- source_dest_check: false
121
- ).and be_idempotent
113
+ end.to create_an_aws_instance("test_machine",
114
+ source_dest_check: false).and be_idempotent
122
115
  end
123
116
 
124
117
  it "base64 encodes the user data", :super_slow do
125
118
  uniq = Random.rand(100)
126
- expect_recipe {
119
+ expect_recipe do
127
120
  machine "test_machine_#{uniq}" do
128
121
  machine_options bootstrap_options: {
129
- subnet_id: 'test_public_subnet',
130
- key_name: 'test_key_pair',
131
- user_data: 'echo \'foo\''
122
+ subnet_id: "test_public_subnet",
123
+ key_name: "test_key_pair",
124
+ user_data: "echo 'foo'"
132
125
  }
133
126
  action :allocate
134
127
  end
135
- }.to create_an_aws_instance("test_machine_#{uniq}"
136
- ).and be_idempotent
128
+ end.to create_an_aws_instance("test_machine_#{uniq}").and be_idempotent
137
129
  expect(
138
130
  driver.ec2_client.describe_instance_attribute(
139
- instance_id: driver.ec2_resource.instances(filters: [{name: "tag:Name", values:["test_machine_#{uniq}"]}]).first.id,
131
+ instance_id: driver.ec2_resource.instances(filters: [{ name: "tag:Name", values: ["test_machine_#{uniq}"] }]).first.id,
140
132
  attribute: "userData"
141
133
  ).user_data.value
142
134
  ).to eq("ZWNobyAnZm9vJw==\n")
143
135
  end
144
136
 
145
137
  it "respects the network_interfaces block with maximum attributes", :super_slow do
146
- private_ip_address_start = Random.rand(30)+10
147
- expect_recipe {
138
+ private_ip_address_start = Random.rand(10..39)
139
+ expect_recipe do
148
140
  machine "test_machine" do
149
141
  machine_options bootstrap_options: {
150
- key_name: 'test_key_pair',
151
- instance_type: 'm3.medium',
142
+ key_name: "test_key_pair",
143
+ instance_type: "m3.medium",
152
144
  network_interfaces: [
153
145
  {
154
146
  # Cannot set associate_public_ip_address and network_interface_id
@@ -161,65 +153,64 @@ describe Chef::Resource::Machine do
161
153
  groups: [test_security_group.aws_object.id],
162
154
  private_ip_addresses: [
163
155
  {
164
- private_ip_address: "10.0.0.#{private_ip_address_start+1}",
156
+ private_ip_address: "10.0.0.#{private_ip_address_start + 1}",
165
157
  primary: false
166
158
  },
167
159
  {
168
- private_ip_address: "10.0.0.#{private_ip_address_start+2}",
160
+ private_ip_address: "10.0.0.#{private_ip_address_start + 2}",
169
161
  primary: false
170
162
  }
171
163
  ],
172
164
  # cannot specify both `private_ip_addresses` and `secondary_private_ip_address_count`
173
- #secondary_private_ip_address_count: 2,
165
+ # secondary_private_ip_address_count: 2,
174
166
  associate_public_ip_address: true
175
167
  }
176
168
  ]
177
169
  }
178
170
  action :ready
179
171
  end
180
- }.to create_an_aws_instance("test_machine",
181
- network_interfaces: [{
182
- network_interface_id: /^eni-/,
183
- subnet_id: test_public_subnet.aws_object.id,
184
- vpc_id: test_vpc.aws_object.id,
185
- description: "network interface description",
186
- status: "in-use",
187
- private_ip_address: "10.0.0.#{private_ip_address_start}",
188
- groups: [{group_name: 'test_security_group'}],
189
- attachment: {
190
- device_index: 0,
191
- delete_on_termination: true,
192
- status: "attached"
193
- },
194
- private_ip_addresses: [
195
- {
196
- private_ip_address: "10.0.0.#{private_ip_address_start}",
197
- primary: true,
198
- # the action must be :ready to give the public ip time to be assigned
199
- association: {
200
- public_ip: /\d+/
201
- }
202
- },
203
- {
204
- private_ip_address: "10.0.0.#{private_ip_address_start+1}",
205
- primary: false
206
- },
207
- {
208
- private_ip_address: "10.0.0.#{private_ip_address_start+2}",
209
- primary: false
210
- }
211
- ]
212
- }]
213
- ).and be_idempotent
172
+ end.to create_an_aws_instance("test_machine",
173
+ network_interfaces: [{
174
+ network_interface_id: /^eni-/,
175
+ subnet_id: test_public_subnet.aws_object.id,
176
+ vpc_id: test_vpc.aws_object.id,
177
+ description: "network interface description",
178
+ status: "in-use",
179
+ private_ip_address: "10.0.0.#{private_ip_address_start}",
180
+ groups: [{ group_name: "test_security_group" }],
181
+ attachment: {
182
+ device_index: 0,
183
+ delete_on_termination: true,
184
+ status: "attached"
185
+ },
186
+ private_ip_addresses: [
187
+ {
188
+ private_ip_address: "10.0.0.#{private_ip_address_start}",
189
+ primary: true,
190
+ # the action must be :ready to give the public ip time to be assigned
191
+ association: {
192
+ public_ip: /\d+/
193
+ }
194
+ },
195
+ {
196
+ private_ip_address: "10.0.0.#{private_ip_address_start + 1}",
197
+ primary: false
198
+ },
199
+ {
200
+ private_ip_address: "10.0.0.#{private_ip_address_start + 2}",
201
+ primary: false
202
+ }
203
+ ]
204
+ }]).and be_idempotent
214
205
  end
215
206
 
216
207
  it "converts associate_public_ip_address at the top level to the network interface", :super_slow do
217
- private_ip_address_start = Random.rand(30)+10
218
- expect_recipe {
208
+ private_ip_address_start = Random.rand(10..39)
209
+ expect_recipe do
219
210
  machine "test_machine" do
220
211
  machine_options bootstrap_options: {
221
- key_name: 'test_key_pair',
222
- instance_type: 'm3.medium',
212
+ key_name: "test_key_pair",
213
+ instance_type: "m3.medium",
223
214
  associate_public_ip_address: true,
224
215
  subnet_id: test_public_subnet.aws_object.id,
225
216
  security_group_ids: [test_security_group.aws_object.id],
@@ -227,74 +218,72 @@ describe Chef::Resource::Machine do
227
218
  }
228
219
  action :ready
229
220
  end
230
- }.to create_an_aws_instance("test_machine",
231
- network_interfaces: [{
232
- network_interface_id: /^eni-/,
233
- subnet_id: test_public_subnet.aws_object.id,
234
- vpc_id: test_vpc.aws_object.id,
235
- status: "in-use",
236
- private_ip_address: "10.0.0.#{private_ip_address_start}",
237
- groups: [{group_name: 'test_security_group'}],
238
- attachment: {
239
- device_index: 0,
240
- delete_on_termination: true,
241
- status: "attached"
242
- },
243
- private_ip_addresses: [
244
- {
245
- private_ip_address: "10.0.0.#{private_ip_address_start}",
246
- primary: true,
247
- association: {
248
- public_ip: /\d+/
249
- }
250
- }
251
- ]
252
- }]
253
- ).and be_idempotent
221
+ end.to create_an_aws_instance("test_machine",
222
+ network_interfaces: [{
223
+ network_interface_id: /^eni-/,
224
+ subnet_id: test_public_subnet.aws_object.id,
225
+ vpc_id: test_vpc.aws_object.id,
226
+ status: "in-use",
227
+ private_ip_address: "10.0.0.#{private_ip_address_start}",
228
+ groups: [{ group_name: "test_security_group" }],
229
+ attachment: {
230
+ device_index: 0,
231
+ delete_on_termination: true,
232
+ status: "attached"
233
+ },
234
+ private_ip_addresses: [
235
+ {
236
+ private_ip_address: "10.0.0.#{private_ip_address_start}",
237
+ primary: true,
238
+ association: {
239
+ public_ip: /\d+/
240
+ }
241
+ }
242
+ ]
243
+ }]).and be_idempotent
254
244
  end
255
245
 
256
246
  context "with a placement group" do
257
- before(:context) {
247
+ before(:context) do
258
248
  begin
259
- driver.ec2_client.create_placement_group({
249
+ driver.ec2_client.create_placement_group(
260
250
  group_name: "agroup",
261
251
  strategy: "cluster"
262
- })
252
+ )
263
253
  rescue ::Aws::EC2::Errors::InvalidPlacementGroupDuplicate
264
254
  # We don't need to create it because it already exists
265
255
  end
266
- }
256
+ end
267
257
 
268
258
  # Must do after the context so we have waited for the instance to terminate
269
- after(:context) {
259
+ after(:context) do
270
260
  driver.ec2_client.delete_placement_group group_name: "agroup"
271
- }
261
+ end
272
262
 
273
263
  it "converts V1 keys to V2 keys", :super_slow do
274
- expect_recipe {
264
+ expect_recipe do
275
265
  machine "test_machine" do
276
266
  machine_options bootstrap_options: {
277
- key_name: 'test_key_pair',
278
- instance_type: 'm4.large',
267
+ key_name: "test_key_pair",
268
+ instance_type: "m4.large",
279
269
  monitoring_enabled: false,
280
270
  availability_zone: test_public_subnet.aws_object.availability_zone_name,
281
271
  placement_group: "agroup",
282
272
  dedicated_tenancy: false, # cannot do true, was getting API error
283
- subnet: 'test_public_subnet'
273
+ subnet: "test_public_subnet"
284
274
  }
285
275
  action :allocate
286
276
  end
287
- }.to create_an_aws_instance("test_machine",
288
- monitoring: {state: "disabled"},
289
- placement: {
290
- availability_zone: test_public_subnet.aws_object.availability_zone_name,
291
- group_name: "agroup",
292
- tenancy: "default",
293
- },
294
- subnet_id: test_public_subnet.aws_object.id
295
- ).and be_idempotent
277
+ end.to create_an_aws_instance("test_machine",
278
+ monitoring: { state: "disabled" },
279
+ placement: {
280
+ availability_zone: test_public_subnet.aws_object.availability_zone_name,
281
+ group_name: "agroup",
282
+ tenancy: "default"
283
+ },
284
+ subnet_id: test_public_subnet.aws_object.id).and be_idempotent
296
285
  end
297
- end
286
+ end
298
287
 
299
288
  context "with a custom iam role" do
300
289
  assume_role_policy_document = '{"Version":"2008-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}'
@@ -309,181 +298,173 @@ describe Chef::Resource::Machine do
309
298
  end
310
299
 
311
300
  it "converts iam_instance_profile from a string to a hash", :super_slow do
312
- expect_recipe {
313
- machine 'test_machine' do
301
+ expect_recipe do
302
+ machine "test_machine" do
314
303
  machine_options bootstrap_options: {
315
- subnet_id: 'test_public_subnet',
316
- key_name: 'test_key_pair',
304
+ subnet_id: "test_public_subnet",
305
+ key_name: "test_key_pair",
317
306
  iam_instance_profile: "machine_test_instance_profile"
318
307
  }
319
308
  action :allocate
320
309
  end
321
- }.to create_an_aws_instance('test_machine',
322
- iam_instance_profile: {arn: /machine_test_instance_profile/}
323
- ).and be_idempotent
310
+ end.to create_an_aws_instance("test_machine",
311
+ iam_instance_profile: { arn: /machine_test_instance_profile/ }).and be_idempotent
324
312
  end
325
313
 
326
314
  it "looks up the iam_instance_profile from the arn", :super_slow do
327
- expect_recipe {
328
- machine 'test_machine' do
315
+ expect_recipe do
316
+ machine "test_machine" do
329
317
  machine_options bootstrap_options: {
330
- subnet_id: 'test_public_subnet',
331
- key_name: 'test_key_pair',
332
- iam_instance_profile: {arn: machine_test_instance_profile.aws_object.arn}
318
+ subnet_id: "test_public_subnet",
319
+ key_name: "test_key_pair",
320
+ iam_instance_profile: { arn: machine_test_instance_profile.aws_object.arn }
333
321
  }
334
322
  action :allocate
335
323
  end
336
- }.to create_an_aws_instance('test_machine',
337
- iam_instance_profile: {arn: /machine_test_instance_profile/}
338
- ).and be_idempotent
324
+ end.to create_an_aws_instance("test_machine",
325
+ iam_instance_profile: { arn: /machine_test_instance_profile/ }).and be_idempotent
339
326
  end
340
327
  end
341
328
 
342
329
  it "machine with from_image option is created from correct image", :super_slow do
343
- expect_recipe {
344
-
345
- machine_image 'test_machine_ami' do
330
+ expect_recipe do
331
+ machine_image "test_machine_ami" do
346
332
  machine_options bootstrap_options: {
347
- subnet_id: 'test_public_subnet',
348
- key_name: 'test_key_pair'
333
+ subnet_id: "test_public_subnet",
334
+ key_name: "test_key_pair"
349
335
  }
350
336
  end
351
337
 
352
- machine 'test_machine' do
353
- from_image 'test_machine_ami'
338
+ machine "test_machine" do
339
+ from_image "test_machine_ami"
354
340
  machine_options bootstrap_options: {
355
- subnet_id: 'test_public_subnet',
356
- key_name: 'test_key_pair'
341
+ subnet_id: "test_public_subnet",
342
+ key_name: "test_key_pair"
357
343
  }
358
344
  action :allocate
359
345
  end
360
- }.to create_an_aws_instance('test_machine',
361
- image_id: driver.ec2.images.filter('name', 'test_machine_ami').first.image_id
362
- ).and create_an_aws_image('test_machine_ami',
363
- name: 'test_machine_ami'
364
- ).and be_idempotent
346
+ end.to create_an_aws_instance("test_machine",
347
+ image_id: driver.ec2.images.filter("name", "test_machine_ami").first.image_id).and create_an_aws_image("test_machine_ami",
348
+ name: "test_machine_ami").and be_idempotent
365
349
  end
366
350
 
367
351
  context "with an existing machine", :super_slow do
368
- machine 'test_machine' do
352
+ machine "test_machine" do
369
353
  machine_options bootstrap_options: {
370
- subnet_id: 'test_public_subnet',
371
- key_name: 'test_key_pair'
354
+ subnet_id: "test_public_subnet",
355
+ key_name: "test_key_pair"
372
356
  }
373
357
  action :allocate
374
358
  end
375
359
 
376
360
  it "stops the machine with the :stop action" do
377
- expect_recipe {
378
- machine 'test_machine' do
361
+ expect_recipe do
362
+ machine "test_machine" do
379
363
  action :stop
380
364
  end
381
- }.to update_an_aws_instance('test_machine',
382
- state: {:name => "stopped"}
383
- ).and be_idempotent
365
+ end.to update_an_aws_instance("test_machine",
366
+ state: { name: "stopped" }).and be_idempotent
384
367
  end
385
368
 
386
369
  it "starts a machine that has been stopped" do
387
- expect_recipe {
388
- machine 'test_machine' do
370
+ expect_recipe do
371
+ machine "test_machine" do
389
372
  action :stop
390
373
  end
391
- machine 'test_machine' do
374
+ machine "test_machine" do
392
375
  action :ready
393
376
  end
394
- }.to update_an_aws_instance('test_machine',
395
- state: {:name => "running"}
396
- )
377
+ end.to update_an_aws_instance("test_machine",
378
+ state: { name: "running" })
397
379
  end
398
380
  end
399
381
 
400
382
  it "doesn't create a machine if the initial action is :stop", :super_slow do
401
- expect_recipe {
402
- machine 'test_machine' do
383
+ expect_recipe do
384
+ machine "test_machine" do
403
385
  action :stop
404
386
  end
405
- }.not_to create_an_aws_instance('test_machine')
387
+ end.not_to create_an_aws_instance("test_machine")
406
388
  end
407
389
 
408
390
  it "can correctly destroy a machine", :super_slow do
409
- converge {
410
- machine 'test_machine1' do
391
+ converge do
392
+ machine "test_machine1" do
411
393
  action :allocate
412
394
  end
413
- }
414
- r = recipe {
415
- machine 'test_machine1' do
395
+ end
396
+ r = recipe do
397
+ machine "test_machine1" do
416
398
  action :destroy
417
399
  end
418
- }
419
- expect(r).to destroy_an_aws_instance('test_machine1')
400
+ end
401
+ expect(r).to destroy_an_aws_instance("test_machine1")
420
402
  end
421
403
 
422
404
  # Tests https://github.com/chef/chef-provisioning-aws/issues/189
423
405
  it "correctly finds the driver_url when switching between machine and aws_instance", :super_slow do
424
- converge {
425
- machine 'test_machine2' do
406
+ converge do
407
+ machine "test_machine2" do
426
408
  action :allocate
427
409
  end
428
- }
429
- r = recipe {
430
- aws_instance 'test_machine2' do
410
+ end
411
+ r = recipe do
412
+ aws_instance "test_machine2" do
431
413
  action :destroy
432
414
  end
433
- }
434
- expect(r).to destroy_an_aws_instance('test_machine2')
415
+ end
416
+ expect(r).to destroy_an_aws_instance("test_machine2")
435
417
  end
436
418
 
437
419
  context "with a custom key" do
438
- let(:private_key) {
420
+ let(:private_key) do
439
421
  k = OpenSSL::PKey::RSA.new(2048)
440
422
  f = Pathname.new(private_key_path)
441
423
  f.write(k.to_pem)
442
424
  k
443
- }
444
- let(:private_key_pem) {
425
+ end
426
+ let(:private_key_pem) do
445
427
  private_key.to_pem
446
- }
447
- let(:private_key_path) {
448
- Pathname.new(ENV['HOME']).join(".ssh", key_pair_name).expand_path
449
- }
450
- let(:public_key) {private_key.public_key}
428
+ end
429
+ let(:private_key_path) do
430
+ Pathname.new(ENV["HOME"]).join(".ssh", key_pair_name).expand_path
431
+ end
432
+ let(:public_key) { private_key.public_key }
451
433
  let(:key_pair_name) { "test_key_pair_#{Random.rand(100)}" }
452
434
 
453
435
  before do
454
- driver.ec2_client.import_key_pair({
436
+ driver.ec2_client.import_key_pair(
455
437
  key_name: key_pair_name, # required
456
438
  public_key_material: "#{public_key.ssh_type} #{[public_key.to_blob].pack('m0')}", # required
457
- })
439
+ )
458
440
  end
459
441
 
460
442
  after do
461
- driver.ec2_client.delete_key_pair({
443
+ driver.ec2_client.delete_key_pair(
462
444
  key_name: key_pair_name, # required
463
- })
445
+ )
464
446
  Pathname.new(private_key_path).delete
465
447
  end
466
448
 
467
449
  it "strips key_path from the bootstrap options when creating the machine", :super_slow do
468
- expect_recipe {
469
- machine 'test_machine' do
450
+ expect_recipe do
451
+ machine "test_machine" do
470
452
  machine_options bootstrap_options: {
471
- instance_type: 't2.medium',
453
+ instance_type: "t2.medium",
472
454
  key_name: key_pair_name,
473
455
  key_path: private_key_path
474
456
  }
475
457
  action :ready
476
458
  end
477
- }.to create_an_aws_instance('test_machine'
478
- ).and be_idempotent
459
+ end.to create_an_aws_instance("test_machine").and be_idempotent
479
460
  end
480
461
 
481
462
  it "uses key_data from the ssh_options", :super_slow do
482
- expect_recipe {
483
- machine 'test_machine' do
463
+ expect_recipe do
464
+ machine "test_machine" do
484
465
  machine_options(
485
466
  bootstrap_options: {
486
- instance_type: 't2.medium',
467
+ instance_type: "t2.medium",
487
468
  key_name: key_pair_name
488
469
  },
489
470
  ssh_options: {
@@ -492,11 +473,9 @@ describe Chef::Resource::Machine do
492
473
  )
493
474
  action :ready
494
475
  end
495
- }.to create_an_aws_instance('test_machine'
496
- ).and be_idempotent
476
+ end.to create_an_aws_instance("test_machine").and be_idempotent
497
477
  end
498
478
  end
499
-
500
479
  end
501
480
  end
502
481
  end