Sha256: d2b87fed6ac9d530cbf3ff07583ec9205fd3a2350003b678af32e02cb8372536

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 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
        iam_users.inject({}) do |resources, user|
          attributes = {
            "arn"=> user.arn,
            "id" => user.user_name,
            "name" => user.user_name,
            "path" => user.path,
            "unique_id" => user.user_id,
          }
          resources["aws_iam_user.#{user.user_name}"] = {
            "type" => "aws_iam_user",
            "primary" => {
              "id" => user.user_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
terraforming-0.2.0 lib/terraforming/resource/iam_user.rb
terraforming-0.1.6 lib/terraforming/resource/iam_user.rb
terraforming-0.1.5 lib/terraforming/resource/iam_user.rb
terraforming-0.1.4 lib/terraforming/resource/iam_user.rb