chef-provisioning-aws 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -69
  3. data/Rakefile +22 -2
  4. data/lib/chef/provider/aws_auto_scaling_group.rb +3 -2
  5. data/lib/chef/provider/aws_cache_cluster.rb +3 -2
  6. data/lib/chef/provider/aws_cache_replication_group.rb +5 -4
  7. data/lib/chef/provider/aws_cache_subnet_group.rb +5 -4
  8. data/lib/chef/provider/aws_cloudsearch_domain.rb +163 -0
  9. data/lib/chef/provider/aws_dhcp_options.rb +9 -6
  10. data/lib/chef/provider/aws_ebs_volume.rb +7 -3
  11. data/lib/chef/provider/aws_eip_address.rb +8 -7
  12. data/lib/chef/provider/aws_image.rb +8 -3
  13. data/lib/chef/provider/aws_instance.rb +14 -2
  14. data/lib/chef/provider/aws_key_pair.rb +2 -1
  15. data/lib/chef/provider/aws_launch_configuration.rb +4 -2
  16. data/lib/chef/provider/aws_load_balancer.rb +18 -0
  17. data/lib/chef/provider/aws_network_acl.rb +6 -2
  18. data/lib/chef/provider/aws_network_interface.rb +11 -24
  19. data/lib/chef/provider/aws_rds_instance.rb +66 -0
  20. data/lib/chef/provider/aws_rds_subnet_group.rb +89 -0
  21. data/lib/chef/provider/aws_route_table.rb +42 -23
  22. data/lib/chef/provider/aws_s3_bucket.rb +32 -8
  23. data/lib/chef/provider/aws_security_group.rb +11 -4
  24. data/lib/chef/provider/aws_server_certificate.rb +23 -0
  25. data/lib/chef/provider/aws_sns_topic.rb +4 -3
  26. data/lib/chef/provider/aws_sqs_queue.rb +3 -2
  27. data/lib/chef/provider/aws_subnet.rb +10 -7
  28. data/lib/chef/provider/aws_vpc.rb +54 -21
  29. data/lib/chef/provider/aws_vpc_peering_connection.rb +88 -0
  30. data/lib/chef/provisioning/aws_driver.rb +8 -0
  31. data/lib/chef/provisioning/aws_driver/aws_provider.rb +45 -76
  32. data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +11 -0
  33. data/lib/chef/provisioning/aws_driver/aws_resource.rb +14 -2
  34. data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +2 -8
  35. data/lib/chef/provisioning/aws_driver/aws_taggable.rb +18 -0
  36. data/lib/chef/provisioning/aws_driver/aws_tagger.rb +61 -0
  37. data/lib/chef/provisioning/aws_driver/credentials2.rb +51 -0
  38. data/lib/chef/provisioning/aws_driver/driver.rb +214 -162
  39. data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +64 -0
  40. data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +39 -0
  41. data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +92 -0
  42. data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -0
  43. data/lib/chef/provisioning/aws_driver/version.rb +1 -1
  44. data/lib/chef/resource/aws_cache_cluster.rb +1 -2
  45. data/lib/chef/resource/aws_cloudsearch_domain.rb +46 -0
  46. data/lib/chef/resource/aws_dhcp_options.rb +2 -0
  47. data/lib/chef/resource/aws_ebs_volume.rb +3 -1
  48. data/lib/chef/resource/aws_eip_address.rb +0 -3
  49. data/lib/chef/resource/aws_image.rb +3 -0
  50. data/lib/chef/resource/aws_instance.rb +7 -2
  51. data/lib/chef/resource/aws_internet_gateway.rb +2 -0
  52. data/lib/chef/resource/aws_load_balancer.rb +3 -0
  53. data/lib/chef/resource/aws_network_acl.rb +2 -0
  54. data/lib/chef/resource/aws_network_interface.rb +3 -1
  55. data/lib/chef/resource/aws_rds_instance.rb +42 -0
  56. data/lib/chef/resource/aws_rds_subnet_group.rb +29 -0
  57. data/lib/chef/resource/aws_route_table.rb +7 -5
  58. data/lib/chef/resource/aws_s3_bucket.rb +3 -0
  59. data/lib/chef/resource/aws_security_group.rb +2 -7
  60. data/lib/chef/resource/aws_server_certificate.rb +21 -0
  61. data/lib/chef/resource/aws_subnet.rb +2 -0
  62. data/lib/chef/resource/aws_vpc.rb +4 -1
  63. data/lib/chef/resource/aws_vpc_peering_connection.rb +73 -0
  64. data/spec/acceptance/aws_ebs_volume/nodes/ettores-mbp.lan.json +3 -0
  65. data/spec/aws_support.rb +25 -8
  66. data/spec/aws_support/aws_resource_run_wrapper.rb +5 -1
  67. data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +19 -0
  68. data/spec/aws_support/matchers/create_an_aws_object.rb +1 -1
  69. data/spec/aws_support/matchers/destroy_an_aws_object.rb +1 -1
  70. data/spec/aws_support/matchers/have_aws_object_tags.rb +9 -15
  71. data/spec/aws_support/matchers/match_an_aws_object.rb +1 -1
  72. data/spec/aws_support/matchers/update_an_aws_object.rb +1 -1
  73. data/spec/integration/aws_cloudsearch_domain_spec.rb +31 -0
  74. data/spec/integration/aws_dhcp_options_spec.rb +73 -0
  75. data/spec/integration/aws_ebs_volume_spec.rb +97 -0
  76. data/spec/integration/aws_network_acl_spec.rb +51 -0
  77. data/spec/integration/aws_network_interface_spec.rb +89 -0
  78. data/spec/integration/aws_rds_instance_spec.rb +150 -0
  79. data/spec/integration/aws_rds_subnet_group_spec.rb +105 -0
  80. data/spec/integration/aws_route_table_spec.rb +94 -7
  81. data/spec/integration/aws_s3_bucket_spec.rb +88 -0
  82. data/spec/integration/aws_security_group_spec.rb +47 -0
  83. data/spec/integration/aws_server_certificate_spec.rb +24 -0
  84. data/spec/integration/aws_subnet_spec.rb +51 -2
  85. data/spec/integration/aws_vpc_peering_connection_spec.rb +99 -0
  86. data/spec/integration/aws_vpc_spec.rb +73 -0
  87. data/spec/integration/load_balancer_spec.rb +101 -0
  88. data/spec/integration/machine_image_spec.rb +61 -6
  89. data/spec/integration/machine_spec.rb +26 -0
  90. data/spec/spec_helper.rb +3 -0
  91. data/spec/unit/{aws_driver → chef/provisioning/aws_driver}/credentials_spec.rb +0 -0
  92. data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +88 -0
  93. metadata +63 -20
  94. data/spec/integration/aws_tagged_items_spec.rb +0 -166
