Skip to content

Commit

Permalink
Merge pull request #6964 from lrxtom2/funny-fix
Browse files Browse the repository at this point in the history
Support 'PATCH' method in corsRule with blob properties
  • Loading branch information
tombuildsstuff authored May 18, 2020
2 parents 99e1ec1 + 9a280cb commit 356ebb2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
27 changes: 17 additions & 10 deletions azurerm/helpers/azure/storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func SchemaStorageAccountCorsRule() *schema.Schema {
func SchemaStorageAccountCorsRule(patchEnabled bool) *schema.Schema {
// CorsRule "PATCH" method is only supported by blob
allowedMethods := []string{
"DELETE",
"GET",
"HEAD",
"MERGE",
"POST",
"OPTIONS",
"PUT"}

if patchEnabled {
allowedMethods = append(allowedMethods, "PATCH")
}

return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -44,15 +58,8 @@ func SchemaStorageAccountCorsRule() *schema.Schema {
Required: true,
MaxItems: 64,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"DELETE",
"GET",
"HEAD",
"MERGE",
"POST",
"OPTIONS",
"PUT"}, false),
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(allowedMethods, false),
},
},
"max_age_in_seconds": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func resourceArmStorageAccount() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cors_rule": azure.SchemaStorageAccountCorsRule(),
"cors_rule": azure.SchemaStorageAccountCorsRule(true),
"delete_retention_policy": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -255,7 +255,7 @@ func resourceArmStorageAccount() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cors_rule": azure.SchemaStorageAccountCorsRule(),
"cors_rule": azure.SchemaStorageAccountCorsRule(false),
"logging": {
Type: schema.TypeList,
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ resource "azurerm_storage_account" "test" {
allowed_origins = ["http://www.example.com"]
exposed_headers = ["x-tempo-*"]
allowed_headers = ["x-tempo-*"]
allowed_methods = ["GET", "PUT"]
allowed_methods = ["GET", "PUT", "PATCH"]
max_age_in_seconds = "500"
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/storage_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ A `cors_rule` block supports the following:
* `allowed_headers` - (Required) A list of headers that are allowed to be a part of the cross-origin request.

* `allowed_methods` - (Required) A list of http headers that are allowed to be executed by the origin. Valid options are
`DELETE`, `GET`, `HEAD`, `MERGE`, `POST`, `OPTIONS` or `PUT`.
`DELETE`, `GET`, `HEAD`, `MERGE`, `POST`, `OPTIONS`, `PUT` or `PATCH`.

* `allowed_origins` - (Required) A list of origin domains that will be allowed by CORS.

Expand Down

0 comments on commit 356ebb2

Please sign in to comment.