Class: Bauble::Resources::LambdaRole

Inherits:
Resource
  • Object
show all
Defined in:
lib/bauble/resources/lambda_role.rb

Overview

aws lambda role

Instance Attribute Summary collapse

Attributes inherited from Resource

#app

Instance Method Summary collapse

Methods inherited from Resource

#resource_name

Constructor Details

#initialize(app, name:, policy_statements: [], **kwargs) ⇒ LambdaRole

Returns a new instance of LambdaRole.



12
13
14
15
16
17
18
# File 'lib/bauble/resources/lambda_role.rb', line 12

def initialize(app, name:, policy_statements: [], **kwargs)
  super(app)
  @name = name
  @policy_statements = policy_statements
  @managed_policy_arns = []
  @description = kwargs.fetch(:description, 'Bauble lambda role')
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/bauble/resources/lambda_role.rb', line 10

def description
  @description
end

#managed_policy_arnsObject

Returns the value of attribute managed_policy_arns.



10
11
12
# File 'lib/bauble/resources/lambda_role.rb', line 10

def managed_policy_arns
  @managed_policy_arns
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/bauble/resources/lambda_role.rb', line 10

def name
  @name
end

#policy_statementsObject

Returns the value of attribute policy_statements.



10
11
12
# File 'lib/bauble/resources/lambda_role.rb', line 10

def policy_statements
  @policy_statements
end

Instance Method Details

#add_policy_statement(effect:, actions:, resources:) ⇒ Object



40
41
42
# File 'lib/bauble/resources/lambda_role.rb', line 40

def add_policy_statement(effect:, actions:, resources:)
  policy_statements << { effect: effect, actions: actions, resources: resources }
end

#bundleObject



44
45
46
# File 'lib/bauble/resources/lambda_role.rb', line 44

def bundle
  true
end

#synthesizeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bauble/resources/lambda_role.rb', line 20

def synthesize
  role_hash = {
    name => {
      'type' => 'aws:iam:Role',
      'properties' => {
        'name' => resource_name(name),
        'assumeRolePolicy' => assume_role_policy,
        'managedPolicyArns' => managed_policy_arns.push(
          'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
        ),
        'description' => @description
      }.compact
    }
  }

  return role_hash.merge(role_policy) if policy_statements.any?

  role_hash
end