Sha256: 03323750c32c16d64a5aa2e6edcde41e6363e999ea17e5e71afa151a7e2765b8

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module Terraforming
  module Resource
    class IAMUser
      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_user")
      end

      def tfstate
        resources = iam_users.inject({}) do |result, user|
          attributes = {
            "arn"=> user.arn,
            "id" => user.user_name,
            "name" => user.user_name,
            "path" => user.path,
            "unique_id" => user.user_id,
          }
          result["aws_iam_user.#{user.user_name}"] = {
            "type" => "aws_iam_user",
            "primary" => {
              "id" => user.user_name,
              "attributes" => attributes
            }
          }

          result
        end

        generate_tfstate(resources)
      end

      private

      def iam_users
        @client.list_users.users
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
terraforming-0.0.5 lib/terraforming/resource/iam_user.rb
terraforming-0.0.4 lib/terraforming/resource/iam_user.rb
terraforming-0.0.3 lib/terraforming/resource/iam_user.rb