Skip to content

Commit

Permalink
Merge branch 'master' of github.com:chef/chef-provisioning-aws
Browse files Browse the repository at this point in the history
Conflicts:
	lib/chef/provider/aws_launch_configuration.rb
  • Loading branch information
jjlimepoint committed Feb 19, 2018
2 parents 0caa7cf + 44f8195 commit 5d6f4bd
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 26 deletions.
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Change Log

## [3.0.1](https://github.com/chef/chef-provisioning-aws/tree/3.0.1) (2018-02-05)
[Full Changelog](https://github.com/chef/chef-provisioning-aws/compare/v3.0.0...3.0.1)
## [3.0.2](https://github.com/chef/chef-provisioning-aws/tree/3.0.2) (2018-02-14)
[Full Changelog](https://github.com/chef/chef-provisioning-aws/compare/v3.0.1...3.0.2)

**Closed issues:**

- auto\_scaling\_group now requires new way to specify subnets [\#560](https://github.com/chef/chef-provisioning-aws/issues/560)
- machine/machine\_image resources no longer wait for transport [\#559](https://github.com/chef/chef-provisioning-aws/issues/559)
- launch\_configuration expects base64 encoded user\_data [\#558](https://github.com/chef/chef-provisioning-aws/issues/558)
- Examples for aws\_cloudwatch\_alarm work only with aws-sdk-v1 [\#557](https://github.com/chef/chef-provisioning-aws/issues/557)

**Merged pull requests:**

- Bug fixes [\#564](https://github.com/chef/chef-provisioning-aws/pull/564) ([tyler-ball](https://github.com/tyler-ball))

## [v3.0.1](https://github.com/chef/chef-provisioning-aws/tree/v3.0.1) (2018-02-05)
[Full Changelog](https://github.com/chef/chef-provisioning-aws/compare/v3.0.0...v3.0.1)

**Merged pull requests:**

Expand Down Expand Up @@ -850,4 +864,4 @@
## [v0.3.1](https://github.com/chef/chef-provisioning-aws/tree/v0.3.1) (2014-03-18)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
38 changes: 19 additions & 19 deletions docs/examples/aws_cloudwatch_alarm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@

# More complicated example settings up an alarm to scale up and auto-scaling
# group if the CPU passes a certain threshold
aws_launch_config 'my-launch-config' do
image 'ami-f0b11187'
instance_type 't1.micro'
aws_launch_configuration 'my-launch-config' do
image 'ami-ca3b11af'
instance_type 't2.micro'
end

scaling_group =
aws_auto_scaling_group 'my-auto-scaling-group' do
desired_capacity 3
min_size 1
max_size 5
launch_config 'my-launch-config'
scaling_policies(
'my-scaling-policy' => {
adjustment_type: 'ChangeInCapacity',
scaling_adjustment: 2
}
)
end
scaling_group = aws_auto_scaling_group 'scaling_group' do
desired_capacity 3
min_size 1
max_size 5
launch_configuration 'my-launch-config'
availability_zones ["#{driver.region}a"]
scaling_policies(
'my-scaling-policy' => {
adjustment_type: 'ChangeInCapacity',
scaling_adjustment: 2
}
)
end

aws_cloudwatch_alarm 'my-test-alert' do
namespace 'AWS/EC2'
Expand All @@ -42,7 +42,7 @@
period 60
statistic 'Average'
threshold 80
alarm_actions [
scaling_group.aws_object.scaling_policies['my-scaling-policy'].arn
]
alarm_actions lazy { [
scaling_group.aws_object.policies().select{ |p| p.name == 'my-scaling-policy'}.first.policy_arn
] }
end
1 change: 1 addition & 0 deletions lib/chef/provider/aws_auto_scaling_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def create_aws_object
options[:auto_scaling_group_name] = new_resource.name
options[:launch_configuration_name] = new_resource.launch_configuration if new_resource.launch_configuration
options[:load_balancer_names] = new_resource.load_balancers if new_resource.load_balancers
options[:vpc_zone_identifier] = [options.delete(:subnets)].flatten.join(",") if options[:subnets]

aws_obj = new_resource.driver.auto_scaling_resource.create_group(options)

Expand Down
15 changes: 14 additions & 1 deletion lib/chef/provider/aws_launch_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def create_aws_object
options[:launch_configuration_name] = new_resource.name if new_resource.name
options[:image_id] = image_id
options[:instance_type] = instance_type
options[:user_data] = Base64.encode64(options[:user_data]) unless options[:user_data].nil?
if options[:user_data]
options[:user_data] = ensure_base64_encoded(options[:user_data])
end

converge_by "create launch configuration #{new_resource.name} in #{region}" do
new_resource.driver.auto_scaling_client.create_launch_configuration(options)
Expand Down Expand Up @@ -49,4 +51,15 @@ def destroy_aws_object(launch_configuration)
end
end

private

def ensure_base64_encoded(data)
begin
Base64.strict_decode64(data)
return data
rescue ArgumentError
return Base64.encode64(data)
end
end

end
4 changes: 2 additions & 2 deletions lib/chef/provisioning/aws_driver/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def region
def cloudsearch
@cloudsearch ||= Aws::CloudSearch::Client.new(aws_config)
end

def self.canonicalize_url(driver_url, config)
[ driver_url, config ]
end
Expand Down Expand Up @@ -1400,7 +1400,7 @@ def wait_for_transport(action_handler, machine_spec, machine_options, instance=n
instance ||= instance_for(machine_spec)
sleep_time = 10
transport = transport_for(machine_spec, machine_options, instance)
unless instance.state.name.eql?("running")
unless instance.state.name.eql?("running") && transport.available?
if action_handler.should_perform_actions
action_handler.report_progress "waiting for #{machine_spec.name} (#{instance.id} on #{driver_url}) to be connectable (transport up and running) ..."
max_wait_time = Chef::Config.chef_provisioning[:machine_max_wait_time] || 120
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/provisioning/aws_driver/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Chef
module Provisioning
module AWSDriver
VERSION = '3.0.1'
VERSION = '3.0.2'
end
end
end
21 changes: 21 additions & 0 deletions spec/integration/aws_auto_scaling_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@
'test_group_with_policy').and be_idempotent
end

# test_public_subnet
context "when referencing a subnet" do
purge_all
setup_public_vpc
it "creates an aws_auto_scaling_group" do
expect_recipe {
aws_auto_scaling_group 'test_group' do
launch_configuration 'test_config'
# availability_zones ["#{driver.region}a"]
min_size 1
max_size 2
options({
subnets: 'test_public_subnet'
})
end
}.to create_an_aws_auto_scaling_group('test_group',
vpc_zone_identifier: test_public_subnet.aws_object.id
).and be_idempotent
end
end

it "creates aws_auto_scaling_group tags" do
expect_recipe {
aws_auto_scaling_group 'test_group_with_policy' do
Expand Down
69 changes: 69 additions & 0 deletions spec/integration/aws_launch_configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'spec_helper'

describe Chef::Resource::AwsLaunchConfiguration do
extend AWSSupport

when_the_chef_12_server "exists", organization: 'foo', server_scope: :context do
with_aws "when connected to AWS" do
let(:image_filters) {
{
filters: [
{
name: "image-type",
values: ["machine"]
},
{
name: "state",
values: ["available"]
},
{
name: "is-public",
values: ["true"]
},
{
name: "owner-alias",
values: ["amazon"]
}
]
}
}

it "creates a minimum aws_launch_configuration" do
expect_recipe {
ami = driver.ec2_client.describe_images(image_filters).images[0].image_id
aws_launch_configuration "my-launch-configuration" do
image ami
instance_type 't2.micro'
end
}.to create_an_aws_launch_configuration("my-launch-configuration").and be_idempotent
end

it "accepts base64 encoded user data" do
expect_recipe {
ami = driver.ec2_client.describe_images(image_filters).images[0].image_id
aws_launch_configuration "my-launch-configuration" do
image ami
instance_type 't2.micro'
options({
user_data: Base64.encode64("echo 1")
})
end
}.to create_an_aws_launch_configuration("my-launch-configuration").and be_idempotent
end

it "accepts regular user data" do
expect_recipe {
ami = driver.ec2_client.describe_images(image_filters).images[0].image_id
aws_launch_configuration "my-launch-configuration" do
image ami
instance_type 't2.micro'
options({
user_data: "echo 1"
})
end
}.to create_an_aws_launch_configuration("my-launch-configuration").and be_idempotent
end

end
end
end

0 comments on commit 5d6f4bd

Please sign in to comment.