class Applb::DSL::EC2::LoadBalancer::TargetGroups::TargetGroup::Result
Constants
- ATTRIBUTES
- UNMODIFIABLE_ATTRIBUTES
Public Class Methods
new(context)
click to toggle source
# File lib/applb/dsl/target_group.rb, line 19 def initialize(context) @context = context @options = context.options end
Public Instance Methods
aws(aws_tg)
click to toggle source
# File lib/applb/dsl/target_group.rb, line 28 def aws(aws_tg) @aws_tg = aws_tg self end
create()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 33 def create Applb.logger.info("Create target group #{name}") return if @options[:dry_run] client.create_target_group(create_option).target_groups.first end
modify()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 39 def modify dsl_hash = to_diff_h aws_hash = to_diff_h_aws return if dsl_hash == aws_hash Applb.logger.info("Modify target group #{name}") Applb.logger.info("<diff>\n#{Applb::Utils.diff(aws_hash, dsl_hash, color: @options[:color])}") if unmodifiable_attributes_updated?(dsl_hash, aws_hash) raise 'Can not modify unmodifiable attributes.' end return if @options[:dry_run] client.modify_target_group(modify_option).target_groups.first end
to_h()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 24 def to_h Hash[ATTRIBUTES.sort.map { |name| [name, public_send(name)] }] end
Private Instance Methods
client()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 93 def client @client ||= Applb::ClientWrapper.new(@options) end
create_option()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 57 def create_option to_h end
modify_option()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 62 def modify_option options = to_h. merge(target_group_arn: @aws_tg.target_group_arn). reject! { |k, v| UNMODIFIABLE_ATTRIBUTES.include?(k) } end
to_diff_h()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 79 def to_diff_h hash = to_h hash.delete(:target_group_arn) Hash[hash.sort] end
to_diff_h_aws()
click to toggle source
# File lib/applb/dsl/target_group.rb, line 85 def to_diff_h_aws hash = @aws_tg.to_h hash[:name] = hash.delete(:target_group_name) hash.delete(:target_group_arn) hash.delete(:load_balancer_arns) Hash[hash.sort] end
unmodifiable_attributes_updated?(dsl_hash, aws_hash)
click to toggle source
# File lib/applb/dsl/target_group.rb, line 68 def unmodifiable_attributes_updated?(dsl_hash, aws_hash) updated = false UNMODIFIABLE_ATTRIBUTES.each do |n| if dsl_hash[n] != aws_hash[n] updated = true Applb.logger.error("can not modify target_group `#{n}'") end end updated end