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

fix(cloudfront): Send zero instead of nil during create/update #2117

Merged

Conversation

jbcjorge
Copy link
Contributor

@jbcjorge jbcjorge commented Nov 4, 2024

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:

  • 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.

@jbcjorge jbcjorge force-pushed the fix/cloudfrount_no_quantity branch from 8b81e57 to 9eb4893 Compare November 4, 2024 11:50
@MisterMX MisterMX changed the title FIX: Cannot create/update CloudFront Distribution fix(cloudfront): Send zero instead of nil during create/update Nov 4, 2024
@MisterMX
Copy link
Collaborator

MisterMX commented Nov 4, 2024

@jbcjorge thanks for fix. Can you adjust the commit title to match the new PR title?

Signed-off-by: Jorge Millán <[email protected]>

This is related to crossplane-contrib#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.
@jbcjorge jbcjorge force-pushed the fix/cloudfrount_no_quantity branch from 9eb4893 to 6e5d322 Compare November 4, 2024 12:14
Copy link
Collaborator

@MisterMX MisterMX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you very much @jbcjorge!

@MisterMX MisterMX merged commit d622889 into crossplane-contrib:master Nov 4, 2024
8 of 9 checks passed
Copy link

github-actions bot commented Nov 4, 2024

Successfully created backport PR #2119 for release-0.50.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Distribution Bugs and Issues
2 participants