Class: Putpaws::Provision::Resources::LogGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/putpaws/provision/resources/log_group.rb

Instance Attribute Summary

Attributes inherited from Base

#clients, #config, #state

Instance Method Summary collapse

Methods inherited from Base

#ensure!, #kind, #plan

Constructor Details

#initialize(log_group_name:, output_key:, **args) ⇒ LogGroup

Returns a new instance of LogGroup.



7
8
9
10
11
# File 'lib/putpaws/provision/resources/log_group.rb', line 7

def initialize(log_group_name:, output_key:, **args)
  super(**args)
  @log_group_name = log_group_name
  @output_key = output_key
end

Instance Method Details

#changed?(current) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/putpaws/provision/resources/log_group.rb', line 26

def changed?(current)
  current.retention_in_days != retention_in_days
end

#create!Object



30
31
32
33
34
35
36
37
# File 'lib/putpaws/provision/resources/log_group.rb', line 30

def create!
  clients.logs.create_log_group(
    log_group_name: name,
    tags: {MANAGED_TAG[:key] => MANAGED_TAG[:value]}
  )
  clients.logs.put_retention_policy(log_group_name: name, retention_in_days: retention_in_days)
  {@output_key => name}
end

#currentObject



21
22
23
24
# File 'lib/putpaws/provision/resources/log_group.rb', line 21

def current
  res = clients.logs.describe_log_groups(log_group_name_prefix: name)
  res.log_groups.detect{|g| g.log_group_name == name}
end

#nameObject



13
14
15
# File 'lib/putpaws/provision/resources/log_group.rb', line 13

def name
  @log_group_name
end

#outputs(_current) ⇒ Object



44
45
46
# File 'lib/putpaws/provision/resources/log_group.rb', line 44

def outputs(_current)
  {@output_key => name}
end

#retention_in_daysObject



17
18
19
# File 'lib/putpaws/provision/resources/log_group.rb', line 17

def retention_in_days
  (config.settings[:log_retention_days] || 30).to_i
end

#update!(_current) ⇒ Object



39
40
41
42
# File 'lib/putpaws/provision/resources/log_group.rb', line 39

def update!(_current)
  clients.logs.put_retention_policy(log_group_name: name, retention_in_days: retention_in_days)
  {@output_key => name}
end