Skip to content

Commit

Permalink
Catch Amazon's "Nothing Changed" error (can happen when just trying t…
Browse files Browse the repository at this point in the history
…o enable/disable a rule)
  • Loading branch information
tremble committed Mar 15, 2021
1 parent 174b0f5 commit 63170a4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/modules/s3_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_message
from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry

Expand Down Expand Up @@ -395,11 +396,11 @@ def compare_and_remove_rule(current_lifecycle_rules, rule_id=None, prefix=None):
return changed, lifecycle_configuration


def compare_rule(rule_a, rule_b, purge_transitions):
def compare_rule(new_rule, old_rule, purge_transitions):

# Copy objects
rule1 = deepcopy(rule_a)
rule2 = deepcopy(rule_b)
rule1 = deepcopy(new_rule)
rule2 = deepcopy(old_rule)

if purge_transitions:
return rule1 == rule2
Expand Down Expand Up @@ -452,8 +453,12 @@ def create_lifecycle_rule(client, module):
aws_retry=True,
Bucket=name,
LifecycleConfiguration=lifecycle_configuration)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e)
except is_boto3_error_message('At least one action needs to be specified in a rule'):
# Amazon interpretted this as not changing anything
changed = False
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, lifecycle_configuration=lifecycle_configuration, name=name, old_lifecycle_rules=old_lifecycle_rules)


_changed = changed
_retries = 10
Expand Down

0 comments on commit 63170a4

Please sign in to comment.