chef-provisioning-aws 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -0
  3. data/Rakefile +5 -0
  4. data/lib/chef/provider/aws_ebs_volume.rb +14 -4
  5. data/lib/chef/provider/aws_image.rb +31 -0
  6. data/lib/chef/provider/aws_instance.rb +14 -0
  7. data/lib/chef/provider/aws_load_balancer.rb +9 -0
  8. data/lib/chef/provider/aws_network_interface.rb +209 -0
  9. data/lib/chef/provider/aws_security_group.rb +9 -4
  10. data/lib/chef/provider/aws_subnet.rb +16 -1
  11. data/lib/chef/provider/aws_vpc.rb +16 -0
  12. data/lib/chef/provisioning/aws_driver/aws_provider.rb +44 -0
  13. data/lib/chef/provisioning/aws_driver/aws_resource.rb +1 -1
  14. data/lib/chef/provisioning/aws_driver/driver.rb +6 -5
  15. data/lib/chef/provisioning/aws_driver/version.rb +1 -1
  16. data/lib/chef/resource/aws_image.rb +1 -2
  17. data/lib/chef/resource/aws_instance.rb +1 -2
  18. data/lib/chef/resource/aws_load_balancer.rb +1 -1
  19. data/lib/chef/resource/aws_network_interface.rb +23 -5
  20. data/lib/chef/resource/aws_vpc.rb +0 -8
  21. data/spec/aws_support.rb +235 -0
  22. data/spec/aws_support/aws_resource_run_wrapper.rb +45 -0
  23. data/spec/aws_support/deep_matcher.rb +40 -0
  24. data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +57 -0
  25. data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +145 -0
  26. data/spec/aws_support/deep_matcher/matchable_array.rb +24 -0
  27. data/spec/aws_support/deep_matcher/matchable_object.rb +25 -0
  28. data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +25 -0
  29. data/spec/aws_support/delayed_stream.rb +41 -0
  30. data/spec/aws_support/matchers/create_an_aws_object.rb +60 -0
  31. data/spec/aws_support/matchers/update_an_aws_object.rb +66 -0
  32. data/spec/integration/aws_ebs_volume_spec.rb +31 -0
  33. data/spec/integration/aws_key_pair_spec.rb +21 -0
  34. data/spec/integration/aws_route_table_spec.rb +40 -0
  35. data/spec/integration/aws_security_group_spec.rb +7 -5
  36. data/spec/integration/aws_subnet_spec.rb +56 -0
  37. data/spec/integration/aws_vpc_spec.rb +109 -0
  38. data/spec/integration/machine_batch_spec.rb +36 -0
  39. data/spec/integration/machine_image_spec.rb +49 -0
  40. data/spec/integration/machine_spec.rb +64 -0
  41. data/spec/spec_helper.rb +8 -2
  42. data/spec/unit/aws_driver/credentials_spec.rb +54 -0
  43. metadata +27 -5
  44. data/spec/support/aws_support.rb +0 -211
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::AwsEbsVolume do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "when connected to AWS" do
8
+
9
+ it "aws_ebs_volume 'test_volume' creates an ebs volume" do
10
+ expect_recipe {
11
+ aws_ebs_volume "test_volume" do
12
+ availability_zone 'a'
13
+ size 8
14
+ end
15
+ }.to create_an_aws_ebs_volume('test_volume',
16
+ :size => 8
17
+ ).and be_idempotent
18
+ end
19
+
20
+ it "aws_ebs_volume 'test_volume_az' creates an ebs volume when provided proper full AZ" do
21
+ expect_recipe {
22
+ aws_ebs_volume "test_volume_az" do
23
+ availability_zone "#{driver.aws_config.region}a"
24
+ size 8
25
+ end
26
+ }.to create_an_aws_ebs_volume('test_volume_az')
27
+ .and be_idempotent
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::AwsKeyPair do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "when connected to AWS" do
8
+ before :each do
9
+ driver.ec2.key_pairs['test_key_pair'].delete
10
+ end
11
+
12
+ it "aws_key_pair 'test_key_pair' creates a key pair" do
13
+ expect_recipe {
14
+ aws_key_pair 'test_key_pair' do
15
+ private_key_options format: :der, type: :rsa
16
+ end
17
+ }.to create_an_aws_key_pair('test_key_pair').and be_idempotent
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::AwsRouteTable do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "with a VPC with an internet gateway" do
8
+ aws_vpc "test_vpc" do
9
+ cidr_block '10.0.0.0/24'
10
+ internet_gateway true
11
+ end
12
+
13
+ it "aws_route_table 'test_route_table' with no parameters except VPC creates a route table" do
14
+ expect_recipe {
15
+ aws_route_table 'test_route_table' do
16
+ vpc 'test_vpc'
17
+ end
18
+ }.to create_an_aws_route_table('test_route_table',
19
+ routes: [
20
+ { destination_cidr_block: '10.0.0.0/24', 'target.id' => 'local', state: :active }
21
+ ]
22
+ ).and be_idempotent
23
+ end
24
+
25
+ it "aws_route_table 'test_route_table' with routes creates a route table" do
26
+ expect_recipe {
27
+ aws_route_table 'test_route_table' do
28
+ vpc 'test_vpc'
29
+ routes '0.0.0.0/0' => :internet_gateway
30
+ end
31
+ }.to create_an_aws_route_table('test_route_table',
32
+ routes: [
33
+ { destination_cidr_block: '10.0.0.0/24', 'target.id' => 'local', state: :active },
34
+ { destination_cidr_block: '0.0.0.0/0', 'target.id' => test_vpc.aws_object.internet_gateway.id, state: :active }
35
+ ]
36
+ ).and be_idempotent
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'chef/provisioning/aws_driver/credentials'
3
2
 
