这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: (storage) added validation for cors parameters method, origin and response_header cannot be empty #14482

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

gurusai-voleti
Copy link
Contributor

@gurusai-voleti gurusai-voleti commented Jul 9, 2025

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.
Fixes: hashicorp/terraform-provider-google#15280

storage: added validation for cors parameters method, origin and response_header cannot be empty

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 18 insertions(+))
google-beta provider: Diff ( 1 file changed, 18 insertions(+))

@modular-magician modular-magician requested a review from kautikdk July 9, 2025 14:01
@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 112
Skipped tests: 10
Affected tests: 1

Click here to see the affected service packages
  • storage
#### Action taken
Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccStorageBucket_cors

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🔴 Tests failed during RECORDING mode:
TestAccStorageBucket_cors [Error message] [Debug log]

🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.

View the build log or the debug log for each test

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 32 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 1 file changed, 32 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 31 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 1 file changed, 31 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 31 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 1 file changed, 31 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 30 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 1 file changed, 30 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 30 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 1 file changed, 30 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 61 insertions(+), 4 deletions(-))
google-beta provider: Diff ( 2 files changed, 61 insertions(+), 4 deletions(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_storage_bucket (604 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_storage_bucket" "primary" {
  cors {
    send_max_age_seconds_if_zero = # value needed
  }
}

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 67 insertions(+), 9 deletions(-))
google-beta provider: Diff ( 3 files changed, 67 insertions(+), 9 deletions(-))

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 70 insertions(+), 10 deletions(-))
google-beta provider: Diff ( 3 files changed, 70 insertions(+), 10 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 112
Skipped tests: 10
Affected tests: 1

Click here to see the affected service packages
  • storage
#### Action taken
Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccStorageBucket_cors

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccStorageBucket_cors [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

@gurusai-voleti gurusai-voleti marked this pull request as ready for review July 17, 2025 07:30
@github-actions github-actions bot requested a review from melinath July 17, 2025 07:31
Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@melinath, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

Copy link
Member

@kautikdk kautikdk left a comment

Choose a reason for hiding this comment

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

While I agree that validation logic will work in this case, can we not fix the issue with diffSupressFunc? If that works, we don't have to go through separate customize diff and validation logic from client side.

If CustomizeDiff is the only solution, I would recommend adding unit and acceptance tests for the same. Current tests are essentially not validating the issue scenario rather they just ensure working of the new field.

@@ -2208,8 +2256,10 @@ func setStorageBucket(d *schema.ResourceData, config *transport_tpg.Config, res
if err := d.Set("location", res.Location); err != nil {
return fmt.Errorf("Error setting location: %s", err)
}
if err := d.Set("cors", flattenCors(res.Cors)); err != nil {
return fmt.Errorf("Error setting cors: %s", err)
if res.Cors != nil {
Copy link
Member

Choose a reason for hiding this comment

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

In case of nil value of CORS, can we set empty empty list similar to lifecycle rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added empty list

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 70 insertions(+), 9 deletions(-))
google-beta provider: Diff ( 3 files changed, 70 insertions(+), 9 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

Copy link

@melinath This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

Comment on lines 30 to 57
func corsValidation(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
cors, corsOk := d.GetOk("cors")
if corsOk && len(cors.([]interface{})) == 0 {
return fmt.Errorf("cors cannot be empty")
}
for _, corsRule := range cors.([]interface{}) {
if corsRule == nil {
return fmt.Errorf("cors cannot be empty")
}
rule := corsRule.(map[string]interface{})
maxAgeSeconds := rule["max_age_seconds"].(int)
sendMaxAge := rule["send_max_age_seconds_if_zero"].(bool)
// if send_max_age_seconds_if_zero is true, max_age_seconds can be zero
if sendMaxAge || maxAgeSeconds > 0 {
continue
}

method := rule["method"].([]interface{})
responseHeader := rule["response_header"].([]interface{})
origin := rule["origin"].([]interface{})

// check if all cors attributes provided have values
if !(len(method) > 0 || len(origin) > 0 || len(responseHeader) > 0) {
return fmt.Errorf("cors attributes cannot be empty or use send_max_age_seconds_if_zero flag to send max_age_seconds as zero")
}
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Just want to verify: are the error cases here things that would otherwise be API errors? Otherwise this would be a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are not replication API errors even API accepts empty values for cors field but in API response we wont get anything back for cors field, so validating here to ensure values are provided and not empty

Copy link
Member

Choose a reason for hiding this comment

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

If it's valid from the API's perspective, we can't add stricter client-side validation once the field in question is introduced. Since cors is already released, adding validation to it would be a breaking change.

Copy link
Member

@melinath melinath left a comment

Choose a reason for hiding this comment

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

If CustomizeDiff is the only solution, I would recommend adding unit and acceptance tests for the same.

I think CustomizeDiff is necessary since this needs to take multiple fields into account. +1 to this point - please add unit tests.

@gurusai-voleti
Copy link
Contributor Author

gurusai-voleti commented Jul 23, 2025

While I agree that validation logic will work in this case, can we not fix the issue with diffSupressFunc? If that works, we don't have to go through separate customize diff and validation logic from client side.

If CustomizeDiff is the only solution, I would recommend adding unit and acceptance tests for the same. Current tests are essentially not validating the issue scenario rather they just ensure working of the new field.

List types cannot be handled by diffsuppress func as per terraform SDK its not recommended approach

@github-actions github-actions bot requested a review from melinath July 23, 2025 04:53
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 70 insertions(+), 9 deletions(-))
google-beta provider: Diff ( 3 files changed, 70 insertions(+), 9 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

Copy link
Member

@melinath melinath left a comment

Choose a reason for hiding this comment

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

Marking as changes requested due to the feedback above.

List types cannot be handled by diffsuppress func as per terraform SDK its not recommended approach

Just to clarify, I don't think this is correct - diffsuppress definitely works for lists - but diffsuppress can't handle validation across multiple fields.

@gurusai-voleti
Copy link
Contributor Author

gurusai-voleti commented Jul 23, 2025

Marking as changes requested due to the feedback above.

List types cannot be handled by diffsuppress func as per terraform SDK its not recommended approach

Just to clarify, I don't think this is correct - diffsuppress definitely works for lists - but diffsuppress can't handle validation across multiple fields.

sorry it supports, I tried diffsuppress first but seems not feasible for this solution to handle multiple fields, customize diff seems a better option here as multiple fields needed for validation

@github-actions github-actions bot requested a review from melinath July 23, 2025 17:08
Copy link
Member

@melinath melinath left a comment

Choose a reason for hiding this comment

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

removing from my queue for now.

@gurusai-voleti
Copy link
Contributor Author

gurusai-voleti commented Jul 24, 2025

Diffsuppress only provides way to show diff or not in tf plan but it will not to throw any error, here we need to validate the data and let customer/user know about the data validation error, so customDiff seems a feasible solution than diffsuppress, please correct me if I am wrong

@github-actions github-actions bot requested a review from melinath July 24, 2025 06:04
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 247 insertions(+), 9 deletions(-))
google-beta provider: Diff ( 3 files changed, 247 insertions(+), 9 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 0
Passed tests: 0
Skipped tests: 0
Affected tests: 0

Click here to see the affected service packages
  • storage
🔴 Errors occurred during REPLAYING mode. Please fix them to complete your PR.

View the build log

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 249 insertions(+), 9 deletions(-))
google-beta provider: Diff ( 3 files changed, 249 insertions(+), 9 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 123
Passed tests: 113
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • storage
🟢 All tests passed!

View the build log

@melinath
Copy link
Member

Diffsuppress only provides way to show diff or not in tf plan but it will not to throw any error, here we need to validate the data and let customer/user know about the data validation error, so customDiff seems a feasible solution than diffsuppress, please correct me if I am wrong

yes, that's also correct. Single-field validation would use validation functions, not diff suppress. 🤦

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.

Exception is being thrown when adding CORS block is being added in google_storage_bucket
4 participants