chef-provisioning-aws 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/Rakefile +8 -5
- data/chef-provisioning-aws.gemspec +3 -3
- data/lib/chef/provider/aws_cloudsearch_domain.rb +5 -3
- data/lib/chef/provider/aws_elasticsearch_domain.rb +131 -0
- data/lib/chef/provider/aws_key_pair.rb +2 -2
- data/lib/chef/provider/aws_rds_instance.rb +7 -5
- data/lib/chef/provider/aws_rds_subnet_group.rb +7 -7
- data/lib/chef/provider/aws_route_table.rb +5 -1
- data/lib/chef/provider/aws_server_certificate.rb +4 -3
- data/lib/chef/provisioning/aws_driver.rb +1 -0
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +2 -1
- data/lib/chef/provisioning/aws_driver/driver.rb +109 -38
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb +40 -0
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_eip_address.rb +4 -24
- data/lib/chef/resource/aws_elasticsearch_domain.rb +42 -0
- data/lib/chef/resource/aws_rds_instance.rb +12 -7
- data/lib/chef/resource/aws_route53_hosted_zone.rb +1 -1
- data/spec/aws_support.rb +2 -2
- data/spec/integration/aws_eip_address_spec.rb +32 -18
- data/spec/integration/aws_elasticsearch_domain_spec.rb +119 -0
- data/spec/integration/aws_key_pair_spec.rb +2 -1
- data/spec/integration/aws_rds_instance_spec.rb +3 -3
- data/spec/integration/aws_route53_hosted_zone_spec.rb +11 -0
- data/spec/integration/aws_route_table_spec.rb +40 -44
- data/spec/integration/aws_server_certificate_spec.rb +12 -0
- data/spec/integration/load_balancer_spec.rb +47 -1
- data/spec/integration/machine_spec.rb +32 -25
- metadata +28 -6
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'chef/provisioning/aws_driver/aws_tagger'
|
2
|
+
|
3
|
+
module Chef::Provisioning::AWSDriver::TaggingStrategy
|
4
|
+
class Elasticsearch
|
5
|
+
|
6
|
+
attr_reader :client, :arn, :desired_tags
|
7
|
+
|
8
|
+
def initialize(client, arn, desired_tags)
|
9
|
+
@client = client
|
10
|
+
@arn = arn
|
11
|
+
@desired_tags = desired_tags
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_tags
|
15
|
+
resp = client.list_tags({arn: arn})
|
16
|
+
Hash[resp.tag_list.map {|t| [t.key, t.value]}]
|
17
|
+
rescue ::Aws::ElasticsearchService::Errors::ResourceNotFoundException
|
18
|
+
Hash.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_tags(tags)
|
22
|
+
tags = tags.map {|k,v|
|
23
|
+
if v.nil?
|
24
|
+
{key: k}
|
25
|
+
else
|
26
|
+
{key: k, value: v}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
client.add_tags({
|
30
|
+
arn: arn,
|
31
|
+
tag_list: tags
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_tags(tag_keys)
|
36
|
+
client.remove_tags({arn: arn,
|
37
|
+
tag_keys: tag_keys})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'chef/provisioning/aws_driver/aws_resource_with_entry'
|
2
|
-
require 'ipaddr'
|
3
2
|
|
4
3
|
class Chef::Resource::AwsEipAddress < Chef::Provisioning::AWSDriver::AWSResourceWithEntry
|
5
4
|
aws_sdk_type AWS::EC2::ElasticIp, option_names: [ :public_ip ], id: :public_ip, managed_entry_id_name: 'public_ip', backcompat_data_bag_name: 'eip_addresses'
|
@@ -10,29 +9,10 @@ class Chef::Resource::AwsEipAddress < Chef::Provisioning::AWSDriver::AWSResource
|
|
10
9
|
attribute :machine, kind_of: [String, FalseClass]
|
11
10
|
attribute :associate_to_vpc, kind_of: [TrueClass, FalseClass]
|
12
11
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
# If the IP address is already allocated to your account, Chef will ensure it is
|
19
|
-
# linked to the current . Thus, this is a way to associate an existing AWS IP
|
20
|
-
# with Chef:
|
21
|
-
#
|
22
|
-
# ```ruby
|
23
|
-
# aws_eip_address 'frontend_ip' do
|
24
|
-
# public_ip '205.32.21.0'
|
25
|
-
# end
|
26
|
-
# ```
|
27
|
-
#
|
28
|
-
attribute :public_ip, kind_of: String, aws_id_attribute: true, coerce: proc { |v| IPAddr.new(v); v },
|
29
|
-
default: lazy {
|
30
|
-
begin
|
31
|
-
IPAddr.new(name)
|
32
|
-
name
|
33
|
-
rescue
|
34
|
-
end
|
35
|
-
}
|
12
|
+
# Like other aws_id_attributes, this is read-only - you cannot provide it and expect
|
13
|
+
# aws to honor it
|
14
|
+
attribute :public_ip, kind_of: String, aws_id_attribute: true,
|
15
|
+
default: lazy { name =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ ? name : nil }
|
36
16
|
|
37
17
|
def aws_object
|
38
18
|
driver, public_ip = get_driver_and_id
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'chef/provisioning/aws_driver/aws_resource'
|
2
|
+
|
3
|
+
module AWS
|
4
|
+
class Elasticsearch
|
5
|
+
class Domain
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Chef::Resource::AwsElasticsearchDomain < Chef::Provisioning::AWSDriver::AWSResource
|
11
|
+
include Chef::Provisioning::AWSDriver::AWSTaggable
|
12
|
+
|
13
|
+
aws_sdk_type ::AWS::Elasticsearch::Domain
|
14
|
+
|
15
|
+
attribute :domain_name, kind_of: String, name_attribute: true
|
16
|
+
|
17
|
+
# Cluster Config
|
18
|
+
attribute :instance_type, kind_of: String
|
19
|
+
attribute :instance_count, kind_of: Integer
|
20
|
+
attribute :dedicated_master_enabled, kind_of: [TrueClass, FalseClass]
|
21
|
+
attribute :dedicated_master_type, kind_of: String
|
22
|
+
attribute :dedicated_master_count, kind_of: Integer
|
23
|
+
attribute :zone_awareness_enabled, kind_of: [TrueClass, FalseClass]
|
24
|
+
|
25
|
+
# EBS Options
|
26
|
+
attribute :ebs_enabled, kind_of: [TrueClass, FalseClass]
|
27
|
+
attribute :volume_type, equal_to: ["standard", "gp2", "io1"]
|
28
|
+
attribute :volume_size, kind_of: Integer
|
29
|
+
attribute :iops, kind_of: Integer
|
30
|
+
|
31
|
+
# Snapshot Options
|
32
|
+
attribute :automated_snapshot_start_hour, kind_of: Integer
|
33
|
+
|
34
|
+
# Access Policies
|
35
|
+
attribute :access_policies, kind_of: String
|
36
|
+
|
37
|
+
def aws_object
|
38
|
+
driver.elasticsearch_client
|
39
|
+
.describe_elasticsearch_domains(domain_names: [domain_name])[:domain_status_list]
|
40
|
+
.find { |d| !d[:deleted] }
|
41
|
+
end
|
42
|
+
end
|
@@ -4,7 +4,7 @@ require 'chef/provisioning/aws_driver/aws_taggable'
|
|
4
4
|
class Chef::Resource::AwsRdsInstance < Chef::Provisioning::AWSDriver::AWSRDSResource
|
5
5
|
include Chef::Provisioning::AWSDriver::AWSTaggable
|
6
6
|
|
7
|
-
aws_sdk_type
|
7
|
+
aws_sdk_type ::Aws::RDS::DBInstance, id: :db_instance_identifier
|
8
8
|
|
9
9
|
attribute :db_instance_identifier, kind_of: String, name_attribute: true
|
10
10
|
|
@@ -28,12 +28,17 @@ class Chef::Resource::AwsRdsInstance < Chef::Provisioning::AWSDriver::AWSRDSReso
|
|
28
28
|
attribute :additional_options, kind_of: Hash, default: {}
|
29
29
|
|
30
30
|
def aws_object
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
result = self.driver.rds_resource.db_instance(name)
|
32
|
+
return nil unless result && result.db_instance_status != 'deleting'
|
33
|
+
result
|
34
|
+
rescue ::Aws::RDS::Errors::DBInstanceNotFound
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def db_instance_status
|
39
|
+
aws_object.db_instance_status if aws_object
|
40
|
+
rescue ::Aws::RDS::Errors::DBInstanceNotFound
|
41
|
+
nil
|
37
42
|
end
|
38
43
|
|
39
44
|
def rds_tagging_type
|
@@ -36,7 +36,7 @@ class Chef::Resource::AwsRoute53HostedZone < Chef::Provisioning::AWSDriver::AWSR
|
|
36
36
|
attribute :name, kind_of: String, callbacks: { "domain name cannot end with a dot" => lambda { |n| n !~ /\.$/ } }
|
37
37
|
|
38
38
|
# The comment included in the CreateHostedZoneRequest element. String <= 256 characters.
|
39
|
-
attribute :comment, kind_of: String
|
39
|
+
attribute :comment, kind_of: String, default: ""
|
40
40
|
|
41
41
|
# the resource name and the AWS ID have to be related here, since they're tightly coupled elsewhere.
|
42
42
|
attribute :aws_route53_zone_id, kind_of: String, aws_id_attribute: true,
|
data/spec/aws_support.rb
CHANGED
@@ -23,7 +23,7 @@ module AWSSupport
|
|
23
23
|
require 'aws'
|
24
24
|
require 'aws_support/deep_matcher/matchable_object'
|
25
25
|
require 'aws_support/deep_matcher/matchable_array'
|
26
|
-
DeepMatcher::MatchableObject.matchable_classes << proc { |o| o.class.name =~ /^(AWS|Aws)::(EC2|ELB|IAM|S3|RDS|CloudSearch|Route53)($|::)/ }
|
26
|
+
DeepMatcher::MatchableObject.matchable_classes << proc { |o| o.class.name =~ /^(AWS|Aws)::(EC2|ELB|IAM|S3|RDS|CloudSearch|Route53|ElasticsearchService)($|::)/ }
|
27
27
|
DeepMatcher::MatchableArray.matchable_classes << AWS::Core::Data::List
|
28
28
|
|
29
29
|
def purge_all
|
@@ -95,7 +95,7 @@ module AWSSupport
|
|
95
95
|
module_eval(&block)
|
96
96
|
end
|
97
97
|
|
98
|
-
if ENV['AWS_TEST_DRIVER']
|
98
|
+
if ENV['AWS_TEST_DRIVER'] && !ENV['AWS_TEST_DRIVER'].empty?
|
99
99
|
aws_driver = Chef::Provisioning.driver_for_url(ENV['AWS_TEST_DRIVER'])
|
100
100
|
when_the_repository "exists #{description ? "and #{description}" : ""}", *tags, &context_block
|
101
101
|
else
|
@@ -13,10 +13,38 @@ describe Chef::Resource::AwsEipAddress do
|
|
13
13
|
).and be_idempotent
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
aws_eip_address "
|
16
|
+
it "raises an error trying to reference an eip that does not exist" do
|
17
|
+
r = recipe {
|
18
|
+
aws_eip_address "0.0.0.0"
|
19
19
|
}
|
20
|
+
expect {r.converge}.to raise_error(/Chef::Resource::AwsEipAddress\[0.0.0.0\] does not exist!/)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with an existing aws_eip_address" do
|
24
|
+
aws_eip_address "test_eip"
|
25
|
+
|
26
|
+
it "can reference the ip address by id in the name field" do
|
27
|
+
expect_recipe {
|
28
|
+
aws_eip_address test_eip.aws_object.public_ip
|
29
|
+
}.to match_an_aws_eip_address(test_eip.aws_object.public_ip,
|
30
|
+
public_ip: test_eip.aws_object.public_ip
|
31
|
+
).and be_idempotent
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can reference the ip address in the public_ip field" do
|
35
|
+
expect_recipe {
|
36
|
+
aws_eip_address "random_identifier" do
|
37
|
+
public_ip test_eip.aws_object.public_ip
|
38
|
+
end
|
39
|
+
}.to match_an_aws_eip_address("random_identifier",
|
40
|
+
public_ip: test_eip.aws_object.public_ip
|
41
|
+
).and be_idempotent
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'action :delete' do
|
46
|
+
aws_eip_address "test_eip"
|
47
|
+
|
20
48
|
it "deletes the elastic ip" do
|
21
49
|
# TODO all the `with_*` and `expect_*` methods from Cheffish
|
22
50
|
# automatically converge the block - we don't want to do that,
|
@@ -44,27 +72,13 @@ describe Chef::Resource::AwsEipAddress do
|
|
44
72
|
end
|
45
73
|
|
46
74
|
it "associates an EIP with a machine" do
|
47
|
-
test_machine_aws_obj = nil
|
48
|
-
expect_recipe {
|
49
|
-
ruby_block 'look up test machine' do
|
50
|
-
block do
|
51
|
-
test_machine_aws_obj = Chef::Resource::AwsInstance.get_aws_object(
|
52
|
-
'test_machine',
|
53
|
-
run_context: run_context,
|
54
|
-
driver: run_context.chef_provisioning.current_driver,
|
55
|
-
managed_entry_store: Chef::Provisioning.chef_managed_entry_store(run_context.cheffish.current_chef_server)
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
}
|
60
|
-
|
61
75
|
expect_recipe {
|
62
76
|
aws_eip_address "test_eip" do
|
63
77
|
associate_to_vpc true
|
64
78
|
machine "test_machine"
|
65
79
|
end
|
66
80
|
}.to create_an_aws_eip_address('test_eip',
|
67
|
-
instance_id:
|
81
|
+
instance_id: test_machine.aws_object.id
|
68
82
|
).and be_idempotent
|
69
83
|
end
|
70
84
|
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def policy(user)
|
4
|
+
<<EOF
|
5
|
+
{
|
6
|
+
"Version": "2012-10-17",
|
7
|
+
"Statement": [
|
8
|
+
{
|
9
|
+
"Effect": "Allow",
|
10
|
+
"Sid": "test-policy",
|
11
|
+
"Principal": {
|
12
|
+
"AWS": "#{user}"
|
13
|
+
},
|
14
|
+
"Action": "es:*",
|
15
|
+
"Resource": "*"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
EOF
|
20
|
+
end
|
21
|
+
|
22
|
+
def all_options_domain(name)
|
23
|
+
aws_elasticsearch_domain name do
|
24
|
+
instance_type "m3.medium.elasticsearch"
|
25
|
+
instance_count 2
|
26
|
+
dedicated_master_enabled true
|
27
|
+
dedicated_master_type "m3.medium.elasticsearch"
|
28
|
+
dedicated_master_count 2
|
29
|
+
zone_awareness_enabled true
|
30
|
+
ebs_enabled true
|
31
|
+
volume_type "io1"
|
32
|
+
volume_size 35
|
33
|
+
iops 1000
|
34
|
+
automated_snapshot_start_hour 2
|
35
|
+
access_policies policy(driver.iam_client.get_user.user.arn)
|
36
|
+
aws_tags key1: "value"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Chef::Resource::AwsElasticsearchDomain do
|
41
|
+
extend AWSSupport
|
42
|
+
|
43
|
+
let(:all_options_result) do
|
44
|
+
{created: true,
|
45
|
+
elasticsearch_cluster_config: {
|
46
|
+
instance_type: "m3.medium.elasticsearch",
|
47
|
+
instance_count: 2,
|
48
|
+
dedicated_master_enabled: true,
|
49
|
+
dedicated_master_type: "m3.medium.elasticsearch",
|
50
|
+
zone_awareness_enabled: true
|
51
|
+
},
|
52
|
+
ebs_options: {
|
53
|
+
ebs_enabled: true,
|
54
|
+
volume_size: 35,
|
55
|
+
volume_type: "io1",
|
56
|
+
iops: 1000
|
57
|
+
},
|
58
|
+
snapshot_options: {
|
59
|
+
automated_snapshot_start_hour: 2
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
when_the_chef_12_server "exists", organization: "foo", server_scope: :context do
|
65
|
+
with_aws "when connected to AWS" do
|
66
|
+
time = DateTime.now.strftime('%Q')
|
67
|
+
|
68
|
+
it "returns nil when aws_object is called for something that does not exist" do
|
69
|
+
r = nil
|
70
|
+
converge {
|
71
|
+
r = aws_elasticsearch_domain "wont-exist" do
|
72
|
+
action :nothing
|
73
|
+
end
|
74
|
+
}
|
75
|
+
expect(r.aws_object).to eq(nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "aws_elasticsearch_domain 'test-#{time}' creates a elasticsearch domain" do
|
79
|
+
expect_recipe {
|
80
|
+
all_options_domain("test-#{time}")
|
81
|
+
}.to create_an_aws_elasticsearch_domain("test-#{time}", all_options_result).and be_idempotent
|
82
|
+
end
|
83
|
+
|
84
|
+
context "with an existing elasticsearch domain" do
|
85
|
+
aws_elasticsearch_domain "test-#{time}-2"
|
86
|
+
|
87
|
+
it "can update all options" do
|
88
|
+
expect_recipe {
|
89
|
+
all_options_domain("test-#{time}-2")
|
90
|
+
}.to update_an_aws_elasticsearch_domain("test-#{time}-2", all_options_result)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "updates the aws_tags" do
|
94
|
+
expect_recipe {
|
95
|
+
all_options_domain("test-#{time}-2")
|
96
|
+
}.to have_aws_elasticsearch_domain_tags("test-#{time}-2", {'key1' => 'value'})
|
97
|
+
end
|
98
|
+
|
99
|
+
it "removes all aws_elasticsearch_domain tags" do
|
100
|
+
expect_recipe {
|
101
|
+
aws_elasticsearch_domain "test-#{time}-2" do
|
102
|
+
aws_tags {}
|
103
|
+
end
|
104
|
+
}.to have_aws_elasticsearch_domain_tags("test-#{time}-2", {}).and be_idempotent
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
it "destroys an elasticsearch domain" do
|
109
|
+
r = recipe {
|
110
|
+
aws_elasticsearch_domain "test-#{time}-2" do
|
111
|
+
action :destroy
|
112
|
+
end
|
113
|
+
}
|
114
|
+
expect(r).to destroy_an_aws_elasticsearch_domain("test-#{time}-2")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -12,7 +12,8 @@ describe Chef::Resource::AwsKeyPair do
|
|
12
12
|
it "aws_key_pair 'test_key_pair' creates a key pair" do
|
13
13
|
expect(recipe {
|
14
14
|
aws_key_pair 'test_key_pair' do
|
15
|
-
private_key_options format: :
|
15
|
+
private_key_options format: :pem, type: :rsa, regenerate_if_different: true
|
16
|
+
allow_overwrite true
|
16
17
|
end
|
17
18
|
}).to create_an_aws_key_pair('test_key_pair').and be_idempotent
|
18
19
|
end
|
@@ -53,9 +53,9 @@ describe Chef::Resource::AwsRdsInstance do
|
|
53
53
|
db_instance_class: "db.t1.micro",
|
54
54
|
master_username: "thechief",
|
55
55
|
).and be_idempotent
|
56
|
-
|
57
|
-
expect(
|
58
|
-
expect(
|
56
|
+
r = driver.rds_resource.db_instance("test-rds-instance")
|
57
|
+
expect(r.db_subnet_group.db_subnet_group_name).to eq("test-db-subnet-group")
|
58
|
+
expect(r.publicly_accessible).to eq(false)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "aws_rds_instance prefers explicit options" do
|
@@ -64,6 +64,17 @@ describe Chef::Resource::AwsRoute53HostedZone do
|
|
64
64
|
}.to create_an_aws_route53_hosted_zone(zone_name,
|
65
65
|
config: { comment: expected_comment }).and be_idempotent
|
66
66
|
end
|
67
|
+
|
68
|
+
it "updates the zone comment when none is given" do
|
69
|
+
expect_recipe {
|
70
|
+
aws_route53_hosted_zone zone_name do
|
71
|
+
comment "Initial comment."
|
72
|
+
end
|
73
|
+
aws_route53_hosted_zone zone_name do
|
74
|
+
end
|
75
|
+
}.to create_an_aws_route53_hosted_zone(zone_name,
|
76
|
+
config: { comment: nil }).and be_idempotent
|
77
|
+
end
|
67
78
|
end
|
68
79
|
|
69
80
|
context "RecordSets" do
|
@@ -8,6 +8,10 @@ describe Chef::Resource::AwsRouteTable do
|
|
8
8
|
purge_all
|
9
9
|
setup_public_vpc
|
10
10
|
|
11
|
+
aws_network_interface 'test_network_interface' do
|
12
|
+
subnet 'test_public_subnet'
|
13
|
+
end
|
14
|
+
|
11
15
|
it "aws_route_table 'test_route_table' with no parameters except VPC creates a route table" do
|
12
16
|
expect_recipe {
|
13
17
|
aws_route_table 'test_route_table' do
|
@@ -15,7 +19,7 @@ describe Chef::Resource::AwsRouteTable do
|
|
15
19
|
end
|
16
20
|
}.to create_an_aws_route_table('test_route_table',
|
17
21
|
routes: [
|
18
|
-
{ destination_cidr_block: '10.0.0.0/
|
22
|
+
{ destination_cidr_block: '10.0.0.0/16', gateway_id: 'local', state: "active" }
|
19
23
|
]
|
20
24
|
).and be_idempotent
|
21
25
|
end
|
@@ -27,29 +31,20 @@ describe Chef::Resource::AwsRouteTable do
|
|
27
31
|
routes '0.0.0.0/0' => :internet_gateway
|
28
32
|
end
|
29
33
|
}.to create_an_aws_route_table('test_route_table',
|
30
|
-
routes: [
|
31
|
-
{ destination_cidr_block: '10.0.0.0/
|
34
|
+
routes: Set[
|
35
|
+
{ destination_cidr_block: '10.0.0.0/16', gateway_id: 'local', state: "active" },
|
32
36
|
{ destination_cidr_block: '0.0.0.0/0', gateway_id: test_vpc.aws_object.internet_gateway.id, state: "active" }
|
33
37
|
]
|
34
38
|
).and be_idempotent
|
35
39
|
end
|
36
40
|
|
37
41
|
it "ignores routes whose target matches ignore_route_targets" do
|
38
|
-
eni = nil
|
39
42
|
expect_recipe {
|
40
|
-
aws_subnet 'test_subnet' do
|
41
|
-
vpc 'test_vpc'
|
42
|
-
end
|
43
|
-
|
44
|
-
eni = aws_network_interface 'test_network_interface' do
|
45
|
-
subnet 'test_subnet'
|
46
|
-
end
|
47
|
-
|
48
43
|
aws_route_table 'test_route_table' do
|
49
44
|
vpc 'test_vpc'
|
50
45
|
routes(
|
51
46
|
'0.0.0.0/0' => :internet_gateway,
|
52
|
-
'172.31.0.0/16' =>
|
47
|
+
'172.31.0.0/16' => test_network_interface
|
53
48
|
)
|
54
49
|
end
|
55
50
|
|
@@ -59,33 +54,19 @@ describe Chef::Resource::AwsRouteTable do
|
|
59
54
|
ignore_route_targets ['^eni-']
|
60
55
|
end
|
61
56
|
}.to create_an_aws_route_table('test_route_table',
|
62
|
-
routes: [
|
63
|
-
{ destination_cidr_block: '10.0.0.0/
|
64
|
-
{ destination_cidr_block: '172.31.0.0/16', network_interface_id:
|
57
|
+
routes: Set[
|
58
|
+
{ destination_cidr_block: '10.0.0.0/16', gateway_id: 'local', state: "active" },
|
59
|
+
{ destination_cidr_block: '172.31.0.0/16', network_interface_id: test_network_interface.aws_object.id, state: "blackhole" },
|
65
60
|
{ destination_cidr_block: '0.0.0.0/0', gateway_id: test_vpc.aws_object.internet_gateway.id, state: "active" },
|
66
61
|
]
|
67
62
|
).and be_idempotent
|
68
63
|
end
|
69
64
|
|
70
|
-
it "creates aws_route_table tags" do
|
71
|
-
expect_recipe {
|
72
|
-
aws_route_table 'test_route_table' do
|
73
|
-
vpc 'test_vpc'
|
74
|
-
aws_tags key1: "value"
|
75
|
-
end
|
76
|
-
}.to create_an_aws_route_table('test_route_table')
|
77
|
-
.and have_aws_route_table_tags('test_route_table',
|
78
|
-
{
|
79
|
-
'Name' => 'test_route_table',
|
80
|
-
'key1' => 'value'
|
81
|
-
}
|
82
|
-
).and be_idempotent
|
83
|
-
end
|
84
|
-
|
85
65
|
context "with an existing routing table" do
|
86
66
|
aws_route_table 'test_route_table' do
|
87
67
|
vpc 'test_vpc'
|
88
|
-
routes '0.0.0.0/0' => :internet_gateway
|
68
|
+
routes '0.0.0.0/0' => :internet_gateway,
|
69
|
+
'1.0.0.0/8' => :internet_gateway
|
89
70
|
end
|
90
71
|
|
91
72
|
it "updates an existing routing table" do
|
@@ -93,12 +74,12 @@ describe Chef::Resource::AwsRouteTable do
|
|
93
74
|
aws_route_table 'test_route_table' do
|
94
75
|
vpc 'test_vpc'
|
95
76
|
routes '0.0.0.0/0' => :internet_gateway,
|
96
|
-
'
|
77
|
+
'2.0.0.0/8' => :internet_gateway
|
97
78
|
end
|
98
79
|
}.to update_an_aws_route_table('test_route_table',
|
99
|
-
routes: [
|
100
|
-
{ destination_cidr_block: '
|
101
|
-
{ destination_cidr_block: '10.0.0.0/
|
80
|
+
routes: Set[
|
81
|
+
{ destination_cidr_block: '2.0.0.0/8', gateway_id: test_vpc.aws_object.internet_gateway.id, state: "active" },
|
82
|
+
{ destination_cidr_block: '10.0.0.0/16', gateway_id: 'local', state: "active" },
|
102
83
|
{ destination_cidr_block: '0.0.0.0/0', gateway_id: test_vpc.aws_object.internet_gateway.id, state: "active" },
|
103
84
|
]
|
104
85
|
).and be_idempotent
|
@@ -119,19 +100,34 @@ describe Chef::Resource::AwsRouteTable do
|
|
119
100
|
aws_route_table 'test_route_table' do
|
120
101
|
vpc 'test_vpc'
|
121
102
|
routes '0.0.0.0/0' => :internet_gateway,
|
122
|
-
'
|
103
|
+
'11.0.0.0/8' => 'test_machine'
|
123
104
|
end
|
124
105
|
|
125
106
|
}.to create_an_aws_route_table('test_route_table',
|
126
|
-
routes: [
|
107
|
+
routes: Set[
|
127
108
|
{ destination_cidr_block: '10.0.0.0/16', gateway_id: 'local', state: "active" },
|
128
|
-
{ destination_cidr_block: '
|
109
|
+
{ destination_cidr_block: '11.0.0.0/8', instance_id: test_machine.aws_object.id, state: "active" },
|
129
110
|
{ destination_cidr_block: '0.0.0.0/0', gateway_id: test_vpc.aws_object.internet_gateway.id, state: "active" },
|
130
111
|
]
|
131
112
|
).and be_idempotent
|
132
113
|
end
|
133
114
|
end
|
134
115
|
|
116
|
+
it "creates aws_route_table tags" do
|
117
|
+
expect_recipe {
|
118
|
+
aws_route_table 'test_route_table' do
|
119
|
+
vpc 'test_vpc'
|
120
|
+
aws_tags key1: "value"
|
121
|
+
end
|
122
|
+
}.to create_an_aws_route_table('test_route_table')
|
123
|
+
.and have_aws_route_table_tags('test_route_table',
|
124
|
+
{
|
125
|
+
'Name' => 'test_route_table',
|
126
|
+
'key1' => 'value'
|
127
|
+
}
|
128
|
+
).and be_idempotent
|
129
|
+
end
|
130
|
+
|
135
131
|
context "with existing tags" do
|
136
132
|
aws_route_table 'test_route_table' do
|
137
133
|
vpc 'test_vpc'
|
@@ -170,7 +166,7 @@ describe Chef::Resource::AwsRouteTable do
|
|
170
166
|
end
|
171
167
|
|
172
168
|
with_aws "with two VPC's with an internet gateway" do
|
173
|
-
aws_vpc "
|
169
|
+
aws_vpc "test_vpc_1" do
|
174
170
|
cidr_block '10.0.0.0/24'
|
175
171
|
internet_gateway true
|
176
172
|
end
|
@@ -184,22 +180,22 @@ describe Chef::Resource::AwsRouteTable do
|
|
184
180
|
pcx = nil
|
185
181
|
expect_recipe {
|
186
182
|
pcx = aws_vpc_peering_connection 'test_peering_connection' do
|
187
|
-
vpc '
|
183
|
+
vpc 'test_vpc_1'
|
188
184
|
peer_vpc 'test_vpc_2'
|
189
185
|
end
|
190
186
|
|
191
187
|
aws_route_table 'test_route_table' do
|
192
|
-
vpc '
|
188
|
+
vpc 'test_vpc_1'
|
193
189
|
routes(
|
194
190
|
'100.100.0.0/16' => pcx,
|
195
191
|
'0.0.0.0/0' => :internet_gateway
|
196
192
|
)
|
197
193
|
end
|
198
194
|
}.to create_an_aws_route_table('test_route_table',
|
199
|
-
routes: [
|
195
|
+
routes: Set[
|
200
196
|
{ destination_cidr_block: '10.0.0.0/24', gateway_id: 'local', state: "active" },
|
201
197
|
{ destination_cidr_block: '100.100.0.0/16', vpc_peering_connection_id: pcx.aws_object.id, state: "active" },
|
202
|
-
{ destination_cidr_block: '0.0.0.0/0', gateway_id:
|
198
|
+
{ destination_cidr_block: '0.0.0.0/0', gateway_id: test_vpc_1.aws_object.internet_gateway.id, state: "active" }
|
203
199
|
]
|
204
200
|
).and be_idempotent
|
205
201
|
end
|