-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
provider/google: Add CORS support for google_storage_bucket. #14695
provider/google: Add CORS support for google_storage_bucket. #14695
Conversation
@@ -89,6 +89,40 @@ func resourceStorageBucket() *schema.Resource { | |||
}, | |||
}, | |||
}, | |||
|
|||
"cors": &schema.Schema{ | |||
Type: schema.TypeSet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this is a set but its contents are lists? (not a criticism, just curious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason really - List semantics weren't important to it, and the first similar block I looked at was a Set. Changed to List for consistency with the rest of the file; it also ends up simplifying a type assertion that way.
return fmt.Sprintf(` | ||
resource "google_storage_bucket" "bucket" { | ||
name = "%s" | ||
cors { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indentation
Also can you add another cors block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
* `method` - (Optional) The list of HTTP methods on which to include CORS response headers, (GET, OPTIONS, POST, etc) Note: "*" is permitted in the list of methods, and means "any method". | ||
|
||
* `response_header` - (Optional) The list of HTTP headers other than the [simple response headers](https://www.w3.org/TR/cors/#simple-response-header) to give permission for the user-agent to share across domains. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: too many spaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
corsRules := make([]*storage.BucketCors, 0, len(configured)) | ||
for _, raw := range configured { | ||
data := raw.(map[string]interface{}) | ||
corsRule := storage.BucketCors{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: totally just my opinion but I think filling out structs/maps inline looks a bit better:
corsRule := storage.BucketCors{
Origin: convertSchemaArrayToStringArray(data["origin"].([]interface{})),
Method: convertSchemaArrayToStringArray(data["method"].([]interface{})),
ResponseHeader: convertSchemaArrayToStringArray(data["response_header"].([]interface{})),
MaxAgeSeconds: int64(data["max_age_seconds"].(int)),
}
and below:
data := map[string]interface{}{
"origin": corsRule.Origin,
"method": corsRule.Method,
"response_header": corsRule.ResponseHeader,
"max_age_seconds": corsRule.MaxAgeSeconds,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Add support for CORS configuration fields to google_storage_bucket.
Fix for #12519.
@danawillow