Skip to content

Commit

Permalink
Consistently handle 'UnsupportedOperationException' on key rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Nov 28, 2020
1 parent f2fa01f commit 4c8df40
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugins/modules/aws_kms.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def get_key_details(connection, module, key_id):
try:
current_rotation_status = connection.get_key_rotation_status(KeyId=key_id)
result['enable_key_rotation'] = current_rotation_status.get('KeyRotationEnabled')
except is_boto3_error_code('AccessDeniedException') as e:
except is_boto3_error_code(['AccessDeniedException', 'UnsupportedOperationException']) as e:
result['enable_key_rotation'] = None
result['aliases'] = aliases.get(result['KeyId'], [])

Expand Down
8 changes: 2 additions & 6 deletions plugins/modules/aws_kms_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def get_key_policy_with_backoff(connection, key_id, policy_name):
def get_enable_key_rotation_with_backoff(connection, key_id):
try:
current_rotation_status = connection.get_key_rotation_status(KeyId=key_id)
except is_boto3_error_code('AccessDeniedException') as e:
except is_boto3_error_code(['AccessDeniedException', 'UnsupportedOperationException']) as e:
return None

return current_rotation_status.get('KeyRotationEnabled')
Expand Down Expand Up @@ -408,11 +408,7 @@ def get_key_details(connection, module, key_id, tokens=None):
**camel_dict_to_snake_dict(e.response))
# We can only get aliases for our own account, so we don't need the full ARN
result['aliases'] = aliases.get(result['KeyId'], [])

if result['Origin'] == 'AWS_KMS':
result['enable_key_rotation'] = get_enable_key_rotation_with_backoff(connection, key_id)
else:
result['enable_key_rotation'] = None
result['enable_key_rotation'] = get_enable_key_rotation_with_backoff(connection, key_id)

if module.params.get('pending_deletion'):
return camel_dict_to_snake_dict(result)
Expand Down

0 comments on commit 4c8df40

Please sign in to comment.