@@ -0,0 +1,73 @@
1
+ describe "AwsDhcpOptions" do
2
+ extend AWSSupport
3
+
4
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
5
+ with_aws "when connected to AWS" do
6
+
7
+ it "creates an aws_dhcp_options resource with maximum attributes" do
8
+ expect_recipe {
9
+ aws_dhcp_options 'test-dhcp-options' do
10
+ domain_name 'example.com'
11
+ domain_name_servers %w(8.8.8.8 8.8.4.4)
12
+ ntp_servers %w(8.8.8.8 8.8.4.4)
13
+ netbios_name_servers %w(8.8.8.8 8.8.4.4)
14
+ netbios_node_type 2
15
+ end
16
+ }.to create_an_aws_dhcp_options('test-dhcp-options', configuration: {
17
+ domain_name: 'example.com',
18
+ domain_name_servers: %w(8.8.8.8 8.8.4.4),
19
+ ntp_servers: %w(8.8.8.8 8.8.4.4),
20
+ netbios_name_servers: %w(8.8.8.8 8.8.4.4),
21
+ netbios_node_type: 2
22
+ }).and be_idempotent
23
+ end
24
+
25
+ it "creates aws_dhcp_options tags" do
26
+ expect_recipe {
27
+ aws_dhcp_options 'test-dhcp-options' do
28
+ aws_tags key1: "value"
29
+ end
30
+ }.to create_an_aws_dhcp_options('test-dhcp-options')
31
+ .and have_aws_dhcp_options_tags('test-dhcp-options',
32
+ {
33
+ 'Name' => 'test-dhcp-options',
34
+ 'key1' => 'value'
35
+ }
36
+ ).and be_idempotent
37
+ end
38
+
39
+ context "with existing tags" do
40
+ aws_dhcp_options 'test-dhcp-options' do
41
+ aws_tags key1: "value"
42
+ end
43
+
44
+ it "updates aws_dhcp_options tags" do
45
+ expect_recipe {
46
+ aws_dhcp_options 'test-dhcp-options' do
47
+ aws_tags key1: "value2", key2: nil
48
+ end
49
+ }.to have_aws_dhcp_options_tags('test-dhcp-options',
50
+ {
51
+ 'Name' => 'test-dhcp-options',
52
+ 'key1' => 'value2',
53
+ 'key2' => ''
54
+ }
55
+ ).and be_idempotent
56
+ end
57
+
58
+ it "removes all aws_dhcp_options tags except Name" do
59
+ expect_recipe {
60
+ aws_dhcp_options 'test-dhcp-options' do
61
+ aws_tags Hash.new
62
+ end
63
+ }.to have_aws_dhcp_options_tags('test-dhcp-options',
64
+ {
65
+ 'Name' => 'test-dhcp-options'
66
+ }
67
+ ).and be_idempotent
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -44,6 +44,103 @@ describe Chef::Resource::AwsEbsVolume do
44
44
  .and be_idempotent
