Class: Terraforming::Resource::KMSKey

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/kms_key.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) ⇒ KMSKey

Returns a new instance of KMSKey.



14
15
16
# File 'lib/terraforming/resource/kms_key.rb', line 14

def initialize(client)
  @client = client
end

Class Method Details

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



6
7
8
# File 'lib/terraforming/resource/kms_key.rb', line 6

def self.tf(client: Aws::KMS::Client.new)
  self.new(client).tf
end

.tfstate(client: Aws::KMS::Client.new) ⇒ Object



10
11
12
# File 'lib/terraforming/resource/kms_key.rb', line 10

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

Instance Method Details

#tfObject



18
19
20
# File 'lib/terraforming/resource/kms_key.rb', line 18

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

#tfstateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/terraforming/resource/kms_key.rb', line 22

def tfstate
  keys.inject({}) do |resources, key|
    resources["aws_kms_key.#{module_name_of(key)}"] = {
      "type" => "aws_kms_key",
      "primary" => {
        "id" => key.key_id,
        "attributes" => {
          "arn" => key.arn,
          "description" => key.description,
          "enable_key_rotation" => key_rotation_status_of(key).key_rotation_enabled.to_s,
          "id" => key.key_id,
          "is_enabled" => key.enabled.to_s,
          "key_id" => key.key_id,
          "key_usage" => key_usage_of(key),
          "policy" => key_policy_of(key),
        },
      },
    }
    resources
  end
end