4
- describe 'Aws Security Group' do
3
+ describe Chef::Resource::AwsSecurityGroup do
5
4
  extend AWSSupport
6
5
 
7
6
  when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
@@ -38,16 +37,19 @@ describe 'Aws Security Group' do
38
37
  ).and be_idempotent
39
38
  end
40
39
 
41
- it "aws_security_group 'test_sg' with inbound rules works" do
40
+ it "aws_security_group 'test_sg' with inbound and outbound rules works" do
42
41
  expect_recipe {
43
42
  aws_security_group 'test_sg' do
44
43
  vpc 'test_vpc'
45
44
  inbound_rules '0.0.0.0/0' => 22
45
+ outbound_rules 22 => '0.0.0.0/0'
46
46
  end
47
47
  }.to create_an_aws_security_group('test_sg',
48
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"}]
49
+ ip_permissions_list: [
50
+ { groups: [], ip_ranges: [{cidr_ip: "0.0.0.0/0"}], ip_protocol: "tcp", from_port: 22, to_port: 22},
51
+ ],
52
+ ip_permissions_list_egress: [{groups: [], ip_ranges: [{cidr_ip: "0.0.0.0/0"}], ip_protocol: "tcp", from_port: 22, to_port: 22 }]
51
53
  ).and be_idempotent
52
54
  end
