Class: Terracop::Cop::Style::SnakeCase

Inherits:
Base
  • Object
show all
Defined in:
lib/terracop/cop/style/snake_case.rb

Overview

Note:

When you rename a resource terraform will destroy and recreate it. Use ‘terraform mv` on the state file to avoid this from happening.

This cop checks terraform resource names that are using CamelCase or in general, contain capital letters. Terraform prefers snake_case.

Examples:

# bad
resource "aws_security_group" "LoadBalancer" { }
resource "aws_security_group" "app_ALB" { }

# good
resource "aws_security_group" "load_balancer" { }
resource "aws_security_group_rule" "app_alb" { }

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



26
27
28
29
30
31
# File 'lib/terracop/cop/style/snake_case.rb', line 26

def check
  # Allow dashes here as there is another cop to complain about that.
  return if name =~ /^[\da-z_\-]+$/

  offense 'Use snake_case for resource names.'
end