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.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/lib/chef/provider/aws_auto_scaling_group.rb +30 -41
- data/lib/chef/provider/aws_dhcp_options.rb +70 -0
- data/lib/chef/provider/aws_ebs_volume.rb +182 -34
- data/lib/chef/provider/aws_eip_address.rb +63 -60
- data/lib/chef/provider/aws_key_pair.rb +18 -27
- data/lib/chef/provider/aws_launch_configuration.rb +50 -0
- data/lib/chef/provider/aws_route_table.rb +122 -0
- data/lib/chef/provider/aws_s3_bucket.rb +42 -49
- data/lib/chef/provider/aws_security_group.rb +252 -59
- data/lib/chef/provider/aws_sns_topic.rb +10 -26
- data/lib/chef/provider/aws_sqs_queue.rb +16 -38
- data/lib/chef/provider/aws_subnet.rb +85 -32
- data/lib/chef/provider/aws_vpc.rb +163 -23
- data/lib/chef/provisioning/aws_driver.rb +18 -1
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +206 -0
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +186 -0
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +114 -0
- data/lib/chef/provisioning/aws_driver/driver.rb +317 -255
- data/lib/chef/provisioning/aws_driver/resources.rb +8 -5
- data/lib/chef/provisioning/aws_driver/super_lwrp.rb +45 -0
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_auto_scaling_group.rb +15 -13
- data/lib/chef/resource/aws_dhcp_options.rb +57 -0
- data/lib/chef/resource/aws_ebs_volume.rb +20 -22
- data/lib/chef/resource/aws_eip_address.rb +50 -25
- data/lib/chef/resource/aws_image.rb +20 -0
- data/lib/chef/resource/aws_instance.rb +20 -0
- data/lib/chef/resource/aws_internet_gateway.rb +16 -0
- data/lib/chef/resource/aws_key_pair.rb +6 -10
- data/lib/chef/resource/aws_launch_configuration.rb +15 -0
- data/lib/chef/resource/aws_load_balancer.rb +16 -0
- data/lib/chef/resource/aws_network_interface.rb +16 -0
- data/lib/chef/resource/aws_route_table.rb +76 -0
- data/lib/chef/resource/aws_s3_bucket.rb +8 -18
- data/lib/chef/resource/aws_security_group.rb +49 -19
- data/lib/chef/resource/aws_sns_topic.rb +14 -15
- data/lib/chef/resource/aws_sqs_queue.rb +16 -14
- data/lib/chef/resource/aws_subnet.rb +87 -17
- data/lib/chef/resource/aws_vpc.rb +137 -15
- data/spec/integration/aws_security_group_spec.rb +55 -0
- data/spec/spec_helper.rb +8 -2
- data/spec/support/aws_support.rb +211 -0
- metadata +33 -10
- data/lib/chef/provider/aws_launch_config.rb +0 -43
- data/lib/chef/provider/aws_provider.rb +0 -22
- data/lib/chef/provisioning/aws_driver/aws_profile.rb +0 -73
- data/lib/chef/resource/aws_launch_config.rb +0 -14
- data/lib/chef/resource/aws_resource.rb +0 -10
- data/spec/chef_zero_rspec_helper.rb +0 -8
- data/spec/unit/provider/aws_subnet_spec.rb +0 -67
- data/spec/unit/resource/aws_subnet_spec.rb +0 -23
@@ -1,73 +0,0 @@
|
|
1
|
-
class AwsProfile
|
2
|
-
|
3
|
-
# Order of operations:
|
4
|
-
# compute_options[:aws_access_key_id] / compute_options[:aws_secret_access_key] / compute_options[:aws_security_token] / compute_options[:region]
|
5
|
-
# compute_options[:aws_profile]
|
6
|
-
# ENV['AWS_ACCESS_KEY_ID'] / ENV['AWS_SECRET_ACCESS_KEY'] / ENV['AWS_SECURITY_TOKEN'] / ENV['AWS_REGION']
|
7
|
-
# ENV['AWS_PROFILE']
|
8
|
-
# ENV['DEFAULT_PROFILE']
|
9
|
-
# 'default'
|
10
|
-
def initialize(driver_options, aws_account_id)
|
11
|
-
aws_credentials = get_aws_credentials(driver_options)
|
12
|
-
compute_options = driver_options[:compute_options] || {}
|
13
|
-
|
14
|
-
aws_profile = if compute_options[:aws_access_key_id]
|
15
|
-
Chef::Log.debug('Using AWS driver access key options')
|
16
|
-
{
|
17
|
-
:aws_access_key_id => compute_options[:aws_access_key_id],
|
18
|
-
:aws_secret_access_key => compute_options[:aws_secret_access_key],
|
19
|
-
:aws_security_token => compute_options[:aws_session_token],
|
20
|
-
:region => compute_options[:region]
|
21
|
-
}
|
22
|
-
elsif driver_options[:aws_profile]
|
23
|
-
Chef::Log.debug("Using AWS profile #{driver_options[:aws_profile]}")
|
24
|
-
aws_credentials[driver_options[:aws_profile]]
|
25
|
-
elsif ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY']
|
26
|
-
Chef::Log.debug('Using AWS environment variable access keys')
|
27
|
-
{
|
28
|
-
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY'],
|
29
|
-
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_KEY'],
|
30
|
-
:aws_security_token => ENV['AWS_SECURITY_TOKEN'],
|
31
|
-
:region => ENV['AWS_REGION']
|
32
|
-
}
|
33
|
-
elsif ENV['AWS_PROFILE']
|
34
|
-
Chef::Log.debug("Using AWS profile #{ENV['AWS_PROFILE']} from AWS_PROFILE environment variable")
|
35
|
-
aws_credentials[ENV['AWS_PROFILE']]
|
36
|
-
else
|
37
|
-
Chef::Log.debug('Using AWS default profile')
|
38
|
-
aws_credentials.default
|
39
|
-
end
|
40
|
-
# Endpoint configuration
|
41
|
-
if compute_options[:ec2_endpoint]
|
42
|
-
aws_profile[:ec2_endpoint] = compute_options[:ec2_endpoint]
|
43
|
-
elsif ENV['EC2_URL']
|
44
|
-
aws_profile[:ec2_endpoint] = ENV['EC2_URL']
|
45
|
-
end
|
46
|
-
if compute_options[:iam_endpoint]
|
47
|
-
aws_profile[:iam_endpoint] = compute_options[:iam_endpoint]
|
48
|
-
elsif ENV['AWS_IAM_URL']
|
49
|
-
aws_profile[:iam_endpoint] = ENV['AWS_IAM_URL']
|
50
|
-
else
|
51
|
-
aws_profile[:iam_endpoint] = 'https://iam.amazonaws.com/'
|
52
|
-
end
|
53
|
-
|
54
|
-
# Merge in account info for profile
|
55
|
-
if aws_profile
|
56
|
-
aws_profile = aws_profile.merge(aws_account_info_for(aws_profile))
|
57
|
-
end
|
58
|
-
|
59
|
-
# If no profile is found (or the profile is not the right account), search
|
60
|
-
# for a profile that matches the given account ID
|
61
|
-
if aws_account_id && (!aws_profile || aws_profile[:aws_account_id] != aws_account_id)
|
62
|
-
aws_profile = find_aws_profile_for_account_id(aws_credentials, aws_account_id)
|
63
|
-
end
|
64
|
-
|
65
|
-
unless aws_profile
|
66
|
-
raise 'No AWS profile specified! Are you missing something in the Chef config or ~/.aws/config?'
|
67
|
-
end
|
68
|
-
|
69
|
-
aws_profile.delete_if { |_, value| value.nil? }
|
70
|
-
aws_profile
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'chef/resource/aws_resource'
|
2
|
-
require 'chef/provisioning/aws_driver'
|
3
|
-
|
4
|
-
class Chef::Resource::AwsLaunchConfig < Chef::Resource::AwsResource
|
5
|
-
self.resource_name = 'aws_launch_config'
|
6
|
-
self.databag_name = 'launch_configs'
|
7
|
-
|
8
|
-
actions :create, :delete, :nothing
|
9
|
-
default_action :create
|
10
|
-
|
11
|
-
attribute :name, :kind_of => String, :name_attribute => true
|
12
|
-
attribute :image, :kind_of => String
|
13
|
-
attribute :instance_type, :kind_of => String
|
14
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Common AWS resource - contains metadata that all AWS resources will need
|
2
|
-
class Chef::Resource::AwsResource < Chef::Resource::ChefDataBagResource
|
3
|
-
stored_attribute :driver
|
4
|
-
|
5
|
-
def initialize(*args)
|
6
|
-
super
|
7
|
-
@driver = run_context.chef_provisioning.current_driver
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'chef_zero_rspec_helper'
|
3
|
-
AWS.stub!
|
4
|
-
|
5
|
-
describe Chef::Provider::AwsSubnet do
|
6
|
-
extend ChefZeroRspecHelper
|
7
|
-
let(:new_resource) {
|
8
|
-
Chef::Resource::AwsSubnet.new('my_subnet', run_context)
|
9
|
-
}
|
10
|
-
let(:my_node) {
|
11
|
-
node = Chef::Node.new
|
12
|
-
node.automatic['platform'] = 'ubuntu'
|
13
|
-
node.automatic['platform_version'] = '12.04'
|
14
|
-
node
|
15
|
-
}
|
16
|
-
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
17
|
-
let(:run_context) {
|
18
|
-
cookbook_collection = {}
|
19
|
-
Chef::RunContext.new(my_node, cookbook_collection ,events)
|
20
|
-
}
|
21
|
-
|
22
|
-
subject(:provider) {
|
23
|
-
described_class.new(new_resource, run_context)
|
24
|
-
}
|
25
|
-
|
26
|
-
when_the_chef_server "is empty" do
|
27
|
-
describe '#action_create' do
|
28
|
-
it 'requires cidr_block' do
|
29
|
-
expect{ provider.action_create }
|
30
|
-
.to raise_error(
|
31
|
-
RuntimeError, "Can't create a Subnet without a CIDR block"
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'requires VPC to exist' do
|
36
|
-
new_resource.cidr_block('1.2.3.4/24')
|
37
|
-
new_resource.vpc('my_vpc')
|
38
|
-
allow_any_instance_of(AWS::EC2::VPCCollection)
|
39
|
-
.to receive(:with_tag)
|
40
|
-
.and_return(nil)
|
41
|
-
expect{ provider.action_create }
|
42
|
-
.to raise_error(AWS::Core::OptionGrammar::FormatError)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should work with a VPC object' do
|
46
|
-
new_resource.cidr_block('1.2.3.4/24')
|
47
|
-
allow_any_instance_of(AWS::EC2::VPCCollection)
|
48
|
-
.to receive(:with_tag)
|
49
|
-
.and_return( [ AWS::EC2::VPC.new('vpc-abcd1234') ] )
|
50
|
-
allow_any_instance_of(AWS::EC2::SubnetCollection)
|
51
|
-
.to receive(:create)
|
52
|
-
.and_return(AWS::EC2::Subnet.new('subnet-feeddeed'))
|
53
|
-
expect(new_resource).to receive(:save)
|
54
|
-
provider.action_create
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should not converge if subnet already exists' do
|
58
|
-
new_resource.cidr_block('1.2.3.4/24')
|
59
|
-
allow_any_instance_of(AWS::EC2::SubnetCollection)
|
60
|
-
.to receive(:with_tag)
|
61
|
-
.and_return([AWS::EC2::Subnet.new('subnet-feeddeed')])
|
62
|
-
expect(provider).to_not receive(:converge_by)
|
63
|
-
provider.action_create
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'chef_zero_rspec_helper'
|
3
|
-
|
4
|
-
describe Chef::Resource::AwsSubnet do
|
5
|
-
extend ChefZeroRspecHelper
|
6
|
-
let(:my_node) { Chef::Node.new() }
|
7
|
-
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
8
|
-
let(:run_context) { Chef::RunContext.new(my_node,{},events) }
|
9
|
-
|
10
|
-
subject(:resource) {
|
11
|
-
described_class.new('my_subnet', run_context)
|
12
|
-
}
|
13
|
-
|
14
|
-
when_the_chef_server "is empty" do
|
15
|
-
it 'should match resource name' do
|
16
|
-
expect(resource.resource_name).to eq(:aws_subnet)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should match name' do
|
20
|
-
expect(resource.name).to eq('my_subnet')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|