chef-provisioning-aws 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/lib/chef/provider/aws_auto_scaling_group.rb +30 -41
  4. data/lib/chef/provider/aws_dhcp_options.rb +70 -0
  5. data/lib/chef/provider/aws_ebs_volume.rb +182 -34
  6. data/lib/chef/provider/aws_eip_address.rb +63 -60
  7. data/lib/chef/provider/aws_key_pair.rb +18 -27
  8. data/lib/chef/provider/aws_launch_configuration.rb +50 -0
  9. data/lib/chef/provider/aws_route_table.rb +122 -0
  10. data/lib/chef/provider/aws_s3_bucket.rb +42 -49
  11. data/lib/chef/provider/aws_security_group.rb +252 -59
  12. data/lib/chef/provider/aws_sns_topic.rb +10 -26
  13. data/lib/chef/provider/aws_sqs_queue.rb +16 -38
  14. data/lib/chef/provider/aws_subnet.rb +85 -32
  15. data/lib/chef/provider/aws_vpc.rb +163 -23
  16. data/lib/chef/provisioning/aws_driver.rb +18 -1
  17. data/lib/chef/provisioning/aws_driver/aws_provider.rb +206 -0
  18. data/lib/chef/provisioning/aws_driver/aws_resource.rb +186 -0
  19. data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +114 -0
  20. data/lib/chef/provisioning/aws_driver/driver.rb +317 -255
  21. data/lib/chef/provisioning/aws_driver/resources.rb +8 -5
  22. data/lib/chef/provisioning/aws_driver/super_lwrp.rb +45 -0
  23. data/lib/chef/provisioning/aws_driver/version.rb +1 -1
  24. data/lib/chef/resource/aws_auto_scaling_group.rb +15 -13
  25. data/lib/chef/resource/aws_dhcp_options.rb +57 -0
  26. data/lib/chef/resource/aws_ebs_volume.rb +20 -22
  27. data/lib/chef/resource/aws_eip_address.rb +50 -25
  28. data/lib/chef/resource/aws_image.rb +20 -0
  29. data/lib/chef/resource/aws_instance.rb +20 -0
  30. data/lib/chef/resource/aws_internet_gateway.rb +16 -0
  31. data/lib/chef/resource/aws_key_pair.rb +6 -10
  32. data/lib/chef/resource/aws_launch_configuration.rb +15 -0
  33. data/lib/chef/resource/aws_load_balancer.rb +16 -0
  34. data/lib/chef/resource/aws_network_interface.rb +16 -0
  35. data/lib/chef/resource/aws_route_table.rb +76 -0
  36. data/lib/chef/resource/aws_s3_bucket.rb +8 -18
  37. data/lib/chef/resource/aws_security_group.rb +49 -19
  38. data/lib/chef/resource/aws_sns_topic.rb +14 -15
  39. data/lib/chef/resource/aws_sqs_queue.rb +16 -14
  40. data/lib/chef/resource/aws_subnet.rb +87 -17
  41. data/lib/chef/resource/aws_vpc.rb +137 -15
  42. data/spec/integration/aws_security_group_spec.rb +55 -0
  43. data/spec/spec_helper.rb +8 -2
  44. data/spec/support/aws_support.rb +211 -0
  45. metadata +33 -10
  46. data/lib/chef/provider/aws_launch_config.rb +0 -43
  47. data/lib/chef/provider/aws_provider.rb +0 -22
  48. data/lib/chef/provisioning/aws_driver/aws_profile.rb +0 -73
  49. data/lib/chef/resource/aws_launch_config.rb +0 -14
  50. data/lib/chef/resource/aws_resource.rb +0 -10
  51. data/spec/chef_zero_rspec_helper.rb +0 -8
  52. data/spec/unit/provider/aws_subnet_spec.rb +0 -67
  53. data/spec/unit/resource/aws_subnet_spec.rb +0 -23
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'chef/provisioning/aws_driver/credentials'
3
+
4
+ describe 'Aws Security Group' do
5
+ extend AWSSupport
6
+
7
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
8
+ with_aws "without a VPC" do
9
+
10
+ it "aws_security_group 'test_sg' with no attributes works" do
11
+ expect_recipe {
12
+ aws_security_group 'test_sg' do
13
+ end
14
+ }.to create_an_aws_security_group('test_sg',
15
+ description: 'test_sg',
16
+ vpc_id: default_vpc.id,
17
+ ip_permissions_list: [],
18
+ ip_permissions_list_egress: [{:groups=>[], :ip_ranges=>[{:cidr_ip=>"0.0.0.0/0"}], :ip_protocol=>"-1"}]
19
+ ).and be_idempotent
20
+ end
21
+
22
+ end
23
+
24
+ with_aws "in a VPC" do
25
+ aws_vpc 'test_vpc' do
26
+ cidr_block '10.0.0.0/24'
27
+ end
28
+
29
+ it "aws_security_group 'test_sg' with no attributes works" do
30
+ expect_recipe {
31
+ aws_security_group 'test_sg' do
32
+ vpc 'test_vpc'
33
+ end
34
+ }.to create_an_aws_security_group('test_sg',
35
+ vpc_id: test_vpc.aws_object.id,
36
+ ip_permissions_list: [],
37
+ ip_permissions_list_egress: [{:groups=>[], :ip_ranges=>[{:cidr_ip=>"0.0.0.0/0"}], :ip_protocol=>"-1"}]
38
+ ).and be_idempotent
39
+ end
40
+
41
+ it "aws_security_group 'test_sg' with inbound rules works" do
42
+ expect_recipe {
43
+ aws_security_group 'test_sg' do
44
+ vpc 'test_vpc'
45
+ inbound_rules '0.0.0.0/0' => 22
46
+ end
47
+ }.to create_an_aws_security_group('test_sg',
48
+ vpc_id: test_vpc.aws_object.id,
49
+ ip_permissions_list: [{:groups=>[], :ip_ranges=>[{:cidr_ip=>"0.0.0.0/0"}], :ip_protocol=>"tcp", :from_port=>22, :to_port=>22}],
50
+ ip_permissions_list_egress: [{:groups=>[], :ip_ranges=>[{:cidr_ip=>"0.0.0.0/0"}], :ip_protocol=>"-1"}]
51
+ ).and be_idempotent
52
+ end
53
+ end
54
+ end
55
+ end
@@ -5,11 +5,17 @@ require 'chef/provisioning/aws_driver'
5
5
  require 'chef/platform'
