class Terracop::Cop::Aws::EnsurePropagatedTags

This cop makes sure that EC2 instances launched by Autoscaling Groups also have tags. It is configured like the Aws/EnsureTags cop.

@example

# bad
resource "aws_asg" "asg" {
  tag {
    key = "Name"
    value = "asg"
    propagate_at_launch = false
  }
}

# good
resource "aws_asg" "asg" {
  tag {
    key = "Name"
    value = "asg"
    propagate_at_launch = true
  }
}

Public Instance Methods

check() click to toggle source
# File lib/terracop/cop/aws/ensure_propagated_tags.rb, line 33
def check
  if self.class.config['Required']
    check_required(propagated_tags, self.class.config['Required'])
  elsif propagated_tags.empty?
    offense 'The EC2 instances launched by this Autoscaling group ' \
            'will not have any tags.'
  end
end

Private Instance Methods

check_required(tags, required_tags) click to toggle source
# File lib/terracop/cop/aws/ensure_propagated_tags.rb, line 49
def check_required(tags, required_tags)
  required_tags.each do |key|
    unless tags.find { |t| t['key'] == key }
      offense "Required tag \"#{key}\" is not propagated to EC2 " \
              'instances launched by this Autoscaling Group.'
    end
  end
end
propagated_tags() click to toggle source
# File lib/terracop/cop/aws/ensure_propagated_tags.rb, line 44
def propagated_tags
  tags = attributes['tags'] || attributes['tag']
  tags.select { |t| t['propagate_at_launch'] }
end