53
55
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::AwsSubnet do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "with a VPC with an internet gateway and route table" do
8
+ before :context do
9
+ driver.ec2.vpcs.with_tag('Name', 'test_vpc').each do |vpc|
10
+ recipe do
11
+ aws_vpc vpc do
12
+ action :purge
13
+ end
14
+ end.converge
15
+ end
16
+ end
17
+ aws_vpc "test_vpc" do
18
+ cidr_block '10.0.0.0/24'
19
+ internet_gateway true
20
+ end
21
+
22
+ aws_route_table 'test_route_table' do
23
+ vpc 'test_vpc'
24
+ end
25
+
26
+ it "aws_subnet 'test_subnet' with no parameters except VPC creates a route table" do
27
+ expect_recipe {
28
+ aws_subnet 'test_subnet' do
29
+ vpc 'test_vpc'
30
+ end
31
+ }.to create_an_aws_subnet('test_subnet',
32
+ vpc_id: test_vpc.aws_object.id,
33
+ cidr_block: test_vpc.aws_object.cidr_block
34
+ ).and be_idempotent
35
+ end
36
+
37
+ it "aws_subnet 'test_subnet' with all parameters creates a route table" do
38
+ az = driver.ec2.availability_zones.first.name
39
+ expect_recipe {
40
+ aws_subnet 'test_subnet' do
41
+ vpc 'test_vpc'
42
+ cidr_block '10.0.0.0/24'
43
+ availability_zone az
44
+ map_public_ip_on_launch true
45
+ route_table 'test_route_table'
46
+ end
47
+ }.to create_an_aws_subnet('test_subnet',
48
+ vpc_id: test_vpc.aws_object.id,
49
+ cidr_block: '10.0.0.0/24',
50
+ 'availability_zone.name' => az,
51
+ 'route_table.id' => test_route_table.aws_object.id
52
+ ).and be_idempotent
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::AwsVpc do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "When AWS has a DHCP options" do
8
+ # Empty DHCP options for the purposes of associating
9
+ aws_dhcp_options 'test_dhcp_options' do
10
+ end
11
+
12
+ context "Creating an aws_vpc" do
13
+ it "aws_vpc 'vpc' with cidr_block '10.0.0.0/24' creates a VPC" do
14
+ expect_recipe {
15
+ aws_vpc 'test_vpc' do
16
+ cidr_block '10.0.0.0/24'
17
+ end
18
+ }.to create_an_aws_vpc('test_vpc',
19
+ cidr_block: '10.0.0.0/24',
20
+ instance_tenancy: :default,
21
+ state: :available,
22
+ internet_gateway: nil
23
+ ).and be_idempotent
24
+ end
25
+
26
+ it "aws_vpc 'vpc' with all attributes creates a VPC" do
27
+ expect_recipe {
28
+ aws_vpc 'test_vpc' do
29
+ cidr_block '10.0.0.0/24'
30
+ internet_gateway true
31
+ instance_tenancy :dedicated
32
+ main_routes '0.0.0.0/0' => :internet_gateway
33
+ dhcp_options 'test_dhcp_options'
34
+ enable_dns_support true
35
+ enable_dns_hostnames true
36
+ end
37
+ }.to create_an_aws_vpc('test_vpc',
38
+ cidr_block: '10.0.0.0/24',
39
+ instance_tenancy: :dedicated,
40
+ dhcp_options_id: test_dhcp_options.aws_object.id,
41
+ state: :available,
42
+ "route_tables.main_route_table.routes" => [
43
+ {
44
+ destination_cidr_block: '10.0.0.0/24',
45
+ target: { id: 'local' }
46
+ },
47
+ {
48
+ destination_cidr_block: '0.0.0.0/0',
49
+ target: an_instance_of(AWS::EC2::InternetGateway)
50
+ }
51
+ ],
52
+ internet_gateway: an_instance_of(AWS::EC2::InternetGateway)
53
+ ).and be_idempotent
54
+ end
55
+ end
56
+
57
+ context "and an existing VPC with values filled in" do
58
+ aws_vpc 'test_vpc' do
59
+ cidr_block '10.0.0.0/24'
60
+ internet_gateway true
61
+ instance_tenancy :dedicated
62
+ main_routes '0.0.0.0/0' => :internet_gateway
63
+ dhcp_options 'test_dhcp_options'
64
+ enable_dns_support true
65
+ enable_dns_hostnames true
66
+ end
67
+
68
+ context "and a route table inside that VPC" do
69
+ aws_route_table 'test_route_table' do
70
+ vpc 'test_vpc'
71
+ end
72
+
73
+ it "aws_vpc can update the main_route_table to it" do
74
+ expect_recipe {
75
+ aws_vpc 'test_vpc' do
76
+ main_route_table 'test_route_table'
77
+ end
78
+ }.to update_an_aws_vpc('test_vpc',
79
+ "route_tables.main_route_table.id" => test_route_table.aws_object.id
80
+ ).and be_idempotent
81
+ end
82
+
83
+ # Clean up the main route table association so we can cleanly delete
84
+ before :each do
85
+ @old_main = test_vpc.aws_object.route_tables.main_route_table
86
+ end
87
+ after :each do
88
+ new_main = test_vpc.aws_object.route_tables.main_route_table
89
+ if new_main != @old_main
90
+ main_association = new_main.associations.select { |a| a.main? }.first
91
+ if main_association
92
+ test_vpc.aws_object.client.replace_route_table_association(
93
+ association_id: main_association.id,
94
+ route_table_id: @old_main.id)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ it "aws_vpc 'vpc' with no attributes fails to create a VPC (must specify cidr_block)" do
102
+ expect_recipe {
103
+ aws_vpc 'test_vpc' do
104
+ end
105
+ }.to be_up_to_date
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::MachineBatch do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "with a VPC and a public subnet" do
8
+
9
+ before :all do
10
+ chef_config[:log_level] = :warn
11
+ end
12
+
13
+ purge_all
14
+ setup_public_vpc
15
+ it "machine_batch creates multiple machines", :super_slow do
16
+ expect_recipe {
17
+ machine_batch 'test_machines' do
18
+ (1..3).each do |i|
19
+ machine "test_machine#{i}" do
20
+ machine_options bootstrap_options: {
21
+ subnet_id: 'test_public_subnet',
22
+ key_name: 'test_key_pair'
23
+ }
24
+ action :allocate
25
+ end
26
+ end
27
+ end
28
+ }.to create_an_aws_instance('test_machine1'
29
+ ).and create_an_aws_instance('test_machine2'
30
+ ).and create_an_aws_instance('test_machine3'
31
+ ).and be_idempotent
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::MachineImage do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "with a VPC and a public subnet" do
8
+ before :all do
9
+ chef_config[:log_level] = :warn
10
+ end
11
+
12
+ purge_all
13
+ setup_public_vpc
14
+
15
+ it "machine_image can create an image in the VPC", :super_slow do
16
+ expect_recipe {
17
+ machine_image 'test_machine_image' do
18
+ machine_options bootstrap_options: {
19
+ subnet_id: 'test_public_subnet',
20
+ key_name: 'test_key_pair'
21
+ }
22
+ end
23
+ }.to create_an_aws_image('test_machine_image',
24
+ name: 'test_machine_image'
25
+ ).and be_idempotent
26
+ end
27
+ end
28
+
29
+ with_aws "Without a VPC" do
30
+ before :all do
31
+ chef_config[:log_level] = :warn
32
+ end
33
+
34
+ it "machine_image with no options can create an image in the VPC", :super_slow do
35
+ expect_recipe {
36
+ aws_key_pair 'test_key_pair' do
37
+ allow_overwrite true
38
+ end
39
+ machine_image 'test_machine_image' do
40
+ machine_options bootstrap_options: { key_name: 'test_key_pair' }
41
+ end
42
+ }.to create_an_aws_image('test_machine_image',
43
+ name: 'test_machine_image'
44
+ ).and create_an_aws_key_pair('test_key_pair'
45
+ ).and be_idempotent
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::Machine do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "with a VPC and a public subnet" do
8
+
9
+ before :all do
10
+ chef_config[:log_level] = :warn
11
+ end
12
+
13
+ purge_all
14
+ setup_public_vpc
15
+ it "machine with few options allocates a machine", :super_slow do
16
+ expect_recipe {
17
+ machine 'test_machine' do
18
+ machine_options bootstrap_options: {
19
+ subnet_id: 'test_public_subnet',
20
+ key_name: 'test_key_pair'
21
+ }
22
+ action :allocate
23
+ end
24
+ }.to create_an_aws_instance('test_machine'
25
+ ).and be_idempotent
26
+ end
27
+
28
+ it "machine with few options converges a machine", :super_slow do
29
+ expect_recipe {
30
+ machine 'test_machine' do
31
+ machine_options bootstrap_options: {
32
+ subnet_id: 'test_public_subnet',
33
+ key_name: 'test_key_pair'
34
+ }
35
+ action :allocate
36
+ end
37
+ }.to create_an_aws_instance('test_machine'
38
+ ).and be_idempotent
39
+ end
40
+ end
41
+
42
+ with_aws "Without a VPC" do
43
+
44
+ before :all do
45
+ chef_config[:log_level] = :warn
46
+ end
47
+
48
+ #purge_all
49
+ it "machine with no options creates an machine", :super_slow do
50
+ expect_recipe {
51
+ aws_key_pair 'test_key_pair' do
52
+ allow_overwrite true
53
+ end
54
+ machine 'test_machine' do
55
+ machine_options bootstrap_options: { key_name: 'test_key_pair' }
56
+ action :allocate
57
+ end
58
+ }.to create_an_aws_instance('test_machine'
59
+ ).and create_an_aws_key_pair('test_key_pair'
60
+ ).and be_idempotent
61
+ end
62
+ end
63
+ end
64
+ end