Repository: crossplane-contrib/provider-aws (go)

Issue:
New Distribution Bugs and Issues
<!--
Thank you for helping to improve Crossplane!

Please be sure to search for open issues before raising a new one. We use issues
for bug reports and feature requests. Please find us at https://slack.crossplane.io
for questions, support, and discussion.
-->

### What happened?
<!--
Please let us know what behaviour you expected and how Crossplane diverged from
that behaviour.
-->
On a Distributions CacheBehaviors there are lambdaFunctionAssociations and functionAssociations
The functionAssociations still has quantity on it and did not exist in the previous version 0.24.1. 

I also get this error when making a new Distribution:
```
- lastTransitionTime: '2022-03-14T20:48:24Z'
      message: >
        create failed: cannot create Distribution in AWS: InvalidParameter: 10
        validation error(s) found.

        - missing required field,
        CreateDistributionInput.DistributionConfig.CacheBehaviors.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.CustomErrorResponses.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Headers.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.DefaultCacheBehavior.ForwardedValues.QueryStringCacheKeys.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.DefaultCacheBehavior.TrustedKeyGroups.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.DefaultCacheBehavior.TrustedSigners.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.OriginGroups.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.Origins.Items[0].CustomHeaders.Quantity.

        - missing required field,
        CreateDistributionInput.DistributionConfig.Restrictions.GeoRestriction.Quantity.
      reason: ReconcileError
      status: 'False'
      type: Synced
```



Pull request:
fix(cloudfront): Send zero instead of nil during create/update
### Description of your changes

This is Fixes #1210, the issue is arised due to the usage of the function `ToIntAsInt64` returns nil when the value is `0`. Since the AWS API for CloudFront expects an actual "Quantity: 0" value, returning nil makes the API complain with something like:

```
create failed: cannot create Distribution in AWS: InvalidParameter: 10
	validation error(s) found.

	- missing required field,
	CreateDistributionInput.DistributionConfig.CacheBehaviors.Quantity.

	- missing required field,
	CreateDistributionInput.DistributionConfig.CustomErrorResponses.Quantity.
...
```

This creates the utility function `ToIntAsInt64Zero` to allow the value `0` to be converted, thus fulfilling the requirement for the CloudFront API to have a real value, even if is zero.

I have:

- [x] Read and followed Crossplane's [contribution process].
- [ ] Run `make reviewable test` to ensure this PR is ready for review.

### How has this code been tested

Tested it in a productive environment where the error was happening.