6
6
  require 'chef/run_context'
7
7
  require 'chef/event_dispatch/dispatcher'
8
+ require 'support/aws_support'
8
9
 
9
10
  RSpec.configure do |rspec|
10
11
  rspec.run_all_when_everything_filtered = true
11
12
  rspec.filter_run :focus
12
- rspec.order = 'random'
13
+ # rspec.order = 'random'
13
14
  rspec.expect_with(:rspec) { |c| c.syntax = :expect }
14
- rspec.before { allow($stdout).to receive(:write) }
15
+ # rspec.before { allow($stdout).to receive(:write) }
15
16
  end
17
+
18
+ #Chef::Log.level = :debug
19
+
20
+ #AWS.stub!
21
+ require 'cheffish/rspec/matchers'
@@ -0,0 +1,211 @@
1
+ require 'cheffish/rspec/chef_run_support'
2
+ require 'cheffish/rspec/recipe_run_wrapper'
3
+ require 'chef/provisioning/aws_driver'
4
+
5
+ module AWSSupport
6
+ def self.extended(other)
7
+ other.extend Cheffish::RSpec::ChefRunSupport
8
+ end
9
+
10
+ def with_aws(description, *tags, &block)
11
+ if ENV['AWS_TEST_DRIVER']
12
+ aws_driver = Chef::Provisioning.driver_for_url(ENV['AWS_TEST_DRIVER'])
13
+ else
14
+ tags << { skip: "AWS_TEST_DRIVER not set ... cannot run AWS test. Set AWS_TEST_DRIVER=aws or aws:profile:region to run tests that hit AWS" }
15
+ end
16
+
17
+ context description, *tags do
18
+ extend WithAWSClassMethods
19
+ include WithAWSInstanceMethods
20
+
21
+ @@driver = aws_driver
22
+ def self.driver
23
+ @@driver
24
+ end
25
+
26
+ module_eval(&block)
27
+ end
28
+ end
29
+
30
+ module WithAWSClassMethods
31
+ def chef_config
32
+ { driver: driver }
33
+ end
34
+
35
+ instance_eval do
36
+ #
37
+ # Create a context-level method for each AWS resource:
38
+ #
39
+ # with_aws do
40
+ # context 'mycontext' do
41
+ # aws_vpc 'myvpc' do
42
+ # ...
43
+ # end
44
+ # end
45
+ # end
46
+ #
47
+ # Creates the AWS thing when the first example in the context runs.
48
+ # Destroys it after the last example in the context runs. Objects created
49
+ # in the order declared, and destroyed in reverse order.
50
+ #
51
+ Chef::Provisioning::AWSDriver::Resources.constants.each do |resource_class|
52
+ resource_class = Chef::Provisioning::AWSDriver::Resources.const_get(resource_class)
53
+ # def aws_vpc(name, &block)
54
+ define_method(resource_class.resource_name) do |name, &block|
55
+ # def myvpc
56
+ # @@myvpc
57
+ # end
58
+ instance_eval do
59
+ define_method(name) { class_variable_get(:"@@#{name}") }
60
+ end
61
+ module_eval do
62
+ define_method(name) { self.class.class_variable_get(:"@@#{name}") }
63
+ end
64
+
65
+ resource = nil
66
+
67
+ before :context do
68
+ resource = AWSResourceRunWrapper.new(self, resource_class.resource_name, name, &block)
69
+ # @myvpc = resource
70
+ begin
71
+ self.class.class_variable_set(:"@@#{name}", resource.resource)
72
+ rescue NameError
73
+ end
74
+ resource.converge
75
+ end
76
+
77
+ after :context do
78
+ resource.destroy if resource
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ module WithAWSInstanceMethods
86
+ def self.included(context)
87
+ context.module_eval do
88
+ # Destroy any objects we know got created during the test
89
+ after :example do
90
+ created_during_test.reverse_each do |resource_name, name|
91
+ (recipe do
92
+ public_send(resource_name, name) do
93
+ action :destroy
94
+ end
95
+ end).converge
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ def chef_config
102
+ { driver: driver }
103
+ end
104
+
105
+ def created_during_test
106
+ @created_during_test ||= []
107
+ end
108
+
109
+ def default_vpc
110
+ @default_vpc ||= driver.ec2.vpcs.filter('isDefault', 'true').first
111
+ end
112
+
113
+ def driver
114
+ self.class.driver
115
+ end
116
+ end
117
+
118
+ class AWSResourceRunWrapper < Cheffish::RSpec::RecipeRunWrapper
119
+ def initialize(rspec_context, resource_type, name, &properties)
120
+ super(rspec_context.chef_config) do
121
+ public_send(resource_type, name, &properties)
122
+ end
123
+ @rspec_context = rspec_context
124
+ @resource_type = resource_type
125
+ @name = name
126
+ @properties = properties
127
+ end
128
+
129
+ attr_reader :rspec_context
130
+ attr_reader :resource_type
131
+ attr_reader :name
132
+
133
+ def resource
134
+ resources.first
135
+ end
136
+
137
+ def to_s
138
+ "#{resource_type}[#{name}]"
139
+ end
140
+
141
+ def destroy
142
+ resource_type = self.resource_type
143
+ name = self.name
144
+ rspec_context.run_recipe do
145
+ public_send(resource_type, name) do
146
+ action :destroy
147
+ end
148
+ end
149
+ end
150
+
151
+ def aws_object
152
+ resource.aws_object
153
+ end
154
+ end
155
+ end
156
+
157
+
158
+ #
159
+ # Matchers for:
160
+ #
161
+ # - create_an_aws_security_group
162
+ # - create_an_aws_vpc
163
+ # etc.
164
+ #
165
+ # Checks if the object got created, then deletes the object at the end of the test.
166
+ #
167
+ Chef::Provisioning::AWSDriver::Resources.constants.each do |resource_class|
168
+ resource_class = Chef::Provisioning::AWSDriver::Resources.const_get(resource_class)
169
+
170
+ RSpec::Matchers.define :"create_an_#{resource_class.resource_name}" do |name, expected_properties|
171
+ match do |recipe|
172
+ @recipe = recipe
173
+
174
+ # Converge
175
+ recipe.converge
176
+ expect(recipe).to be_updated
177
+
178
+ resource = resource_class.new(name, nil)
179
+ resource.driver driver
180
+ resource.managed_entry_store Chef::Provisioning.chef_managed_entry_store
181
+ aws_object = resource.aws_object
182
+
183
+ # Check existence and properties
184
+ if aws_object.nil?
185
+ raise "#{resource.to_s} succeeded but was not created!"
186
+ end
187
+
188
+ created_during_test << [ resource_class.resource_name, name ]
189
+
190
+ # Check to see if properties have the expected values
191
+ @differences = {}
192
+ expected_properties.each do |name, value|
193
+ aws_value = aws_object.public_send(name)
194
+ if !(aws_value === expected_properties[name])
195
+ @differences[name] = aws_value
196
+ end
197
+ end
198
+
199
+ @differences.empty?
200
+ end
201
+
202
+ failure_message {
203
+ message = "#{@recipe} created an AWS object with unexpected values:\n"
204
+ @differences.each do |name, value|
205
+ message << "- expected #{name} to match #{expected_properties[name].inspect}, but the actual value was #{value.inspect}\n"
206
+ end
207
+ message << @recipe.output_for_failure_message
208
+ message
209
+ }
210
+ end
211
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: retryable
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -106,11 +120,12 @@ files:
106
120
  - README.md
