Class: Terracop::Cop::Aws::EnsureTags

Inherits:
Base
  • Object
show all
Defined in:
lib/terracop/cop/aws/ensure_tags.rb

Overview

This cop makes sure that AWS resources that can be tagged, are indeed tagged. By default it just checks that resources have at least one tag, any tag. It is configurable to enforce the existance of some specific tags.

Examples:

# bad
resource "aws_alb" "lb" {
  name_prefix = "app"
}

# good
resource "aws_alb" "lb" {
  name_prefix = "app"
  tags = {
    environment = "staging"
  }
}

Instance Attribute Summary

Attributes inherited from Base

#attributes, #index, #name, #offenses, #type

Instance Method Summary collapse

Methods inherited from Base

config, cop_name, #human_name, #initialize, #offense, run

Constructor Details

This class inherits a constructor from Terracop::Cop::Base

Instance Method Details

#checkObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/terracop/cop/aws/ensure_tags.rb', line 29

def check
  tags = tags_for(attributes)
  return unless tags

  if self.class.config['Required']
    check_required(tags, self.class.config['Required'])
  elsif tags.empty?
    offense 'Tag resources properly.'
  end
end