chef-provisioning-aws 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/README.md +70 -69
- data/Rakefile +22 -2
- data/lib/chef/provider/aws_auto_scaling_group.rb +3 -2
- data/lib/chef/provider/aws_cache_cluster.rb +3 -2
- data/lib/chef/provider/aws_cache_replication_group.rb +5 -4
- data/lib/chef/provider/aws_cache_subnet_group.rb +5 -4
- data/lib/chef/provider/aws_cloudsearch_domain.rb +163 -0
- data/lib/chef/provider/aws_dhcp_options.rb +9 -6
- data/lib/chef/provider/aws_ebs_volume.rb +7 -3
- data/lib/chef/provider/aws_eip_address.rb +8 -7
- data/lib/chef/provider/aws_image.rb +8 -3
- data/lib/chef/provider/aws_instance.rb +14 -2
- data/lib/chef/provider/aws_key_pair.rb +2 -1
- data/lib/chef/provider/aws_launch_configuration.rb +4 -2
- data/lib/chef/provider/aws_load_balancer.rb +18 -0
- data/lib/chef/provider/aws_network_acl.rb +6 -2
- data/lib/chef/provider/aws_network_interface.rb +11 -24
- data/lib/chef/provider/aws_rds_instance.rb +66 -0
- data/lib/chef/provider/aws_rds_subnet_group.rb +89 -0
- data/lib/chef/provider/aws_route_table.rb +42 -23
- data/lib/chef/provider/aws_s3_bucket.rb +32 -8
- data/lib/chef/provider/aws_security_group.rb +11 -4
- data/lib/chef/provider/aws_server_certificate.rb +23 -0
- data/lib/chef/provider/aws_sns_topic.rb +4 -3
- data/lib/chef/provider/aws_sqs_queue.rb +3 -2
- data/lib/chef/provider/aws_subnet.rb +10 -7
- data/lib/chef/provider/aws_vpc.rb +54 -21
- data/lib/chef/provider/aws_vpc_peering_connection.rb +88 -0
- data/lib/chef/provisioning/aws_driver.rb +8 -0
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +45 -76
- data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +11 -0
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +14 -2
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +2 -8
- data/lib/chef/provisioning/aws_driver/aws_taggable.rb +18 -0
- data/lib/chef/provisioning/aws_driver/aws_tagger.rb +61 -0
- data/lib/chef/provisioning/aws_driver/credentials2.rb +51 -0
- data/lib/chef/provisioning/aws_driver/driver.rb +214 -162
- data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +64 -0
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +39 -0
- data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +92 -0
- data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -0
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_cache_cluster.rb +1 -2
- data/lib/chef/resource/aws_cloudsearch_domain.rb +46 -0
- data/lib/chef/resource/aws_dhcp_options.rb +2 -0
- data/lib/chef/resource/aws_ebs_volume.rb +3 -1
- data/lib/chef/resource/aws_eip_address.rb +0 -3
- data/lib/chef/resource/aws_image.rb +3 -0
- data/lib/chef/resource/aws_instance.rb +7 -2
- data/lib/chef/resource/aws_internet_gateway.rb +2 -0
- data/lib/chef/resource/aws_load_balancer.rb +3 -0
- data/lib/chef/resource/aws_network_acl.rb +2 -0
- data/lib/chef/resource/aws_network_interface.rb +3 -1
- data/lib/chef/resource/aws_rds_instance.rb +42 -0
- data/lib/chef/resource/aws_rds_subnet_group.rb +29 -0
- data/lib/chef/resource/aws_route_table.rb +7 -5
- data/lib/chef/resource/aws_s3_bucket.rb +3 -0
- data/lib/chef/resource/aws_security_group.rb +2 -7
- data/lib/chef/resource/aws_server_certificate.rb +21 -0
- data/lib/chef/resource/aws_subnet.rb +2 -0
- data/lib/chef/resource/aws_vpc.rb +4 -1
- data/lib/chef/resource/aws_vpc_peering_connection.rb +73 -0
- data/spec/acceptance/aws_ebs_volume/nodes/ettores-mbp.lan.json +3 -0
- data/spec/aws_support.rb +25 -8
- data/spec/aws_support/aws_resource_run_wrapper.rb +5 -1
- data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +19 -0
- data/spec/aws_support/matchers/create_an_aws_object.rb +1 -1
- data/spec/aws_support/matchers/destroy_an_aws_object.rb +1 -1
- data/spec/aws_support/matchers/have_aws_object_tags.rb +9 -15
- data/spec/aws_support/matchers/match_an_aws_object.rb +1 -1
- data/spec/aws_support/matchers/update_an_aws_object.rb +1 -1
- data/spec/integration/aws_cloudsearch_domain_spec.rb +31 -0
- data/spec/integration/aws_dhcp_options_spec.rb +73 -0
- data/spec/integration/aws_ebs_volume_spec.rb +97 -0
- data/spec/integration/aws_network_acl_spec.rb +51 -0
- data/spec/integration/aws_network_interface_spec.rb +89 -0
- data/spec/integration/aws_rds_instance_spec.rb +150 -0
- data/spec/integration/aws_rds_subnet_group_spec.rb +105 -0
- data/spec/integration/aws_route_table_spec.rb +94 -7
- data/spec/integration/aws_s3_bucket_spec.rb +88 -0
- data/spec/integration/aws_security_group_spec.rb +47 -0
- data/spec/integration/aws_server_certificate_spec.rb +24 -0
- data/spec/integration/aws_subnet_spec.rb +51 -2
- data/spec/integration/aws_vpc_peering_connection_spec.rb +99 -0
- data/spec/integration/aws_vpc_spec.rb +73 -0
- data/spec/integration/load_balancer_spec.rb +101 -0
- data/spec/integration/machine_image_spec.rb +61 -6
- data/spec/integration/machine_spec.rb +26 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/{aws_driver → chef/provisioning/aws_driver}/credentials_spec.rb +0 -0
- data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +88 -0
- metadata +63 -20
- data/spec/integration/aws_tagged_items_spec.rb +0 -166
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chef::Resource::AwsVpcPeeringConnection do
|
4
|
+
extend AWSSupport
|
5
|
+
|
6
|
+
when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
|
7
|
+
with_aws "with 2 VPCs" do
|
8
|
+
|
9
|
+
aws_vpc "test_vpc" do
|
10
|
+
cidr_block '10.0.0.0/24'
|
11
|
+
internet_gateway false
|
12
|
+
end
|
13
|
+
|
14
|
+
aws_vpc "test_vpc_2" do
|
15
|
+
cidr_block '11.0.0.0/24'
|
16
|
+
internet_gateway false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "aws_peering_connection 'test_vpc' with no attributes fails to create a VPC peering connection (must specify vpc and peer_vpc)" do
|
20
|
+
expect_converge {
|
21
|
+
aws_vpc_peering_connection 'test_peering_connection' do
|
22
|
+
end
|
23
|
+
}.to raise_error(RuntimeError, /VCP peering connection create action for 'test_peering_connection' requires the 'vpc' attribute./)
|
24
|
+
|
25
|
+
expect_converge {
|
26
|
+
aws_vpc_peering_connection 'test_peering_connection' do
|
27
|
+
vpc 'test_vpc'
|
28
|
+
end
|
29
|
+
}.to raise_error(RuntimeError, /VCP peering connection create action for 'test_peering_connection' requires the 'peer_vpc' attribute./)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "aws_peering_connection 'test_peering_connection' with minimal parameters creates a active connection" do
|
33
|
+
expect_recipe {
|
34
|
+
aws_vpc_peering_connection 'test_peering_connection' do
|
35
|
+
vpc 'test_vpc'
|
36
|
+
peer_vpc 'test_vpc_2'
|
37
|
+
end
|
38
|
+
}.to create_an_aws_vpc_peering_connection('test_peering_connection',
|
39
|
+
:'requester_vpc_info.vpc_id' => test_vpc.aws_object.id,
|
40
|
+
:'accepter_vpc_info.vpc_id' => test_vpc_2.aws_object.id,
|
41
|
+
:'status.code' => 'active'
|
42
|
+
).and be_idempotent
|
43
|
+
end
|
44
|
+
|
45
|
+
it "aws_peering_connection 'test_peering_connection' with peer_owner_id set to be the actual account id, creates an active peering" do
|
46
|
+
expect_recipe {
|
47
|
+
aws_vpc_peering_connection 'test_peering_connection' do
|
48
|
+
vpc 'test_vpc'
|
49
|
+
peer_vpc 'test_vpc_2'
|
50
|
+
peer_owner_id driver.account_id
|
51
|
+
end
|
52
|
+
}.to create_an_aws_vpc_peering_connection('test_peering_connection',
|
53
|
+
:'requester_vpc_info.vpc_id' => test_vpc.aws_object.id,
|
54
|
+
:'accepter_vpc_info.vpc_id' => test_vpc_2.aws_object.id,
|
55
|
+
:'status.code' => 'active'
|
56
|
+
).and be_idempotent
|
57
|
+
end
|
58
|
+
|
59
|
+
it "aws_peering_connection 'test_peering_connection' with a false peer_owner_id, creates a failed peering connection" do
|
60
|
+
expect_recipe {
|
61
|
+
aws_vpc_peering_connection 'test_peering_connection' do
|
62
|
+
vpc 'test_vpc'
|
63
|
+
peer_vpc 'test_vpc_2'
|
64
|
+
peer_owner_id '000000000000'
|
65
|
+
end
|
66
|
+
}.to create_an_aws_vpc_peering_connection('test_peering_connection',
|
67
|
+
:'requester_vpc_info.vpc_id' => test_vpc.aws_object.id,
|
68
|
+
:'accepter_vpc_info.vpc_id' => test_vpc_2.aws_object.id,
|
69
|
+
:'status.code' => 'failed'
|
70
|
+
).and be_idempotent
|
71
|
+
end
|
72
|
+
|
73
|
+
it "aws_peering_connection 'test_peering_connection' with accept action, accepts a pending peering connection" do
|
74
|
+
pcx = nil
|
75
|
+
ec2_resource = driver.ec2_resource
|
76
|
+
expect_recipe {
|
77
|
+
ruby_block "fetch VPC objects" do
|
78
|
+
block do
|
79
|
+
test_vpc = Chef::Resource::AwsVpc.get_aws_object("test_vpc", run_context: run_context)
|
80
|
+
test_vpc_2 = Chef::Resource::AwsVpc.get_aws_object("test_vpc_2", run_context: run_context)
|
81
|
+
pcx = ec2_resource.vpc(test_vpc.id).request_vpc_peering_connection({ :peer_vpc_id => test_vpc_2.id })
|
82
|
+
end
|
83
|
+
end
|
84
|
+
}.to match_an_aws_vpc_peering_connection(pcx.id,
|
85
|
+
:'status.code' => 'pending-acceptance'
|
86
|
+
)
|
87
|
+
|
88
|
+
expect_recipe {
|
89
|
+
aws_vpc_peering_connection pcx.id do
|
90
|
+
action :accept
|
91
|
+
end
|
92
|
+
}.to match_an_aws_vpc_peering_connection(pcx.id,
|
93
|
+
:'status.code' => 'active'
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -114,12 +114,85 @@ describe Chef::Resource::AwsVpc do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
it "creates aws_vpc tags" do
|
118
|
+
expect_recipe {
|
119
|
+
aws_vpc 'test_vpc' do
|
120
|
+
cidr_block '10.0.0.0/24'
|
121
|
+
aws_tags key1: "value"
|
122
|
+
end
|
123
|
+
}.to create_an_aws_vpc('test_vpc')
|
124
|
+
.and have_aws_vpc_tags('test_vpc',
|
125
|
+
{
|
126
|
+
'Name' => 'test_vpc',
|
127
|
+
'key1' => 'value'
|
128
|
+
}
|
129
|
+
).and be_idempotent
|
130
|
+
end
|
131
|
+
|
132
|
+
context "with existing tags" do
|
133
|
+
aws_vpc 'test_vpc' do
|
134
|
+
cidr_block '10.0.0.0/24'
|
135
|
+
aws_tags key1: "value"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "updates aws_vpc tags" do
|
139
|
+
expect_recipe {
|
140
|
+
aws_vpc 'test_vpc' do
|
141
|
+
aws_tags key1: "value2", key2: nil
|
142
|
+
end
|
143
|
+
}.to have_aws_vpc_tags('test_vpc',
|
144
|
+
{
|
145
|
+
'Name' => 'test_vpc',
|
146
|
+
'key1' => 'value2',
|
147
|
+
'key2' => ''
|
148
|
+
}
|
149
|
+
).and be_idempotent
|
150
|
+
end
|
151
|
+
|
152
|
+
it "removes all aws_vpc tags except Name" do
|
153
|
+
expect_recipe {
|
154
|
+
aws_vpc 'test_vpc' do
|
155
|
+
aws_tags {}
|
156
|
+
end
|
157
|
+
}.to have_aws_vpc_tags('test_vpc',
|
158
|
+
{
|
159
|
+
'Name' => 'test_vpc'
|
160
|
+
}
|
161
|
+
).and be_idempotent
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
117
165
|
it "aws_vpc 'vpc' with no attributes fails to create a VPC (must specify cidr_block)" do
|
118
166
|
expect_converge {
|
119
167
|
aws_vpc 'test_vpc' do
|
120
168
|
end
|
121
169
|
}.to raise_error(AWS::Core::OptionGrammar::FormatError, /expected string value for option cidr_block/)
|
122
170
|
end
|
171
|
+
|
172
|
+
context "When having two VPC's and a peering connection between them" do
|
173
|
+
aws_vpc "test_vpc_1" do
|
174
|
+
cidr_block '20.0.0.0/24'
|
175
|
+
end
|
176
|
+
|
177
|
+
aws_vpc "test_vpc_2" do
|
178
|
+
cidr_block '21.0.0.0/24'
|
179
|
+
end
|
180
|
+
|
181
|
+
aws_vpc_peering_connection "test_peering_connection" do
|
182
|
+
vpc "test_vpc_1"
|
183
|
+
peer_vpc "test_vpc_2"
|
184
|
+
end
|
185
|
+
|
186
|
+
it "deletes the peer connection when one of the vpc's is deleted." do
|
187
|
+
expect_recipe {
|
188
|
+
aws_vpc "test_vpc_1" do
|
189
|
+
action :purge
|
190
|
+
end
|
191
|
+
}.to match_an_aws_vpc_peering_connection('test_peering_connection',
|
192
|
+
:'status.code' => 'deleted'
|
193
|
+
)
|
194
|
+
end
|
195
|
+
end
|
123
196
|
end
|
124
197
|
end
|
125
198
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chef::Resource::LoadBalancer 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
|
+
purge_all
|
10
|
+
setup_public_vpc
|
11
|
+
|
12
|
+
it "creates a load_balancer with the maximum attributes" do
|
13
|
+
expect_recipe {
|
14
|
+
load_balancer 'test-load-balancer' do
|
15
|
+
load_balancer_options({
|
16
|
+
listeners: [{
|
17
|
+
:port => 80,
|
18
|
+
:protocol => :http,
|
19
|
+
:instance_port => 80,
|
20
|
+
:instance_protocol => :http,
|
21
|
+
}],
|
22
|
+
subnets: ["test_public_subnet"],
|
23
|
+
security_groups: ["test_security_group"],
|
24
|
+
health_check: {
|
25
|
+
target: "HTTP:80/",
|
26
|
+
interval: 10,
|
27
|
+
timeout: 5,
|
28
|
+
unhealthy_threshold: 2,
|
29
|
+
healthy_threshold: 2
|
30
|
+
}
|
31
|
+
# 'only 1 of subnets or availability_zones may be specified'
|
32
|
+
# availability_zones: [test_public_subnet.aws_object.availability_zone_name]
|
33
|
+
})
|
34
|
+
end
|
35
|
+
}.to create_an_aws_load_balancer('test-load-balancer', {
|
36
|
+
listeners: [{
|
37
|
+
:port => 80,
|
38
|
+
:protocol => :http,
|
39
|
+
:instance_port => 80,
|
40
|
+
:instance_protocol => :http,
|
41
|
+
}],
|
42
|
+
subnets: [test_public_subnet.aws_object],
|
43
|
+
security_groups: [test_security_group.aws_object],
|
44
|
+
health_check: {
|
45
|
+
target: "HTTP:80/",
|
46
|
+
interval: 10,
|
47
|
+
timeout: 5,
|
48
|
+
unhealthy_threshold: 2,
|
49
|
+
healthy_threshold: 2
|
50
|
+
}
|
51
|
+
}
|
52
|
+
).and be_idempotent
|
53
|
+
end
|
54
|
+
|
55
|
+
it "creates load_balancer tags" do
|
56
|
+
expect_recipe {
|
57
|
+
load_balancer 'test-load-balancer' do
|
58
|
+
aws_tags key1: "value"
|
59
|
+
load_balancer_options :availability_zones => ['us-east-1d']
|
60
|
+
end
|
61
|
+
}.to create_an_aws_load_balancer('test-load-balancer')
|
62
|
+
.and have_aws_load_balancer_tags('test-load-balancer',
|
63
|
+
{
|
64
|
+
'key1' => 'value'
|
65
|
+
}
|
66
|
+
).and be_idempotent
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with existing tags" do
|
70
|
+
load_balancer 'test-load-balancer' do
|
71
|
+
aws_tags key1: "value"
|
72
|
+
load_balancer_options :availability_zones => ['us-east-1d']
|
73
|
+
end
|
74
|
+
|
75
|
+
it "updates aws_load_balancer tags" do
|
76
|
+
expect_recipe {
|
77
|
+
load_balancer 'test-load-balancer' do
|
78
|
+
aws_tags key1: "value2", key2: nil
|
79
|
+
end
|
80
|
+
}.to have_aws_load_balancer_tags('test-load-balancer',
|
81
|
+
{
|
82
|
+
'key1' => 'value2',
|
83
|
+
'key2' => ''
|
84
|
+
}
|
85
|
+
).and be_idempotent
|
86
|
+
end
|
87
|
+
|
88
|
+
it "removes all aws_load_balancer tags" do
|
89
|
+
expect_recipe {
|
90
|
+
load_balancer 'test-load-balancer' do
|
91
|
+
aws_tags Hash.new
|
92
|
+
end
|
93
|
+
}.to have_aws_load_balancer_tags('test-load-balancer',
|
94
|
+
Hash.new
|
95
|
+
).and be_idempotent
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -17,7 +17,8 @@ describe Chef::Resource::MachineImage do
|
|
17
17
|
machine_image 'test_machine_image' do
|
18
18
|
machine_options bootstrap_options: {
|
19
19
|
subnet_id: 'test_public_subnet',
|
20
|
-
key_name: 'test_key_pair'
|
20
|
+
key_name: 'test_key_pair',
|
21
|
+
instance_type: 'm3.medium'
|
21
22
|
}
|
22
23
|
end
|
23
24
|
}.to create_an_aws_image('test_machine_image',
|
@@ -31,19 +32,73 @@ describe Chef::Resource::MachineImage do
|
|
31
32
|
chef_config[:log_level] = :warn
|
32
33
|
end
|
33
34
|
|
35
|
+
aws_key_pair 'test_key_pair' do
|
36
|
+
allow_overwrite true
|
37
|
+
end
|
38
|
+
|
34
39
|
it "machine_image with no options can create an image in the VPC", :super_slow do
|
35
40
|
expect_recipe {
|
36
|
-
aws_key_pair 'test_key_pair' do
|
37
|
-
allow_overwrite true
|
38
|
-
end
|
39
41
|
machine_image 'test_machine_image' do
|
40
|
-
machine_options bootstrap_options: {
|
42
|
+
machine_options bootstrap_options: {
|
43
|
+
key_name: 'test_key_pair',
|
44
|
+
instance_type: 'm3.medium'
|
45
|
+
}
|
41
46
|
end
|
42
47
|
}.to create_an_aws_image('test_machine_image',
|
43
48
|
name: 'test_machine_image'
|
44
|
-
).and create_an_aws_key_pair('test_key_pair'
|
45
49
|
).and be_idempotent
|
46
50
|
end
|
51
|
+
|
52
|
+
it "creates aws_image tags", :super_slow do
|
53
|
+
expect_recipe {
|
54
|
+
machine_image 'test_machine_image' do
|
55
|
+
machine_options bootstrap_options: {
|
56
|
+
key_name: 'test_key_pair',
|
57
|
+
instance_type: 'm3.medium'
|
58
|
+
}
|
59
|
+
aws_tags key1: "value"
|
60
|
+
end
|
61
|
+
}.to create_an_aws_image('test_machine_image')
|
62
|
+
.and have_aws_image_tags('test_machine_image',
|
63
|
+
{
|
64
|
+
'key1' => 'value'
|
65
|
+
}
|
66
|
+
).and be_idempotent
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with existing tags" do
|
70
|
+
machine_image 'test_machine_image' do
|
71
|
+
machine_options bootstrap_options: {
|
72
|
+
key_name: 'test_key_pair',
|
73
|
+
instance_type: 'm3.medium'
|
74
|
+
}
|
75
|
+
aws_tags key1: "value"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "updates aws_image tags", :super_slow do
|
79
|
+
expect_recipe {
|
80
|
+
machine_image 'test_machine_image' do
|
81
|
+
aws_tags key1: "value2", key2: nil
|
82
|
+
end
|
83
|
+
}.to have_aws_image_tags('test_machine_image',
|
84
|
+
{
|
85
|
+
'key1' => 'value2',
|
86
|
+
'key2' => ''
|
87
|
+
}
|
88
|
+
).and be_idempotent
|
89
|
+
end
|
90
|
+
|
91
|
+
it "removes all aws_image tags", :super_slow do
|
92
|
+
expect_recipe {
|
93
|
+
machine_image 'test_machine_image' do
|
94
|
+
aws_tags {}
|
95
|
+
end
|
96
|
+
}.to have_aws_image_tags('test_machine_image',
|
97
|
+
{}
|
98
|
+
).and be_idempotent
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
47
102
|
end
|
48
103
|
end
|
49
104
|
end
|
@@ -52,6 +52,32 @@ describe Chef::Resource::Machine do
|
|
52
52
|
source_dest_check: false
|
53
53
|
).and be_idempotent
|
54
54
|
end
|
55
|
+
|
56
|
+
it "machine with from_image option is created from correct image", :super_slow do
|
57
|
+
expect_recipe {
|
58
|
+
|
59
|
+
machine_image 'test_machine_ami' do
|
60
|
+
machine_options bootstrap_options: {
|
61
|
+
subnet_id: 'test_public_subnet',
|
62
|
+
key_name: 'test_key_pair'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
machine 'test_machine' do
|
67
|
+
from_image 'test_machine_ami'
|
68
|
+
machine_options bootstrap_options: {
|
69
|
+
subnet_id: 'test_public_subnet',
|
70
|
+
key_name: 'test_key_pair'
|
71
|
+
}
|
72
|
+
action :allocate
|
73
|
+
end
|
74
|
+
}.to create_an_aws_instance('test_machine',
|
75
|
+
image_id: driver.ec2.images.filter('name', 'test_machine_ami').first.image_id
|
76
|
+
).and create_an_aws_image('test_machine_ami',
|
77
|
+
name: 'test_machine_ami'
|
78
|
+
).and be_idempotent
|
79
|
+
end
|
80
|
+
|
55
81
|
end
|
56
82
|
|
57
83
|
with_aws "Without a VPC" do
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'chef/provisioning/aws_driver/driver'
|
2
|
+
require 'chef/provisioning/aws_driver/credentials2'
|
3
|
+
|
4
|
+
describe Chef::Provisioning::AWSDriver::Driver do
|
5
|
+
|
6
|
+
let(:driver) { Chef::Provisioning::AWSDriver::Driver.new("aws::us-east-1", {}) }
|
7
|
+
let(:aws_credentials) { double("credentials", :default => {
|
8
|
+
aws_access_key_id: "id",
|
9
|
+
aws_secret_access_key: "secret"
|
10
|
+
})}
|
11
|
+
let(:credentials2) { double("credentials2", :get_credentials => {})}
|
12
|
+
|
13
|
+
before do
|
14
|
+
expect_any_instance_of(Chef::Provisioning::AWSDriver::Driver).to receive(:aws_credentials).and_return(aws_credentials)
|
15
|
+
expect(AWS).to receive(:config) do |h|
|
16
|
+
expect(h).to include({
|
17
|
+
access_key_id: "id",
|
18
|
+
secret_access_key: "secret",
|
19
|
+
region: "us-east-1"
|
20
|
+
})
|
21
|
+
end
|
22
|
+
expect(Chef::Provisioning::AWSDriver::Credentials2).to receive(:new).and_return(credentials2)
|
23
|
+
expect(::Aws).to receive(:config).and_return({})
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#determine_remote_host" do
|
27
|
+
let(:machine_spec) { double("machine_spec", :reference => reference, :name => 'name') }
|
28
|
+
let(:instance) { double("instance", :private_ip_address => 'private', :dns_name => 'dns', :public_ip_address => 'public') }
|
29
|
+
|
30
|
+
context "when 'use_private_ip_for_ssh' is specified in the machine_spec.reference" do
|
31
|
+
let(:reference) { { 'use_private_ip_for_ssh' => true } }
|
32
|
+
it "returns the private ip" do
|
33
|
+
expect(driver.determine_remote_host(machine_spec, instance)).to eq('private')
|
34
|
+
expect(reference).to eq( {'transport_address_location' => :private_ip} )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when 'transport_address_location' is set to :private_ip" do
|
39
|
+
let(:reference) { { 'transport_address_location' => :private_ip } }
|
40
|
+
it "returns the private ip" do
|
41
|
+
expect(driver.determine_remote_host(machine_spec, instance)).to eq('private')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when 'transport_address_location' is set to :dns" do
|
46
|
+
let(:reference) { { 'transport_address_location' => :dns } }
|
47
|
+
it "returns the dns name" do
|
48
|
+
expect(driver.determine_remote_host(machine_spec, instance)).to eq('dns')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when 'transport_address_location' is set to :public_ip" do
|
53
|
+
let(:reference) { { 'transport_address_location' => :public_ip } }
|
54
|
+
it "returns the public ip" do
|
55
|
+
expect(driver.determine_remote_host(machine_spec, instance)).to eq('public')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when machine_spec.reference does not specify the transport type" do
|
60
|
+
let(:reference) { Hash.new }
|
61
|
+
|
62
|
+
context "when the machine does not have a public_ip_address" do
|
63
|
+
let(:instance) { double("instance", :private_ip_address => 'private', :public_ip_address => nil) }
|
64
|
+
|
65
|
+
it "returns the private ip" do
|
66
|
+
expect(driver.determine_remote_host(machine_spec, instance)).to eq('private')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the machine has a public_ip_address" do
|
71
|
+
let(:instance) { double("instance", :private_ip_address => 'private', :public_ip_address => 'public') }
|
72
|
+
|
73
|
+
it "returns the public ip" do
|
74
|
+
expect(driver.determine_remote_host(machine_spec, instance)).to eq('public')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when the machine does not have a public_ip_address or private_ip_address" do
|
79
|
+
let(:instance) { double("instance", :private_ip_address => nil, :public_ip_address => nil, :id => 'id') }
|
80
|
+
|
81
|
+
it "raises an error" do
|
82
|
+
expect {driver.determine_remote_host(machine_spec, instance)}.to raise_error("Server #{instance.id} has no private or public IP address!")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|