45
45
  end
46
46
 
47
+ # These tests are testing the tagging functionality - they use some example resources rather
48
+ # because these are integration tests so we cannot make a mock resource.
49
+ it "aws_ebs_volume 'test_volume' created with default Name tag" do
50
+ expect_recipe {
51
+ aws_ebs_volume "test_volume"
52
+ }.to create_an_aws_ebs_volume('test_volume'
53
+ ).and have_aws_ebs_volume_tags('test_volume',
54
+ { 'Name' => 'test_volume' }
55
+ ).and be_idempotent
56
+ end
57
+
58
+ it "allows users to specify a unique Name tag" do
59
+ expect_recipe {
60
+ aws_ebs_volume "test_volume_2" do
61
+ aws_tags :Name => 'test_volume_new'
62
+ end
63
+ }.to create_an_aws_ebs_volume('test_volume_2'
64
+ ).and have_aws_ebs_volume_tags('test_volume_2',
65
+ { 'Name' => 'test_volume_new' }
66
+ ).and be_idempotent
67
+ end
68
+
69
+ it "allows tags to be specified as strings or symbols" do
70
+ expect_recipe {
71
+ aws_ebs_volume "test_volume" do
72
+ aws_tags({
73
+ :key1 => :symbol,
74
+ 'key2' => :symbol,
75
+ :key3 => 'string',
76
+ 'key4' => 'string'
77
+ })
78
+ end
79
+ }.to create_an_aws_ebs_volume('test_volume'
80
+ ).and have_aws_ebs_volume_tags('test_volume',
81
+ {
82
+ 'key1' => 'symbol',
83
+ 'key2' => 'symbol',
84
+ 'key3' => 'string',
85
+ 'key4' => 'string'
86
+ }
87
+ ).and be_idempotent
88
+ end
89
+
90
+ context "when there are existing tags" do
91
+ before(:each) do
92
+ converge {
93
+ aws_ebs_volume "test_volume_a" do
94
+ aws_tags :byebye => 'true'
95
+ end
96
+ }
97
+ end
98
+
99
+ after(:each) do
100
+ converge {
101
+ aws_ebs_volume "test_volume_a" do
102
+ action :purge
103
+ end
104
+ }
105
+ end
106
+
107
+ it "updates the tags" do
108
+ expect_recipe {
109
+ aws_ebs_volume "test_volume_a" do
110
+ aws_tags 'Name' => 'test_volume_b', :project => 'X'
111
+ end
112
+ }.to have_aws_ebs_volume_tags('test_volume_a',
113
+ {
114
+ 'Name' => 'test_volume_b',
115
+ 'project' => 'X'
116
+ }
117
+ ).and be_idempotent
118
+ end
119
+
120
+ it "deletes the tags" do
121
+ expect_recipe {
122
+ aws_ebs_volume "test_volume_a" do
123
+ aws_tags {}
124
+ end
125
+ }.to have_aws_ebs_volume_tags('test_volume_a',
126
+ {
127
+ 'Name' => 'test_volume_a',
128
+ }
129
+ ).and be_idempotent
130
+ end
131
+
132
+ it "aws_ebs_volume 'test_volume' tags are not changed when not updated" do
133
+ expect_recipe {
134
+ #aws_ebs_volume "test_volume_a"
135
+ }.to have_aws_ebs_volume_tags('test_volume_a',
136
+ {
137
+ 'Name' => 'test_volume_a',
138
+ 'byebye' => 'true'
139
+ }
140
+ )
141
+ end
142
+ end
143
+
47
144
  end
