Class: VpcHasFlowLogRule

Inherits:
BaseRule show all
Defined in:
lib/cfn-nag/custom_rules/VpcHasFlowLogRule.rb

Instance Method Summary collapse

Methods inherited from BaseRule

#audit

Instance Method Details

#audit_impl(cfn_model) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/cfn-nag/custom_rules/VpcHasFlowLogRule.rb', line 19

def audit_impl(cfn_model)
  violating_vpcs = cfn_model.resources_by_type('AWS::EC2::VPC')
                            .select do |vpc|
    flowlog_for_vpc(cfn_model, vpc).nil?
  end

  violating_vpcs.map(&:logical_resource_id)
end

#flowlog_for_vpc(cfn_model, vpc) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/cfn-nag/custom_rules/VpcHasFlowLogRule.rb', line 28

def flowlog_for_vpc(cfn_model, vpc)
  cfn_model.resources_by_type('AWS::EC2::FlowLog').find do |flowlog|
    if flowlog.resourceId && flowlog.resourceId['Ref']
      flowlog.resourceId['Ref'] == vpc.logical_resource_id
    end
  end
end

#rule_idObject



15
16
17
# File 'lib/cfn-nag/custom_rules/VpcHasFlowLogRule.rb', line 15

def rule_id
  'W60'
end

#rule_textObject



7
8
9
# File 'lib/cfn-nag/custom_rules/VpcHasFlowLogRule.rb', line 7

def rule_text
  'VPC should have a flow log attached'
end

#rule_typeObject



11
12
13
# File 'lib/cfn-nag/custom_rules/VpcHasFlowLogRule.rb', line 11

def rule_type
  Violation::WARNING
end