Sha256: 7cdc6c523d801ba1e9ef4d0c3c6832dbf9455378a038f7d3eb0f08000a72e448

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

module Terraforming
  module Resource
    class IAMRole
      include Terraforming::Util

      def self.tf(client: Aws::IAM::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::IAM::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/iam_role")
      end

      def tfstate
        iam_roles.inject({}) do |resources, role|
          attributes = {
            "arn" => role.arn,
            "assume_role_policy" =>
              prettify_policy(role.assume_role_policy_document, breakline: true, unescape: true),
            "id" => role.role_name,
            "name" => role.role_name,
            "path" => role.path,
            "unique_id" => role.role_id,
          }
          resources["aws_iam_role.#{module_name_of(role)}"] = {
            "type" => "aws_iam_role",
            "primary" => {
              "id" => role.role_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def iam_roles
        @client.list_roles.map(&:roles).flatten
      end

      def module_name_of(role)
        normalize_module_name(role.role_name)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
terraforming-0.18.0 lib/terraforming/resource/iam_role.rb
terraforming-0.17.0 lib/terraforming/resource/iam_role.rb
terraforming-0.16.0 lib/terraforming/resource/iam_role.rb
terraforming-0.15.0 lib/terraforming/resource/iam_role.rb
aws-insight-0.14.1 lib/terraforming/resource/iam_role.rb
aws-insight-0.14.0 lib/terraforming/resource/iam_role.rb
terraforming-0.14.0 lib/terraforming/resource/iam_role.rb
terraforming-0.13.2 lib/terraforming/resource/iam_role.rb
terraforming-0.13.1 lib/terraforming/resource/iam_role.rb
terraforming-0.13.0 lib/terraforming/resource/iam_role.rb