48
145
  end
49
146
  end
@@ -102,6 +102,57 @@ describe Chef::Resource::AwsNetworkAcl do
102
102
  ).and be_idempotent
103
103
  end
104
104
  end
105
+
106
+ it "creates aws_network_acl tags" do
107
+ expect_recipe {
108
+ aws_network_acl 'test_network_acl' do
109
+ vpc 'test_vpc'
110
+ aws_tags key1: "value"
111
+ end
112
+ }.to create_an_aws_network_acl('test_network_acl')
113
+ .and have_aws_network_acl_tags('test_network_acl',
114
+ {
115
+ 'Name' => 'test_network_acl',
116
+ 'key1' => 'value'
117
+ }
118
+ ).and be_idempotent
119
+ end
120
+
121
+ context "with existing tags" do
122
+ aws_network_acl 'test_network_acl' do
123
+ vpc 'test_vpc'
124
+ aws_tags key1: "value"
125
+ end
126
+
127
+ it "updates aws_network_acl tags" do
128
+ expect_recipe {
129
+ aws_network_acl 'test_network_acl' do
130
+ vpc 'test_vpc'
131
+ aws_tags key1: "value2", key2: nil
132
+ end
133
+ }.to have_aws_network_acl_tags('test_network_acl',
134
+ {
135
+ 'Name' => 'test_network_acl',
136
+ 'key1' => 'value2',
137
+ 'key2' => ''
138
+ }
139
+ ).and be_idempotent
140
+ end
141
+
142
+ it "removes all aws_network_acl tags except Name" do
143
+ expect_recipe {
144
+ aws_network_acl 'test_network_acl' do
145
+ vpc 'test_vpc'
146
+ aws_tags {}
147
+ end
148
+ }.to have_aws_network_acl_tags('test_network_acl',
149
+ {
150
+ 'Name' => 'test_network_acl'
151
+ }
152
+ ).and be_idempotent
153
+ end
154
+ end
155
+
105
156
  end
106
157
  end
107
158
  end