Patch:
diff --git a/pkg/controller/cloudfront/distribution/setup.go b/pkg/controller/cloudfront/distribution/setup.go
index 7cdd13519..45f0b2f3d 100644
--- a/pkg/controller/cloudfront/distribution/setup.go
+++ b/pkg/controller/cloudfront/distribution/setup.go
@@ -107,157 +107,157 @@ func preCreate(_ context.Context, cr *svcapitypes.Distribution, cdi *svcsdk.Crea
 	// if cr.Spec.ForProvider.DistributionConfig.Origins is not nil then cdi.DistributionConfig.Origins is not nil
 	if cr.Spec.ForProvider.DistributionConfig.Origins != nil {
 		cdi.DistributionConfig.Origins.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.Aliases != nil {
 		cdi.DistributionConfig.Aliases.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Aliases.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Aliases.Items))
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.CustomErrorResponses != nil {
 		cdi.DistributionConfig.CustomErrorResponses.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.CustomErrorResponses.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.CustomErrorResponses.Items))
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.Restrictions != nil && cr.Spec.ForProvider.DistributionConfig.Restrictions.GeoRestriction != nil {
 		cdi.DistributionConfig.Restrictions.GeoRestriction.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Restrictions.GeoRestriction.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Restrictions.GeoRestriction.Items))
 	}
 
 	dcb := cr.Spec.ForProvider.DistributionConfig.DefaultCacheBehavior
 	if dcb != nil {
 		if dcb.AllowedMethods != nil {
 			cdi.DistributionConfig.DefaultCacheBehavior.AllowedMethods.Quantity =
-				pointer.ToIntAsInt64(len(dcb.AllowedMethods.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.AllowedMethods.Items))
 
 			if dcb.AllowedMethods != nil && dcb.AllowedMethods.CachedMethods != nil {
 				cdi.DistributionConfig.DefaultCacheBehavior.AllowedMethods.CachedMethods.Quantity =
-					pointer.ToIntAsInt64(len(dcb.AllowedMethods.CachedMethods.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.AllowedMethods.CachedMethods.Items))
 			}
 		}
 
 		if dcb.ForwardedValues != nil {
 			if dcb.ForwardedValues.Cookies != nil && dcb.ForwardedValues.Cookies.WhitelistedNames != nil {
 				cdi.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Cookies.WhitelistedNames.Quantity =
-					pointer.ToIntAsInt64(len(dcb.ForwardedValues.Cookies.WhitelistedNames.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.ForwardedValues.Cookies.WhitelistedNames.Items))
 			}
 
 			if dcb.ForwardedValues.Headers != nil {
 				cdi.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Headers.Quantity =
-					pointer.ToIntAsInt64(len(dcb.ForwardedValues.Headers.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.ForwardedValues.Headers.Items))
 			}
 
 			if dcb.ForwardedValues.QueryStringCacheKeys != nil {
 				cdi.DistributionConfig.DefaultCacheBehavior.ForwardedValues.QueryStringCacheKeys.Quantity =
-					pointer.ToIntAsInt64(len(dcb.ForwardedValues.QueryStringCacheKeys.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.ForwardedValues.QueryStringCacheKeys.Items))
 			}
 		}
 
 		if dcb.FunctionAssociations != nil {
 			cdi.DistributionConfig.DefaultCacheBehavior.FunctionAssociations.Quantity =
-				pointer.ToIntAsInt64(len(dcb.FunctionAssociations.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.FunctionAssociations.Items))
 		}
 
 		if dcb.LambdaFunctionAssociations != nil {
 			cdi.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Quantity =
-				pointer.ToIntAsInt64(len(dcb.LambdaFunctionAssociations.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.LambdaFunctionAssociations.Items))
 		}
 
 		if dcb.TrustedKeyGroups != nil {
 			cdi.DistributionConfig.DefaultCacheBehavior.TrustedKeyGroups.Quantity =
-				pointer.ToIntAsInt64(len(dcb.TrustedKeyGroups.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.TrustedKeyGroups.Items))
 		}
 
 		if dcb.TrustedSigners != nil {
 			cdi.DistributionConfig.DefaultCacheBehavior.TrustedSigners.Quantity =
-				pointer.ToIntAsInt64(len(dcb.TrustedSigners.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.TrustedSigners.Items))
 		}
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.CacheBehaviors != nil {
 		cdi.DistributionConfig.CacheBehaviors.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.CacheBehaviors.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.CacheBehaviors.Items))
 
 		for i, cbi := range cr.Spec.ForProvider.DistributionConfig.CacheBehaviors.Items {
 			if cbi.AllowedMethods != nil {
 				cdi.DistributionConfig.CacheBehaviors.Items[i].AllowedMethods.Quantity =
-					pointer.ToIntAsInt64(len(cbi.AllowedMethods.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.AllowedMethods.Items))
 			}
 
 			if cbi.AllowedMethods != nil && cbi.AllowedMethods.CachedMethods != nil {
 				cdi.DistributionConfig.CacheBehaviors.Items[i].AllowedMethods.CachedMethods.Quantity =
-					pointer.ToIntAsInt64(len(cbi.AllowedMethods.CachedMethods.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.AllowedMethods.CachedMethods.Items))
 			}
 
 			if cbi.ForwardedValues != nil {
 				if cbi.ForwardedValues.Cookies != nil && cbi.ForwardedValues.Cookies.WhitelistedNames != nil {
 					cdi.DistributionConfig.CacheBehaviors.Items[i].ForwardedValues.Cookies.WhitelistedNames.Quantity =
-						pointer.ToIntAsInt64(len(cbi.ForwardedValues.Cookies.WhitelistedNames.Items))
+						pointer.ToIntAsInt64Zero(len(cbi.ForwardedValues.Cookies.WhitelistedNames.Items))
 				}
 
 				if cbi.ForwardedValues.Headers != nil {
 					cdi.DistributionConfig.CacheBehaviors.Items[i].ForwardedValues.Headers.Quantity =
-						pointer.ToIntAsInt64(len(cbi.ForwardedValues.Headers.Items))
+						pointer.ToIntAsInt64Zero(len(cbi.ForwardedValues.Headers.Items))
 				}
 
 				if cbi.ForwardedValues.QueryStringCacheKeys != nil {
 					cdi.DistributionConfig.CacheBehaviors.Items[i].ForwardedValues.QueryStringCacheKeys.Quantity =
-						pointer.ToIntAsInt64(len(cbi.ForwardedValues.QueryStringCacheKeys.Items))
+						pointer.ToIntAsInt64Zero(len(cbi.ForwardedValues.QueryStringCacheKeys.Items))
 				}
 			}
 
 			if cbi.FunctionAssociations != nil {
 				cdi.DistributionConfig.CacheBehaviors.Items[i].FunctionAssociations.Quantity =
-					pointer.ToIntAsInt64(len(cbi.FunctionAssociations.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.FunctionAssociations.Items))
 			}
 
 			if cbi.LambdaFunctionAssociations != nil {
 				cdi.DistributionConfig.CacheBehaviors.Items[i].LambdaFunctionAssociations.Quantity =
-					pointer.ToIntAsInt64(len(cbi.LambdaFunctionAssociations.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.LambdaFunctionAssociations.Items))
 			}
 
 			if cbi.TrustedKeyGroups != nil {
 				cdi.DistributionConfig.CacheBehaviors.Items[i].TrustedKeyGroups.Quantity =
-					pointer.ToIntAsInt64(len(cbi.TrustedKeyGroups.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.TrustedKeyGroups.Items))
 			}
 
 			if cbi.TrustedSigners != nil {
 				cdi.DistributionConfig.CacheBehaviors.Items[i].TrustedSigners.Quantity =
-					pointer.ToIntAsInt64(len(cbi.TrustedSigners.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.TrustedSigners.Items))
 			}
 		}
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.OriginGroups != nil {
 		cdi.DistributionConfig.OriginGroups.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.OriginGroups.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.OriginGroups.Items))
 
 		for i, ogi := range cr.Spec.ForProvider.DistributionConfig.OriginGroups.Items {
 			if ogi.FailoverCriteria != nil && ogi.FailoverCriteria.StatusCodes != nil {
 				cdi.DistributionConfig.OriginGroups.Items[i].FailoverCriteria.StatusCodes.Quantity =
-					pointer.ToIntAsInt64(len(ogi.FailoverCriteria.StatusCodes.Items))
+					pointer.ToIntAsInt64Zero(len(ogi.FailoverCriteria.StatusCodes.Items))
 			}
 
 			if ogi.Members != nil {
-				cdi.DistributionConfig.OriginGroups.Items[i].Members.Quantity = pointer.ToIntAsInt64(len(ogi.Members.Items))
+				cdi.DistributionConfig.OriginGroups.Items[i].Members.Quantity = pointer.ToIntAsInt64Zero(len(ogi.Members.Items))
 			}
 		}
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.Origins != nil {
 		cdi.DistributionConfig.Origins.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
 
 		for i, io := range cr.Spec.ForProvider.DistributionConfig.Origins.Items {
 			if io.CustomHeaders != nil {
 				cdi.DistributionConfig.Origins.Items[i].CustomHeaders.Quantity =
-					pointer.ToIntAsInt64(len(io.CustomHeaders.Items))
+					pointer.ToIntAsInt64Zero(len(io.CustomHeaders.Items))
 			}
 
 			if io.CustomOriginConfig != nil && io.CustomOriginConfig.OriginSSLProtocols != nil {
 				cdi.DistributionConfig.Origins.Items[i].CustomOriginConfig.OriginSslProtocols.Quantity =
-					pointer.ToIntAsInt64(len(io.CustomOriginConfig.OriginSSLProtocols.Items))
+					pointer.ToIntAsInt64Zero(len(io.CustomOriginConfig.OriginSSLProtocols.Items))
 			}
 		}
 	}
