Sha256: b1995963c016a30366d7877a89543282ec058ac906870bc784606e14a47c6603

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 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.#{role.role_name}"] = {
            "type" => "aws_iam_role",
            "primary" => {
              "id" => role.role_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def iam_roles
        @client.list_roles.roles
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
terraforming-0.7.0 lib/terraforming/resource/iam_role.rb
terraforming-0.6.2 lib/terraforming/resource/iam_role.rb
terraforming-0.6.1 lib/terraforming/resource/iam_role.rb
terraforming-0.6.0 lib/terraforming/resource/iam_role.rb
terraforming-0.5.0 lib/terraforming/resource/iam_role.rb
terraforming-0.4.0 lib/terraforming/resource/iam_role.rb
terraforming-0.3.2 lib/terraforming/resource/iam_role.rb
terraforming-0.3.1 lib/terraforming/resource/iam_role.rb
terraforming-0.3.0 lib/terraforming/resource/iam_role.rb
terraforming-0.2.0 lib/terraforming/resource/iam_role.rb
terraforming-0.1.6 lib/terraforming/resource/iam_role.rb
terraforming-0.1.5 lib/terraforming/resource/iam_role.rb