@@ -0,0 +1,89 @@
1
+ describe "AwsNetworkInterface" do
2
+ extend AWSSupport
3
+
4
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
5
+ with_aws "when connected to AWS" do
6
+
7
+ context "setting up public VPC", :super_slow do
8
+
9
+ # Putting this in its own context so it doesn't slow down other tests
10
+ setup_public_vpc
11
+
12
+ it "creates an aws_network_interface resource with maximum attributes" do
13
+ expect_recipe {
14
+ machine "test_machine" do
15
+ machine_options bootstrap_options: {
16
+ subnet_id: 'test_public_subnet',
17
+ security_group_ids: ['test_security_group']
18
+ }
19
+ action :allocate
20
+ end
21
+
22
+ aws_network_interface 'test_network_interface' do
23
+ subnet 'test_public_subnet'
24
+ private_ip_address '10.0.0.25'
25
+ description "test_network_interface"
26
+ security_groups ['test_security_group']
27
+ machine "test_machine"
28
+ device_index 1
29
+ end
30
+ }.to create_an_aws_instance('test_machine'
31
+ ).and create_an_aws_network_interface('test_network_interface'
32
+ ).and be_idempotent
33
+ end
34
+
35
+ it "creates aws_network_interface tags" do
36
+ expect_recipe {
37
+ aws_network_interface 'test_network_interface' do
38
+ subnet 'test_public_subnet'
39
+ aws_tags key1: "value"
40
+ end
41
+ }.to create_an_aws_network_interface('test_network_interface')
42
+ .and have_aws_network_interface_tags('test_network_interface',
43
+ {
44
+ 'Name' => 'test_network_interface',
45
+ 'key1' => 'value'
46
+ }
47
+ ).and be_idempotent
48
+ end
49
+
50
+ context "with existing tags" do
51
+ aws_network_interface 'test_network_interface' do
52
+ subnet 'test_public_subnet'
53
+ aws_tags key1: "value"
54
+ end
55
+
56
+ it "updates aws_network_interface tags" do
57
+ expect_recipe {
58
+ aws_network_interface 'test_network_interface' do
59
+ subnet 'test_public_subnet'
60
+ aws_tags key1: "value2", key2: nil
61
+ end
62
+ }.to have_aws_network_interface_tags('test_network_interface',
63
+ {
64
+ 'Name' => 'test_network_interface',
65
+ 'key1' => 'value2',
66
+ 'key2' => ''
67
+ }
68
+ ).and be_idempotent
69
+ end
70
+
71
+ it "removes all aws_network_interface tags except Name" do
72
+ expect_recipe {
73
+ aws_network_interface 'test_network_interface' do
74
+ subnet 'test_public_subnet'
75
+ aws_tags {}
76
+ end
77
+ }.to have_aws_network_interface_tags('test_network_interface',
78
+ {
79
+ 'Name' => 'test_network_interface'
80
+ }
81
+ ).and be_idempotent
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Resource::AwsRdsInstance do
4
+ extend AWSSupport
5
+
6
+ when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
7
+ with_aws "with a connection to AWS, a VPC, two subnets, and a db subnet group" do
8
+
9
+ azs = []
10
+ driver.ec2.availability_zones.each do |az|
11
+ azs << az
12
+ end
13
+ az_1 = azs[0].name
14
+ az_2 = azs[1].name
15
+
16
+ aws_vpc "test_vpc" do
17
+ cidr_block '10.0.5.0/24'
18
+ internet_gateway true
19
+ end
20
+
21
+ aws_subnet "test_subnet" do
22
+ vpc 'test_vpc'
23
+ cidr_block "10.0.5.0/26"
24
+ availability_zone az_1
25
+ end
26
+
27
+ aws_subnet "test_subnet_2" do
28
+ vpc 'test_vpc'
29
+ cidr_block "10.0.5.64/26"
30
+ availability_zone az_2
31
+ end
32
+
33
+ aws_rds_subnet_group "test-db-subnet-group" do
34
+ description "some_description"
35
+ subnets ["test_subnet", test_subnet_2.aws_object.id]
36
+ end
37
+
38
+ it "aws_rds_instance 'test-rds-instance' creates an rds instance that can parse the aws_rds_subnet_group" do
39
+ expect_recipe {
40
+ aws_rds_instance "test-rds-instance" do
41
+ engine "postgres"
42
+ publicly_accessible false
43
+ db_instance_class "db.t1.micro"
44
+ master_username "thechief"
45
+ master_user_password "securesecure" # 2x security
46
+ multi_az false
47
+ allocated_storage 5
48
+ db_subnet_group_name "test-db-subnet-group"
49
+ end
50
+ }.to create_an_aws_rds_instance('test-rds-instance',
51
+ engine: 'postgres',
52
+ multi_az: false,
53
+ db_instance_class: "db.t1.micro",
54
+ master_username: "thechief",
55
+ ).and be_idempotent
56
+ i = driver.rds.client.describe_db_instances(:db_instance_identifier => "test-rds-instance")[:db_instances].first
57
+ expect(i[:db_subnet_group][:db_subnet_group_name]).to eq("test-db-subnet-group")
58
+ expect(i[:publicly_accessible]).to eq(false)
59
+ end
60
+
61
+ it "aws_rds_instance prefers explicit options" do
62
+ expect_recipe {
63
+ aws_rds_instance "test-rds-instance2" do
64
+ engine "postgres"
65
+ publicly_accessible false
66
+ db_instance_class "db.t1.micro"
67
+ master_username "thechief"
68
+ master_user_password "securesecure"
69
+ multi_az false
70
+ allocated_storage 5
71
+ additional_options(multi_az: true, backup_retention_period: 2)
72
+ end
73
+ }.to create_an_aws_rds_instance('test-rds-instance2',
74
+ engine: 'postgres',
75
+ multi_az: false,
76
+ db_instance_class: "db.t1.micro",
77
+ master_username: "thechief",
78
+ backup_retention_period: 2)
79
+
80
+ end
81
+
82
+ tagging_id = Random.rand(1000)
83
+
84
+ it "creates aws_rds_instance tags" do
85
+ expect_recipe {
86
+ aws_rds_instance "test-rds-instance-tagging-#{tagging_id}" do
87
+ aws_tags key1: "value"
88
+ allocated_storage 5
89
+ db_instance_class "db.t1.micro"
90
+ engine "postgres"
91
+ master_username "thechief"
92
+ master_user_password "securesecure"
93
+ end
94
+ }.to create_an_aws_rds_instance("test-rds-instance-tagging-#{tagging_id}")
95
+ .and have_aws_rds_instance_tags("test-rds-instance-tagging-#{tagging_id}",
96
+ {
97
+ 'key1' => 'value'
98
+ }
99
+ ).and be_idempotent
100
+ end
101
+
102
+ # if we use let, the tagging_id method is not available in the context block
103
+ tagging_id = Random.rand(1000)
104
+
105
+ context "with existing tags" do
106
+ aws_rds_instance "test-rds-instance-tagging-#{tagging_id}" do
107
+ aws_tags key1: "value"
108
+ allocated_storage 5
109
+ db_instance_class "db.t1.micro"
110
+ engine "postgres"
111
+ master_username "thechief"
112
+ master_user_password "securesecure"
113
+ end
114
+
115
+ it "updates aws_rds_instance tags" do
116
+ expect_recipe {
117
+ aws_rds_instance "test-rds-instance-tagging-#{tagging_id}" do
118
+ aws_tags key1: "value2", key2: nil
119
+ allocated_storage 5
120
+ db_instance_class "db.t1.micro"
121
+ engine "postgres"
122
+ master_username "thechief"
123
+ master_user_password "securesecure"
124
+ end
125
+ }.to have_aws_rds_instance_tags("test-rds-instance-tagging-#{tagging_id}",
126
+ {
127
+ 'key1' => 'value2',
128
+ 'key2' => nil
129
+ }
130
+ ).and be_idempotent
131
+ end
132
+
133
+ it "removes all aws_rds_instance tags" do
134
+ expect_recipe {
135
+ aws_rds_instance "test-rds-instance-tagging-#{tagging_id}" do
136
+ aws_tags {}
137
+ allocated_storage 5
138
+ db_instance_class "db.t1.micro"
139
+ engine "postgres"
140
+ master_username "thechief"
141
+ master_user_password "securesecure"
142
+ end
143
+ }.to have_aws_rds_instance_tags("test-rds-instance-tagging-#{tagging_id}", {}
144
+ ).and be_idempotent
145
+ end
146
+ end
147
+
148
+ end
149
+ end
150
+ end