# Buggy code
def update_password_policy(self, module, policy):
    min_pw_length = module.params.get("min_pw_length")
    require_symbols = module.params.get("require_symbols")
    require_numbers = module.params.get("require_numbers")
    require_uppercase = module.params.get("require_uppercase")
    require_lowercase = module.params.get("require_lowercase")
    allow_pw_change = module.params.get("allow_pw_change")
    pw_max_age = module.params.get("pw_max_age")
    pw_reuse_prevent = module.params.get("pw_reuse_prevent")
    pw_expire = module.params.get("pw_expire")

    try:
        results = policy.update(
            MinimumPasswordLength=min_pw_length,
            RequireSymbols=require_symbols,
            RequireNumbers=require_numbers,
            RequireUppercaseCharacters=require_uppercase,
            RequireLowercaseCharacters=require_lowercase,
            AllowUsersToChangePassword=allow_pw_change,
            MaxPasswordAge=pw_max_age,
            PasswordReusePrevention=pw_reuse_prevent,
            HardExpiry=pw_expire,
        )
        policy.reload()
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        self.module.fail_json_aws(e, msg="Couldn't update IAM Password Policy")
    return camel_dict_to_snake_dict(results)


# Traceback (ParamValidationError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_iam_password_policy_payload_gn34QS/__main__.py", line 140, in update_password_policy
HardExpiry=pw_expire
File "/usr/lib/python2.7/site-packages/boto3/resources/factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 575, in _make_api_call
api_params, operation_model, context=request_context)
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 630, in _convert_to_request_dict
api_params, operation_model)
File "/usr/lib/python2.7/site-packages/botocore/validate.py", line 291, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
ParamValidationError: Parameter validation failed:
Invalid range for parameter MaxPasswordAge, value: 0, valid range: 1-inf

fatal: [it-cloud-aws-login -> localhost]: FAILED! => {
"boto3_version": "1.4.6",
"botocore_version": "1.6.0",
"changed": false,
"invocation": {
"module_args": {
"allow_pw_change": true,
"aws_access_key": null,
"aws_secret_key": null,
"debug_botocore_endpoint_logs": false,
"ec2_url": null,
"min_pw_length": 14,
"profile": null,
"pw_expire": false,
"pw_max_age": 0,
"pw_reuse_prevent": 6,
"region": null,
"require_lowercase": true,
"require_numbers": true,
"require_symbols": true,
"require_uppercase": true,
"security_token": null,
"state": "present",
"validate_certs": true
}
},
"msg": "Couldn't update IAM Password Policy: Parameter validation failed:\nInvalid range for parameter MaxPasswordAge, value: 0, valid range: 1-inf"
}

# Fixed code
def update_password_policy(self, module, policy):
    min_pw_length = module.params.get("min_pw_length")
    require_symbols = module.params.get("require_symbols")
    require_numbers = module.params.get("require_numbers")
    require_uppercase = module.params.get("require_uppercase")
    require_lowercase = module.params.get("require_lowercase")
    allow_pw_change = module.params.get("allow_pw_change")
    pw_max_age = module.params.get("pw_max_age")
    pw_reuse_prevent = module.params.get("pw_reuse_prevent")
    pw_expire = module.params.get("pw_expire")

    update_parameters = dict(
        MinimumPasswordLength=min_pw_length,
        RequireSymbols=require_symbols,
        RequireNumbers=require_numbers,
        RequireUppercaseCharacters=require_uppercase,
        RequireLowercaseCharacters=require_lowercase,
        AllowUsersToChangePassword=allow_pw_change,
        PasswordReusePrevention=pw_reuse_prevent,
        HardExpiry=pw_expire,
    )
    if pw_max_age:
        update_parameters.update(MaxPasswordAge=pw_max_age)

    try:
        results = policy.update(**update_parameters)
        policy.reload()
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        self.module.fail_json_aws(e, msg="Couldn't update IAM Password Policy")
    return camel_dict_to_snake_dict(results)