Sha256: a8a31a36dea85949ec50e28c359cb71e79f7a269e345f51b22719ac839cff65c

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

module Jets::Resource::Iam
  module BaseRoleDefinition
    attr_reader :policy_definitions, :managed_policy_definitions

    def definition
      logical_id = role_logical_id

      definition = {
        logical_id => {
          type: "AWS::IAM::Role",
          properties: {
            role_name: role_name,
            path: "/",
            assume_role_policy_document: {
              version: "2012-10-17",
              statement: [{
                effect: "Allow",
                principal: {service: ["lambda.amazonaws.com"]},
                action: ["sts:AssumeRole"]}
              ]
            }
          }
        }
      }

      definition[logical_id][:properties][:policies] = [
        policy_name: "#{role_name}-policy",
        policy_document: policy_document,
      ] unless policy_document['Statement'].empty?

      unless managed_policy_arns.empty?
        definition[logical_id][:properties][:managed_policy_arns] = managed_policy_arns
      end

      definition
    end

    def policy_document
      PolicyDocument.new(@policy_definitions.uniq).policy_document
    end

    def managed_policy_arns
      ManagedPolicy.new(@managed_policy_definitions.uniq).arns
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jets-0.9.0 lib/jets/resource/iam/base_role_definition.rb