Sha256: 33f459e0784b6eabf9ffe3192d067e7d083971ccac1e7a1e11a6fa05badd82a5

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 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.#{module_name_of(user)}"] = {
            "type" => "aws_iam_user",
            "primary" => {
              "id" => user.user_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def iam_users
        @client.list_users.users
      end

      def module_name_of(user)
        normalize_module_name(user.user_name)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
terraforming-0.6.2 lib/terraforming/resource/iam_user.rb
terraforming-0.6.1 lib/terraforming/resource/iam_user.rb
terraforming-0.6.0 lib/terraforming/resource/iam_user.rb
terraforming-0.5.0 lib/terraforming/resource/iam_user.rb
terraforming-0.4.0 lib/terraforming/resource/iam_user.rb
terraforming-0.3.2 lib/terraforming/resource/iam_user.rb
terraforming-0.3.1 lib/terraforming/resource/iam_user.rb
terraforming-0.3.0 lib/terraforming/resource/iam_user.rb