Class: PracticeTerraforming::Resource::IAMUser

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/practice_terraforming/resource/iam_user.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #name_from_tag, #normalize_module_name, #prettify_policy, #template_path

Constructor Details

#initialize(client) ⇒ IAMUser

Returns a new instance of IAMUser.



20
21
22
# File 'lib/practice_terraforming/resource/iam_user.rb', line 20

def initialize(client)
  @client = client
end

Class Method Details

.tf(client: Aws::IAM::Client.new) ⇒ Object

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



10
11
12
# 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) ⇒ Object

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



16
17
18
# File 'lib/practice_terraforming/resource/iam_user.rb', line 16

def self.tfstate(client: Aws::IAM::Client.new)
  self.new(client).tfstate
end

Instance Method Details

#tfObject



24
25
26
# File 'lib/practice_terraforming/resource/iam_user.rb', line 24

def tf
  apply_template(@client, "tf/iam_user")
end

#tfstateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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" => "false",
      "tags" => iam_tags_of(user).map { |t| [t.key, t.value] }.to_h
    }
    resources["aws_iam_user.#{module_name_of(user)}"] = {
      "type" => "aws_iam_user",
      "primary" => {
        "id" => user.user_name,
        "attributes" => attributes
      }
    }

    resources
  end
end