107
121
  - Rakefile
108
122
  - lib/chef/provider/aws_auto_scaling_group.rb
123
+ - lib/chef/provider/aws_dhcp_options.rb
109
124
  - lib/chef/provider/aws_ebs_volume.rb
110
125
  - lib/chef/provider/aws_eip_address.rb
111
126
  - lib/chef/provider/aws_key_pair.rb
112
- - lib/chef/provider/aws_launch_config.rb
113
- - lib/chef/provider/aws_provider.rb
127
+ - lib/chef/provider/aws_launch_configuration.rb
128
+ - lib/chef/provider/aws_route_table.rb
114
129
  - lib/chef/provider/aws_s3_bucket.rb
115
130
  - lib/chef/provider/aws_security_group.rb
116
131
  - lib/chef/provider/aws_sns_topic.rb
@@ -118,29 +133,37 @@ files:
118
133
  - lib/chef/provider/aws_subnet.rb
119
134
  - lib/chef/provider/aws_vpc.rb
120
135
  - lib/chef/provisioning/aws_driver.rb
121
- - lib/chef/provisioning/aws_driver/aws_profile.rb
136
+ - lib/chef/provisioning/aws_driver/aws_provider.rb
137
+ - lib/chef/provisioning/aws_driver/aws_resource.rb
138
+ - lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb
122
139
  - lib/chef/provisioning/aws_driver/credentials.rb
