Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding tags attribute to KMS key resource #522

Merged
merged 7 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/resources/aws_kms_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ See also the [AWS documentation on KS Keys](https://docs.aws.amazon.com/kms/late
|description | The description of the key. |
|deletion\_time | Specifies the date and time after which AWS KMS deletes the key. This value is present only when KeyState is PendingDeletion, otherwise this value is nil. |
|invalidation\_time | Provides the date and time until the key is not valid. Once the key is not valid, AWS KMS deletes the key and it becomes unusable. This value will be null unless the keys Origin is EXTERNAL and its matcher have\_key\_expiration is set to true. |
|tags | A hash with each key-value pair corresponding to a tag associated with the entity. |

## Examples

Expand Down
16 changes: 16 additions & 0 deletions libraries/aws_kms_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ def exists?
!@key.empty?
end

def kms_tags(tag_list)
return {} if tag_list.nil? || tag_list.empty?
tags = {}
tag_list.each do |tag|
tags[tag[:tag_key]] = tag[:tag_value]
end
tags
end

def tags
catch_aws_errors do
tag_list = @aws.kms_client.list_resource_tags(key_id: @display_name).tags
kms_tags(tag_list)
end
end

def created_days_ago
((Time.now - @key[:creation_date]) / (24 * 60 * 60)).to_i unless @key[:creation_date].nil?
end
Expand Down