From 9a280cb24e5c78b2d2c7df01336f459614573474 Mon Sep 17 00:00:00 2001 From: Chang Li Date: Sat, 16 May 2020 11:56:07 +0800 Subject: [PATCH] Support 'PATCH' method in corsRule with blob properties --- azurerm/helpers/azure/storage_account.go | 27 ++++++++++++------- .../storage/resource_arm_storage_account.go | 4 +-- .../resource_arm_storage_account_test.go | 2 +- website/docs/r/storage_account.html.markdown | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/azurerm/helpers/azure/storage_account.go b/azurerm/helpers/azure/storage_account.go index 52974c6816d6..590f304a6347 100644 --- a/azurerm/helpers/azure/storage_account.go +++ b/azurerm/helpers/azure/storage_account.go @@ -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, @@ -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": { diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index c52522ac52fe..b27c667dc0b5 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -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, @@ -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, diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go index b188a3fd0148..92c52a4cc6e8 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go @@ -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" } diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index 860722c3f48a..7147357afdd2 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -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.