123
140
  - lib/chef/provisioning/aws_driver/driver.rb
124
141
  - lib/chef/provisioning/aws_driver/resources.rb
142
+ - lib/chef/provisioning/aws_driver/super_lwrp.rb
125
143
  - lib/chef/provisioning/aws_driver/version.rb
126
144
  - lib/chef/provisioning/driver_init/aws.rb
127
145
  - lib/chef/resource/aws_auto_scaling_group.rb
146
+ - lib/chef/resource/aws_dhcp_options.rb
128
147
  - lib/chef/resource/aws_ebs_volume.rb
129
148
  - lib/chef/resource/aws_eip_address.rb
149
+ - lib/chef/resource/aws_image.rb
150
+ - lib/chef/resource/aws_instance.rb
151
+ - lib/chef/resource/aws_internet_gateway.rb
130
152
  - lib/chef/resource/aws_key_pair.rb
131
- - lib/chef/resource/aws_launch_config.rb
132
- - lib/chef/resource/aws_resource.rb
153
+ - lib/chef/resource/aws_launch_configuration.rb
154
+ - lib/chef/resource/aws_load_balancer.rb
155
+ - lib/chef/resource/aws_network_interface.rb
156
+ - lib/chef/resource/aws_route_table.rb
133
157
  - lib/chef/resource/aws_s3_bucket.rb
