class PracticeTerraforming::Resource::IAMUser

Public Class Methods

new(client) click to toggle source
# File lib/practice_terraforming/resource/iam_user.rb, line 20
def initialize(client)
  @client = client
end
tf(client: Aws::IAM::Client.new) click to toggle source

TODO: Select appropriate Client class from here: docs.aws.amazon.com/sdkforruby/api/index.html

# File lib/practice_terraforming/resource/iam_user.rb, line 10
def self.tf(client: Aws::IAM::Client.new)
  self.new(client).tf
end
tfstate(client: Aws::IAM::Client.new) click to toggle source

TODO: Select appropriate Client class from here: docs.aws.amazon.com/sdkforruby/api/index.html

# File lib/practice_terraforming/resource/iam_user.rb, line 16
def self.tfstate(client: Aws::IAM::Client.new)
  self.new(client).tfstate
end

Public Instance Methods

tf() click to toggle source
# File lib/practice_terraforming/resource/iam_user.rb, line 24
def tf
  apply_template(@client, "tf/iam_user")
end
tfstate() click to toggle source
# File lib/practice_terraforming/resource/iam_user.rb, line 28
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,
      "force_destroy" => "true"
    }
    resources["aws_iam_user.#{module_name_of(user)}"] = {
      "type" => "aws_iam_user",
      "primary" => {
        "id" => user.user_name,
        "attributes" => attributes
      }
    }

    resources
  end
end

Private Instance Methods

iam_tags_of(user) click to toggle source
# File lib/practice_terraforming/resource/iam_user.rb, line 56
def iam_tags_of(user)
  @client.list_user_tags(user_name: user.user_name).map(&:tags).flatten
end
iam_users() click to toggle source
# File lib/practice_terraforming/resource/iam_user.rb, line 52
def iam_users
  @client.list_users.map(&:users).flatten
end
module_name_of(user) click to toggle source
# File lib/practice_terraforming/resource/iam_user.rb, line 60
def module_name_of(user)
  normalize_module_name(user.user_name)
end