@@ -353,154 +353,154 @@ func preUpdate(_ context.Context, cr *svcapitypes.Distribution, udi *svcsdk.Upda
 	udi.Id = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
 	udi.SetIfMatch(pointer.StringValue(cr.Status.AtProvider.ETag))
 	udi.DistributionConfig.Origins.Quantity =
-		pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
+		pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
 
 	if cr.Spec.ForProvider.DistributionConfig.Aliases != nil {
 		udi.DistributionConfig.Aliases.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Aliases.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Aliases.Items))
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.CustomErrorResponses != nil {
 		udi.DistributionConfig.CustomErrorResponses.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.CustomErrorResponses.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.CustomErrorResponses.Items))
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.Restrictions != nil && cr.Spec.ForProvider.DistributionConfig.Restrictions.GeoRestriction != nil {
 		udi.DistributionConfig.Restrictions.GeoRestriction.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Restrictions.GeoRestriction.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Restrictions.GeoRestriction.Items))
 	}
 
 	dcb := cr.Spec.ForProvider.DistributionConfig.DefaultCacheBehavior
 	if dcb != nil {
 		if dcb.AllowedMethods != nil {
 			udi.DistributionConfig.DefaultCacheBehavior.AllowedMethods.Quantity =
-				pointer.ToIntAsInt64(len(dcb.AllowedMethods.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.AllowedMethods.Items))
 
 			if dcb.AllowedMethods != nil && dcb.AllowedMethods.CachedMethods != nil {
 				udi.DistributionConfig.DefaultCacheBehavior.AllowedMethods.CachedMethods.Quantity =
-					pointer.ToIntAsInt64(len(dcb.AllowedMethods.CachedMethods.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.AllowedMethods.CachedMethods.Items))
 			}
 		}
 
 		if dcb.ForwardedValues != nil {
 			if dcb.ForwardedValues.Cookies != nil && dcb.ForwardedValues.Cookies.WhitelistedNames != nil {
 				udi.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Cookies.WhitelistedNames.Quantity =
-					pointer.ToIntAsInt64(len(dcb.ForwardedValues.Cookies.WhitelistedNames.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.ForwardedValues.Cookies.WhitelistedNames.Items))
 			}
 
 			if dcb.ForwardedValues.Headers != nil {
 				udi.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Headers.Quantity =
-					pointer.ToIntAsInt64(len(dcb.ForwardedValues.Headers.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.ForwardedValues.Headers.Items))
 			}
 
 			if dcb.ForwardedValues.QueryStringCacheKeys != nil {
 				udi.DistributionConfig.DefaultCacheBehavior.ForwardedValues.QueryStringCacheKeys.Quantity =
-					pointer.ToIntAsInt64(len(dcb.ForwardedValues.QueryStringCacheKeys.Items))
+					pointer.ToIntAsInt64Zero(len(dcb.ForwardedValues.QueryStringCacheKeys.Items))
 			}
 		}
 		if dcb.FunctionAssociations != nil {
 			udi.DistributionConfig.DefaultCacheBehavior.FunctionAssociations.Quantity =
-				pointer.ToIntAsInt64(len(dcb.FunctionAssociations.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.FunctionAssociations.Items))
 		}
 
 		if dcb.LambdaFunctionAssociations != nil {
 			udi.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Quantity =
-				pointer.ToIntAsInt64(len(dcb.LambdaFunctionAssociations.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.LambdaFunctionAssociations.Items))
 		}
 
 		if dcb.TrustedKeyGroups != nil {
 			udi.DistributionConfig.DefaultCacheBehavior.TrustedKeyGroups.Quantity =
-				pointer.ToIntAsInt64(len(dcb.TrustedKeyGroups.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.TrustedKeyGroups.Items))
 		}
 
 		if dcb.TrustedSigners != nil {
 			udi.DistributionConfig.DefaultCacheBehavior.TrustedSigners.Quantity =
-				pointer.ToIntAsInt64(len(dcb.TrustedSigners.Items))
+				pointer.ToIntAsInt64Zero(len(dcb.TrustedSigners.Items))
 		}
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.CacheBehaviors != nil {
 		udi.DistributionConfig.CacheBehaviors.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.CacheBehaviors.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.CacheBehaviors.Items))
 
 		for i, cbi := range cr.Spec.ForProvider.DistributionConfig.CacheBehaviors.Items {
 			if cbi.AllowedMethods != nil {
 				udi.DistributionConfig.CacheBehaviors.Items[i].AllowedMethods.Quantity =
-					pointer.ToIntAsInt64(len(cbi.AllowedMethods.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.AllowedMethods.Items))
 			}
 
 			if cbi.AllowedMethods != nil && cbi.AllowedMethods.CachedMethods != nil {
 				udi.DistributionConfig.CacheBehaviors.Items[i].AllowedMethods.CachedMethods.Quantity =
-					pointer.ToIntAsInt64(len(cbi.AllowedMethods.CachedMethods.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.AllowedMethods.CachedMethods.Items))
 			}
 
 			if cbi.ForwardedValues != nil {
 				if cbi.ForwardedValues.Cookies != nil && cbi.ForwardedValues.Cookies.WhitelistedNames != nil {
 					udi.DistributionConfig.CacheBehaviors.Items[i].ForwardedValues.Cookies.WhitelistedNames.Quantity =
-						pointer.ToIntAsInt64(len(cbi.ForwardedValues.Cookies.WhitelistedNames.Items))
+						pointer.ToIntAsInt64Zero(len(cbi.ForwardedValues.Cookies.WhitelistedNames.Items))
 				}
 
 				if cbi.ForwardedValues.Headers != nil {
 					udi.DistributionConfig.CacheBehaviors.Items[i].ForwardedValues.Headers.Quantity =
-						pointer.ToIntAsInt64(len(cbi.ForwardedValues.Headers.Items))
+						pointer.ToIntAsInt64Zero(len(cbi.ForwardedValues.Headers.Items))
 				}
 
 				if cbi.ForwardedValues.QueryStringCacheKeys != nil {
 					udi.DistributionConfig.CacheBehaviors.Items[i].ForwardedValues.QueryStringCacheKeys.Quantity =
-						pointer.ToIntAsInt64(len(cbi.ForwardedValues.QueryStringCacheKeys.Items))
+						pointer.ToIntAsInt64Zero(len(cbi.ForwardedValues.QueryStringCacheKeys.Items))
 				}
 			}
 
 			if cbi.FunctionAssociations != nil {
 				udi.DistributionConfig.CacheBehaviors.Items[i].FunctionAssociations.Quantity =
-					pointer.ToIntAsInt64(len(cbi.FunctionAssociations.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.FunctionAssociations.Items))
 			}
 
 			if cbi.LambdaFunctionAssociations != nil {
 				udi.DistributionConfig.CacheBehaviors.Items[i].LambdaFunctionAssociations.Quantity =
-					pointer.ToIntAsInt64(len(cbi.LambdaFunctionAssociations.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.LambdaFunctionAssociations.Items))
 			}
 
 			if cbi.TrustedKeyGroups != nil {
 				udi.DistributionConfig.CacheBehaviors.Items[i].TrustedKeyGroups.Quantity =
-					pointer.ToIntAsInt64(len(cbi.TrustedKeyGroups.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.TrustedKeyGroups.Items))
 			}
 
 			if cbi.TrustedSigners != nil {
 				udi.DistributionConfig.CacheBehaviors.Items[i].TrustedSigners.Quantity =
-					pointer.ToIntAsInt64(len(cbi.TrustedSigners.Items))
+					pointer.ToIntAsInt64Zero(len(cbi.TrustedSigners.Items))
 			}
 		}
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.OriginGroups != nil {
 		udi.DistributionConfig.OriginGroups.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.OriginGroups.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.OriginGroups.Items))
 
 		for i, ogi := range cr.Spec.ForProvider.DistributionConfig.OriginGroups.Items {
 			if ogi.FailoverCriteria != nil && ogi.FailoverCriteria.StatusCodes != nil {
 				udi.DistributionConfig.OriginGroups.Items[i].FailoverCriteria.StatusCodes.Quantity =
-					pointer.ToIntAsInt64(len(ogi.FailoverCriteria.StatusCodes.Items))
+					pointer.ToIntAsInt64Zero(len(ogi.FailoverCriteria.StatusCodes.Items))
 			}
 
 			if ogi.Members != nil {
-				udi.DistributionConfig.OriginGroups.Items[i].Members.Quantity = pointer.ToIntAsInt64(len(ogi.Members.Items))
+				udi.DistributionConfig.OriginGroups.Items[i].Members.Quantity = pointer.ToIntAsInt64Zero(len(ogi.Members.Items))
 			}
 		}
 	}
 
 	if cr.Spec.ForProvider.DistributionConfig.Origins != nil {
 		udi.DistributionConfig.Origins.Quantity =
-			pointer.ToIntAsInt64(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
+			pointer.ToIntAsInt64Zero(len(cr.Spec.ForProvider.DistributionConfig.Origins.Items))
 
 		for i, io := range cr.Spec.ForProvider.DistributionConfig.Origins.Items {
 			if io.CustomHeaders != nil {
 				udi.DistributionConfig.Origins.Items[i].CustomHeaders.Quantity =
-					pointer.ToIntAsInt64(len(io.CustomHeaders.Items))
+					pointer.ToIntAsInt64Zero(len(io.CustomHeaders.Items))
 			}
 			if io.CustomOriginConfig != nil && io.CustomOriginConfig.OriginSSLProtocols != nil {
 				udi.DistributionConfig.Origins.Items[i].CustomOriginConfig.OriginSslProtocols.Quantity =
-					pointer.ToIntAsInt64(len(io.CustomOriginConfig.OriginSSLProtocols.Items))
+					pointer.ToIntAsInt64Zero(len(io.CustomOriginConfig.OriginSSLProtocols.Items))
 			}
 		}
 	}
diff --git a/pkg/controller/s3/bucket/lifecycleConfig.go b/pkg/controller/s3/bucket/lifecycleConfig.go
index 8abc2551f..fe19afb1c 100644
--- a/pkg/controller/s3/bucket/lifecycleConfig.go
+++ b/pkg/controller/s3/bucket/lifecycleConfig.go
@@ -161,19 +161,13 @@ func GenerateLifecycleRules(in []v1beta1.LifecycleRule) []types.LifecycleRule {
 			}
 		}
 		if local.Expiration != nil {
-			rule.Expiration = &types.LifecycleExpiration{}
-			if local.Expiration.Days > 0 {
-				rule.Expiration.Days = ptr.To(local.Expiration.Days)
+			rule.Expiration = &types.LifecycleExpiration{
+				Days:                      ptr.To(local.Expiration.Days),
+				ExpiredObjectDeleteMarker: ptr.To(local.Expiration.ExpiredObjectDeleteMarker),
 			}
 			if local.Expiration.Date != nil {
 				rule.Expiration.Date = ptr.To(local.Expiration.Date.Time)
 			}
-			// NOTE(kkendzia): ExpiredObjectDeleteMarker must not be set when Days or Date is specified
-			// This behaviour is in line with terraform provider aws and avoids a MalformedXML Error
-			// When both is set, ExpiredObjectDeleteMarker will be ignored.
-			if local.Expiration.Date == nil && local.Expiration.Days == 0 {
-				rule.Expiration.ExpiredObjectDeleteMarker = ptr.To(local.Expiration.ExpiredObjectDeleteMarker)
-			}
 		}
 		if local.NoncurrentVersionExpiration != nil {
 			rule.NoncurrentVersionExpiration = &types.NoncurrentVersionExpiration{NoncurrentDays: ptr.To(local.NoncurrentVersionExpiration.NoncurrentDays)}
diff --git a/pkg/utils/pointer/pointer.go b/pkg/utils/pointer/pointer.go
index 44226f221..8b6c3df1a 100644
--- a/pkg/utils/pointer/pointer.go
+++ b/pkg/utils/pointer/pointer.go
@@ -53,6 +53,12 @@ func ToIntAsInt64(v int) *int64 {
 	return &val64
 }
 
+// Int64 converts the supplied int for use with the AWS Go SDK, this allows 0 to be converted.
+func ToIntAsInt64Zero(v int) *int64 {
+	val64 := int64(v)
+	return &val64
+}
+
 // Int32 converts the supplied int for use with the AWS Go SDK.
 func ToIntAsInt32(v int) *int32 {
 	if v == 0 {


Test patch:
diff --git a/pkg/controller/s3/bucket/lifecycleConfig_test.go b/pkg/controller/s3/bucket/lifecycleConfig_test.go
index c26403226..aa11ed9cd 100644
--- a/pkg/controller/s3/bucket/lifecycleConfig_test.go
+++ b/pkg/controller/s3/bucket/lifecycleConfig_test.go
@@ -44,7 +44,7 @@ var (
 	location, _       = time.LoadLocation("UTC")
 	date              = metav1.Date(2020, time.September, 25, 11, 40, 0, 0, location)
 	awsDate           = time.Date(2020, time.September, 25, 11, 40, 0, 0, location)
-	marker            = true
+	marker            = false
 	prefix            = "test-"
 	id                = "test-id"
 	storage           = "ONEZONE_IA"
@@ -58,8 +58,9 @@ func generateLifecycleConfig() *v1beta1.BucketLifecycleConfiguration {
 			{
 				AbortIncompleteMultipartUpload: &v1beta1.AbortIncompleteMultipartUpload{DaysAfterInitiation: 1},
 				Expiration: &v1beta1.LifecycleExpiration{
-					Date: &date,
-					Days: days,
+					Date:                      &date,
+					Days:                      days,
+					ExpiredObjectDeleteMarker: marker,
 				},
 				Filter: &v1beta1.LifecycleRuleFilter{
 					And: &v1beta1.LifecycleRuleAndOperator{
@@ -84,14 +85,6 @@ func generateLifecycleConfig() *v1beta1.BucketLifecycleConfiguration {
 	}
 }
 
-func generateLifecycleConfigWithMarker() *v1beta1.BucketLifecycleConfiguration {
-	res := generateLifecycleConfig()
-	res.Rules[0].Expiration = &v1beta1.LifecycleExpiration{
-		ExpiredObjectDeleteMarker: marker,
-	}
-	return res
-}
-
 func generateAWSLifecycle(sortTag bool) *s3types.BucketLifecycleConfiguration {
 	conf := &s3types.BucketLifecycleConfiguration{
 		Rules: []s3types.LifecycleRule{
@@ -100,7 +93,7 @@ func generateAWSLifecycle(sortTag bool) *s3types.BucketLifecycleConfiguration {
 				Expiration: &s3types.LifecycleExpiration{
 					Date:                      &awsDate,
 					Days:                      &days,
-					ExpiredObjectDeleteMarker: nil,
+					ExpiredObjectDeleteMarker: &marker,
 				},
 				Filter: &s3types.LifecycleRuleFilterMemberAnd{
 					Value: s3types.LifecycleRuleAndOperator{
@@ -129,14 +122,6 @@ func generateAWSLifecycle(sortTag bool) *s3types.BucketLifecycleConfiguration {
 	return conf
 }
 
-func generateAWSLifecycleWithMarker(sortTag bool) *s3types.BucketLifecycleConfiguration {
-	res := generateAWSLifecycle(sortTag)
-	res.Rules[0].Expiration = &s3types.LifecycleExpiration{
-		ExpiredObjectDeleteMarker: &marker,
-	}
-	return res
-}
-
 func TestGenerateLifecycleConfiguration(t *testing.T) {
 	type args struct {
 		b *v1beta1.Bucket
@@ -158,14 +143,6 @@ func TestGenerateLifecycleConfiguration(t *testing.T) {
 				input: generateAWSLifecycle(true).Rules,
 			},
 		},
-		"Marker": {
-			args: args{
-				b: s3testing.Bucket(s3testing.WithLifecycleConfig(generateLifecycleConfigWithMarker())),
-			},
-			want: want{
-				input: generateAWSLifecycleWithMarker(true).Rules,
-			},
-		},
 	}
 
 	for name, tc := range cases {