Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions alb_support/recipes/attach_to_alb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@
raise "alb_helper block not specified in layer JSON" if node[:alb_helper].nil?
raise "Target group ARN not specified in layer JSON" if node[:alb_helper][:target_group_arn].nil?

stack = search("aws_opsworks_stack").first
instance = search("aws_opsworks_instance", "self:true").first
if ( Chef::VERSION.to_f >= 12.0 )
stack = search("aws_opsworks_stack").first
instance = search("aws_opsworks_instance", "self:true").first

stack_region = stack[:region]
ec2_instance_id = instance[:ec2_instance_id]
else
stack_region = node["opsworks"]["instance"]["region"]
ec2_instance_id = node["opsworks"]["instance"]["aws_instance_id"]
end

stack_region = stack[:region]
ec2_instance_id = instance[:ec2_instance_id]
target_group_arn = node[:alb_helper][:target_group_arn]

Chef::Log.info("Creating ELB client in region #{stack_region}")
Expand Down
19 changes: 15 additions & 4 deletions alb_support/recipes/detach_from_alb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
chef_gem "aws-sdk-core" do
version "~> 2.6"
action :install
end

ruby_block "detach from ALB" do
block do
require "aws-sdk-core"
Expand All @@ -28,11 +33,17 @@
Chef::Log.info("connection_draining_timeout: #{connection_draining_timeout}")
Chef::Log.info("state_check_frequency: #{state_check_frequency}")

stack = search("aws_opsworks_stack").first
instance = search("aws_opsworks_instance", "self:true").first
if ( Chef::VERSION.to_f >= 12.0 )
stack = search("aws_opsworks_stack").first
instance = search("aws_opsworks_instance", "self:true").first

stack_region = stack[:region]
ec2_instance_id = instance[:ec2_instance_id]
else
stack_region = node["opsworks"]["instance"]["region"]
ec2_instance_id = node["opsworks"]["instance"]["aws_instance_id"]
end

stack_region = stack[:region]
ec2_instance_id = instance[:ec2_instance_id]
target_group_arn = node[:alb_helper][:target_group_arn]

Chef::Log.info("Creating ELB client in region #{stack_region}")
Expand Down