134
158
  - lib/chef/resource/aws_security_group.rb
135
159
  - lib/chef/resource/aws_sns_topic.rb
136
160
  - lib/chef/resource/aws_sqs_queue.rb
137
161
  - lib/chef/resource/aws_subnet.rb
138
162
  - lib/chef/resource/aws_vpc.rb
139
- - spec/chef_zero_rspec_helper.rb
163
+ - spec/integration/aws_security_group_spec.rb
140
164
  - spec/spec_helper.rb
165
+ - spec/support/aws_support.rb
141
166
  - spec/unit/aws_driver/credentials_spec.rb
142
- - spec/unit/provider/aws_subnet_spec.rb
143
- - spec/unit/resource/aws_subnet_spec.rb
144
167
  homepage: https://github.com/opscode/chef-provisioning-aws
145
168
  licenses: []
146
169
  metadata: {}
@@ -1,43 +0,0 @@
1
- require 'chef/provider/aws_provider'
2
-
3
- class Chef::Provider::AwsLaunchConfig < Chef::Provider::AwsProvider
4
- action :create do
5
- if existing_launch_config.nil?
6
- converge_by "Creating new Launch Config #{id} in #{new_driver.aws_config.region}" do
7
- @existing_launch_config = new_driver.auto_scaling.launch_configurations.create(
8
- new_resource.name,
9
- new_resource.image,
10
- new_resource.instance_type
11
- )
12
-
13
- new_resource.save
14
- end
15
- end
16
- end
17
-
18
- action :delete do
19
- if existing_launch_config
20
- converge_by "Deleting Launch Config #{id} in #{new_driver.aws_config.region}" do
21
- begin
22
- existing_launch_config.delete
23
- rescue AWS::AutoScaling::Errors::ResourceInUse
24
- sleep 5
25
- retry
26
- end
27
- end
28
- end
29
-
30
- new_resource.delete
31
- end
32
-
33
- def existing_launch_config
34
- @existing_launch_config ||= begin
35
- elc = new_driver.auto_scaling.launch_configurations[new_resource.name]
36
- elc.exists? ? elc : nil
37
- end
38
- end
39
-
40
- def id
41
- new_resource.name
42
- end
43
- end
@@ -1,22 +0,0 @@
1
- require 'chef/provider/lwrp_base'
2
-
3
- class Chef::Provider::AwsProvider < Chef::Provider::LWRPBase
4
- use_inline_resources
5
-
6
- # All these need to implement whyrun
7
- def whyrun_supported?
8
- true
9
- end
10
-
11
- def fqn
12
- if id
13
- id
14
- else
15
- "#{new_resource.name}_#{new_driver.aws_config.region}"
16
- end
17
- end
18
-
19
- def new_driver
20
- run_context.chef_provisioning.driver_for(new_resource.driver)
21
- end
22
- end