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

Support 'PATCH' method in corsRule with blob properties #6964

Merged
merged 1 commit into from May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions azurerm/helpers/azure/storage_account.go
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
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
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
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