From ddc8b4ca63e194e3c47b633fff4e8fee13166183 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 1 Feb 2021 11:45:21 +0800 Subject: [PATCH 01/29] update --- .../storage_management_policy_resource.go | 106 ++++++++++++++ ...storage_management_policy_resource_test.go | 135 ++++++++++++++++++ .../r/storage_management_policy.html.markdown | 16 ++- 3 files changed, 256 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 8fac7b6562a2..4fd9d570dd37 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -1,6 +1,7 @@ package storage import ( + "bytes" "fmt" "regexp" "time" @@ -81,6 +82,33 @@ func resourceStorageManagementPolicy() *schema.Resource { }, Set: schema.HashString, }, + + "blob_index_match": { + Type: schema.TypeSet, + Optional: true, + Set: resourceStorageManagementPolicyBlobIndexMatchHash, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "tag_name": { + Type: schema.TypeString, + Required: true, + }, + + "tag_op": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "==", + }, false), + }, + + "tag_value": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, }, }, }, @@ -288,6 +316,8 @@ func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) st } } definition.Filters.BlobTypes = &blobTypes + + definition.Filters.BlobIndexMatch = expandAzureRmStorageBlobIndexMatch(filterRef["blob_index_match"].(*schema.Set).List()) } } if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions", ruleIndex)); ok { @@ -370,6 +400,9 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul } filter["blob_types"] = blobTypes } + + filter["blob_index_match"] = flattenAzureRmStorageBlobIndexMatch(armFilter.BlobIndexMatch) + rule["filters"] = [1]interface{}{filter} } @@ -413,3 +446,76 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul return rules } + +func expandAzureRmStorageBlobIndexMatch(blobIndexMatches []interface{}) *[]storage.TagFilter { + results := make([]storage.TagFilter, 0) + + if len(blobIndexMatches) == 0 { + return &results + } + for _, v := range blobIndexMatches { + blobIndexMatch := v.(map[string]interface{}) + + filter := storage.TagFilter{ + Name: utils.String(blobIndexMatch["tag_name"].(string)), + Op: utils.String(blobIndexMatch["tag_op"].(string)), + Value: utils.String(blobIndexMatch["tag_value"].(string)), + } + + results = append(results, filter) + } + + return &results +} + +func flattenAzureRmStorageBlobIndexMatch(blobIndexMatches *[]storage.TagFilter) *schema.Set { + result := &schema.Set{ + F: resourceStorageManagementPolicyBlobIndexMatchHash, + } + + if blobIndexMatches == nil || len(*blobIndexMatches) == 0 { + return result + } + + for _, blobIndexMatch := range *blobIndexMatches { + var name, op, value string + if blobIndexMatch.Name != nil { + name = *blobIndexMatch.Name + } + if blobIndexMatch.Op != nil { + op = *blobIndexMatch.Op + } + if blobIndexMatch.Value != nil { + value = *blobIndexMatch.Value + } + result.Add(map[string]interface{}{ + "tag_name": name, + "tag_op": op, + "tag_value": value, + }) + } + return result +} + +func resourceStorageManagementPolicyBlobIndexMatchHash(v interface{}) int { + var buf bytes.Buffer + + if m, ok := v.(storage.TagFilter); ok { + var name, op, value string + if m.Name != nil { + name = *m.Name + } + + if m.Op != nil { + op = *m.Op + } + + if m.Value != nil { + value = *m.Value + } + + buf.WriteString(fmt.Sprintf("%s-%s-%s", name, op, value)) + } + + return schema.HashString(buf.String()) +} diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 27f7334c6533..6afbd01e5f95 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -290,6 +290,35 @@ func TestAccStorageManagementPolicy_blobTypes(t *testing.T) { }) } +func TestAccStorageManagementPolicy_blobIndexMatch(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + r := StorageManagementPolicyResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.blobIndexMatchDisabled(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.blobIndexMatch(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.blobIndexMatchDisabled(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r StorageManagementPolicyResource) Exists(ctx context.Context, client *clients.Client, state *terraform.InstanceState) (*bool, error) { storageAccountId := state.Attributes["storage_account_id"] id, err := parse.StorageAccountID(storageAccountId) @@ -611,3 +640,109 @@ resource "azurerm_storage_management_policy" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } + +func (r StorageManagementPolicyResource) blobIndexMatchTemplate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = azurerm_resource_group.test.name + + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_role_assignment" "test" { + scope = azurerm_storage_account.test.id + role_definition_name = "Storage Blob Data Owner" + principal_id = data.azurerm_client_config.current.object_id +} + +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func (r StorageManagementPolicyResource) blobIndexMatch(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_storage_management_policy" "test" { + storage_account_id = azurerm_storage_account.test.id + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + + blob_index_match { + tag_name = "tag1" + tag_op = "==" + tag_value = "val1" + } + + blob_index_match { + tag_name = "tag2" + tag_op = "==" + tag_value = "val2" + } + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + delete_after_days_since_creation_greater_than = 30 + } + } + } + + depends_on = [azurerm_role_assignment.test] +} +`, r.blobIndexMatchTemplate(data)) +} + +func (r StorageManagementPolicyResource) blobIndexMatchDisabled(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_storage_management_policy" "test" { + storage_account_id = azurerm_storage_account.test.id + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + delete_after_days_since_creation_greater_than = 30 + } + } + } + + depends_on = [azurerm_role_assignment.test] +} +`, r.blobIndexMatchTemplate(data)) +} diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index ddb10df0689a..f6ab7c114b44 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -37,6 +37,11 @@ resource "azurerm_storage_management_policy" "example" { filters { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] +blob_index_match { + tag_name = "tag1" + tag_op = "==" + tag_value = "val1" + } } actions { base_blob { @@ -93,7 +98,8 @@ The following arguments are supported: * `prefix_match` - An array of strings for prefixes to be matched. * `blob_types` - An array of predefined values. Valid options are `blockBlob` and `appendBlob`. - +* `blob_index_match` - A `blob_index_match` block as defined below. +~> **NOTE:** Please enable `blobIndex` feature by [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/) before setting the block `blob_index_match`. --- `actions` supports the following: @@ -115,6 +121,14 @@ The following arguments are supported: * `delete_after_days_since_creation_greater_than` - The age in days after create to delete the snaphot. Must be at least 0. +--- + +`blob_index_match` supports the following: + +* `tag_name` - The age in days after create to delete the snaphot. Must be at least 0. +* `tag_op` - The age in days after create to delete the snaphot. Must be at least 0. +* `tag_value` - The age in days after create to delete the snaphot. Must be at least 0. + ## Attributes Reference The following attributes are exported: From ee671a85f2b8069fea1238afa0bc9badba985857 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 1 Feb 2021 13:56:47 +0800 Subject: [PATCH 02/29] update --- .../storage/storage_management_policy_resource.go | 6 +++--- .../storage/storage_management_policy_resource_test.go | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 4fd9d570dd37..dbdcd8e610a1 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -448,11 +448,11 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul } func expandAzureRmStorageBlobIndexMatch(blobIndexMatches []interface{}) *[]storage.TagFilter { - results := make([]storage.TagFilter, 0) - if len(blobIndexMatches) == 0 { - return &results + return nil } + + results := make([]storage.TagFilter, 0) for _, v := range blobIndexMatches { blobIndexMatch := v.(map[string]interface{}) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 6afbd01e5f95..50fafa7ea538 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -659,15 +659,14 @@ resource "azurerm_storage_account" "test" { location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" - account_kind = "BlobStorage" } data "azurerm_client_config" "current" {} resource "azurerm_role_assignment" "test" { - scope = azurerm_storage_account.test.id - role_definition_name = "Storage Blob Data Owner" - principal_id = data.azurerm_client_config.current.object_id + scope = azurerm_storage_account.test.id + role_definition_name = "Storage Blob Data Owner" + principal_id = data.azurerm_client_config.current.object_id } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -705,9 +704,6 @@ resource "azurerm_storage_management_policy" "test" { tier_to_archive_after_days_since_modification_greater_than = 50 delete_after_days_since_modification_greater_than = 100 } - snapshot { - delete_after_days_since_creation_greater_than = 30 - } } } From 761f58d5c6aef3d12b0dc610ef161a87a1f62698 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 1 Feb 2021 14:58:33 +0800 Subject: [PATCH 03/29] update --- .../storage_management_policy_resource.go | 11 ++-- ...storage_management_policy_resource_test.go | 6 +-- .../validate/storage_blob_index_tag.go | 23 ++++++++ .../validate/storage_blob_index_tag_test.go | 53 +++++++++++++++++++ 4 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 azurerm/internal/services/storage/validate/storage_blob_index_tag.go create mode 100644 azurerm/internal/services/storage/validate/storage_blob_index_tag_test.go diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index dbdcd8e610a1..ef3a5c457eba 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -3,6 +3,7 @@ package storage import ( "bytes" "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/validate" "regexp" "time" @@ -90,8 +91,9 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tag_name": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.StorageBlobIndexTagName, }, "tag_op": { @@ -103,8 +105,9 @@ func resourceStorageManagementPolicy() *schema.Resource { }, "tag_value": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.StorageBlobIndexTagValue, }, }, }, diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 50fafa7ea538..374bd2dd1342 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -664,9 +664,9 @@ resource "azurerm_storage_account" "test" { data "azurerm_client_config" "current" {} resource "azurerm_role_assignment" "test" { - scope = azurerm_storage_account.test.id - role_definition_name = "Storage Blob Data Owner" - principal_id = data.azurerm_client_config.current.object_id + scope = azurerm_storage_account.test.id + role_definition_name = "Storage Blob Data Owner" + principal_id = data.azurerm_client_config.current.object_id } `, data.RandomInteger, data.Locations.Primary, data.RandomString) diff --git a/azurerm/internal/services/storage/validate/storage_blob_index_tag.go b/azurerm/internal/services/storage/validate/storage_blob_index_tag.go new file mode 100644 index 000000000000..67f93ca81239 --- /dev/null +++ b/azurerm/internal/services/storage/validate/storage_blob_index_tag.go @@ -0,0 +1,23 @@ +package validate + +import ( + "fmt" +) + +func StorageBlobIndexTagName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if len(value) == 0 || len(value) > 128 { + errors = append(errors, fmt.Errorf( + "%q must be between 1 and 128 characters: %q", k, value)) + } + return warnings, errors +} + +func StorageBlobIndexTagValue(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if len(value) > 256 { + errors = append(errors, fmt.Errorf( + "%q must be between 0 and 256 characters: %q", k, value)) + } + return warnings, errors +} diff --git a/azurerm/internal/services/storage/validate/storage_blob_index_tag_test.go b/azurerm/internal/services/storage/validate/storage_blob_index_tag_test.go new file mode 100644 index 000000000000..cab46d26ab22 --- /dev/null +++ b/azurerm/internal/services/storage/validate/storage_blob_index_tag_test.go @@ -0,0 +1,53 @@ +package validate + +import ( + "strings" + "testing" +) + +func TestStorageBlobIndexTagName(t *testing.T) { + validNames := []string{ + "valid-name", + "valid02-name", + strings.Repeat("w", 128), + } + for _, v := range validNames { + _, errors := StorageBlobIndexTagName(v, "name") + if len(errors) != 0 { + t.Fatalf("%q should be a valid Blob Index Tag Name: %q", v, errors) + } + } + + invalidNames := []string{ + "", + strings.Repeat("w", 129), + } + for _, v := range invalidNames { + if _, errors := StorageBlobIndexTagName(v, "name"); len(errors) == 0 { + t.Fatalf("%q should be an invalid Blob Index Tag Name", v) + } + } +} + +func TestStorageBlobIndexTagValue(t *testing.T) { + validNames := []string{ + "valid-name", + "", + strings.Repeat("w", 256), + } + for _, v := range validNames { + _, errors := StorageBlobIndexTagValue(v, "name") + if len(errors) != 0 { + t.Fatalf("%q should be a valid Blob Index Tag Value: %q", v, errors) + } + } + + invalidNames := []string{ + strings.Repeat("w", 257), + } + for _, v := range invalidNames { + if _, errors := StorageBlobIndexTagValue(v, "name"); len(errors) == 0 { + t.Fatalf("%q should be an invalid Blob Index Tag Value", v) + } + } +} From dcec0ee17eb194683f0aa10e0a1fcc8c9588f278 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 1 Feb 2021 15:10:56 +0800 Subject: [PATCH 04/29] fmt --- .../services/storage/storage_management_policy_resource.go | 3 ++- .../storage/storage_management_policy_resource_test.go | 4 ---- website/docs/r/storage_management_policy.html.markdown | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index ef3a5c457eba..377f46c302b5 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -3,10 +3,11 @@ package storage import ( "bytes" "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/validate" "regexp" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 374bd2dd1342..48ad50d72251 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -668,7 +668,6 @@ resource "azurerm_role_assignment" "test" { role_definition_name = "Storage Blob Data Owner" principal_id = data.azurerm_client_config.current.object_id } - `, data.RandomInteger, data.Locations.Primary, data.RandomString) } @@ -732,9 +731,6 @@ resource "azurerm_storage_management_policy" "test" { tier_to_archive_after_days_since_modification_greater_than = 50 delete_after_days_since_modification_greater_than = 100 } - snapshot { - delete_after_days_since_creation_greater_than = 30 - } } } diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index f6ab7c114b44..689baa1b63b4 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -37,7 +37,7 @@ resource "azurerm_storage_management_policy" "example" { filters { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] -blob_index_match { + blob_index_match { tag_name = "tag1" tag_op = "==" tag_value = "val1" From 935c988d66d12f69540eca2ac2a141b5236bf055 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Tue, 2 Feb 2021 09:46:26 +0800 Subject: [PATCH 05/29] update --- .../storage_management_policy_resource.go | 27 ++++++++++--------- ...storage_management_policy_resource_test.go | 15 +++++------ .../r/storage_management_policy.html.markdown | 20 +++++++------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 377f46c302b5..7c83bc584343 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -85,27 +85,28 @@ func resourceStorageManagementPolicy() *schema.Resource { Set: schema.HashString, }, - "blob_index_match": { + "blob_index_match_tag": { Type: schema.TypeSet, Optional: true, Set: resourceStorageManagementPolicyBlobIndexMatchHash, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "tag_name": { + "name": { Type: schema.TypeString, Required: true, ValidateFunc: validate.StorageBlobIndexTagName, }, - "tag_op": { + "operation": { Type: schema.TypeString, - Required: true, + Optional: true, ValidateFunc: validation.StringInSlice([]string{ "==", }, false), + Default: "==", }, - "tag_value": { + "value": { Type: schema.TypeString, Required: true, ValidateFunc: validate.StorageBlobIndexTagValue, @@ -321,7 +322,7 @@ func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) st } definition.Filters.BlobTypes = &blobTypes - definition.Filters.BlobIndexMatch = expandAzureRmStorageBlobIndexMatch(filterRef["blob_index_match"].(*schema.Set).List()) + definition.Filters.BlobIndexMatch = expandAzureRmStorageBlobIndexMatch(filterRef["blob_index_match_tag"].(*schema.Set).List()) } } if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions", ruleIndex)); ok { @@ -405,7 +406,7 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul filter["blob_types"] = blobTypes } - filter["blob_index_match"] = flattenAzureRmStorageBlobIndexMatch(armFilter.BlobIndexMatch) + filter["blob_index_match_tag"] = flattenAzureRmStorageBlobIndexMatch(armFilter.BlobIndexMatch) rule["filters"] = [1]interface{}{filter} } @@ -461,9 +462,9 @@ func expandAzureRmStorageBlobIndexMatch(blobIndexMatches []interface{}) *[]stora blobIndexMatch := v.(map[string]interface{}) filter := storage.TagFilter{ - Name: utils.String(blobIndexMatch["tag_name"].(string)), - Op: utils.String(blobIndexMatch["tag_op"].(string)), - Value: utils.String(blobIndexMatch["tag_value"].(string)), + Name: utils.String(blobIndexMatch["name"].(string)), + Op: utils.String(blobIndexMatch["operation"].(string)), + Value: utils.String(blobIndexMatch["value"].(string)), } results = append(results, filter) @@ -493,9 +494,9 @@ func flattenAzureRmStorageBlobIndexMatch(blobIndexMatches *[]storage.TagFilter) value = *blobIndexMatch.Value } result.Add(map[string]interface{}{ - "tag_name": name, - "tag_op": op, - "tag_value": value, + "name": name, + "operation": op, + "value": value, }) } return result diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 48ad50d72251..706122f32b85 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -685,16 +685,15 @@ resource "azurerm_storage_management_policy" "test" { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] - blob_index_match { - tag_name = "tag1" - tag_op = "==" - tag_value = "val1" + blob_index_match_tag { + name = "tag1" + value = "val1" } - blob_index_match { - tag_name = "tag2" - tag_op = "==" - tag_value = "val2" + blob_index_match_tag { + name = "tag2" + operation = "==" + value = "val2" } } actions { diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index 689baa1b63b4..05bdfa89209b 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -37,10 +37,10 @@ resource "azurerm_storage_management_policy" "example" { filters { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] - blob_index_match { - tag_name = "tag1" - tag_op = "==" - tag_value = "val1" + blob_index_match_tag { + name = "tag1" + operation = "==" + value = "val1" } } actions { @@ -98,8 +98,8 @@ The following arguments are supported: * `prefix_match` - An array of strings for prefixes to be matched. * `blob_types` - An array of predefined values. Valid options are `blockBlob` and `appendBlob`. -* `blob_index_match` - A `blob_index_match` block as defined below. -~> **NOTE:** Please enable `blobIndex` feature by [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/) before setting the block `blob_index_match`. +* `blob_index_match_tag` - A `blob_index_match_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. +~> **NOTE:** This property requires enabling the `blobIndex` feature with [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/) before setting the block `blob_index_match_tag`. --- `actions` supports the following: @@ -123,11 +123,11 @@ The following arguments are supported: --- -`blob_index_match` supports the following: +`blob_index_match_tag` supports the following: -* `tag_name` - The age in days after create to delete the snaphot. Must be at least 0. -* `tag_op` - The age in days after create to delete the snaphot. Must be at least 0. -* `tag_value` - The age in days after create to delete the snaphot. Must be at least 0. +* `name` - The filter tag name used for tag based filtering for blob objects. +* `operation` - The comparison operator which is used for object comparison and filtering. Possible value is `==`. Defaults to `==`. +* `value` - The filter tag value used for tag based filtering for blob objects. ## Attributes Reference From 1139b256cc82d5e0a4cdbecf307267a4777a4ce2 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Tue, 2 Feb 2021 09:50:05 +0800 Subject: [PATCH 06/29] update --- .../services/storage/storage_management_policy_resource.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 7c83bc584343..0b83d00fd020 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -6,16 +6,14 @@ import ( "regexp" "time" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/validate" - - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func resourceStorageManagementPolicy() *schema.Resource { From 2810a31108f3985718a7f39f256f51f5712f45ec Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Tue, 23 Mar 2021 14:27:47 +0800 Subject: [PATCH 07/29] update --- .../storage_management_policy_data_source.go | 23 +++++++++++++ ...rage_management_policy_data_source_test.go | 2 ++ .../storage_management_policy_resource.go | 33 ++----------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source.go b/azurerm/internal/services/storage/storage_management_policy_data_source.go index 6cf0a96f216c..84267555b09b 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source.go @@ -53,6 +53,29 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, + + "blob_index_match_tag": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + + "operation": { + Type: schema.TypeString, + Computed: true, + }, + + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, }, }, diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go index 886e3c68d6ba..c38fc2eb7ed7 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go @@ -110,6 +110,7 @@ resource "azurerm_storage_management_policy" "test" { data "azurerm_storage_management_policy" "test" { storage_account_id = azurerm_storage_management_policy.test.storage_account_id +depends_on = [azurerm_storage_management_policy.test] } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } @@ -158,6 +159,7 @@ resource "azurerm_storage_management_policy" "test" { data "azurerm_storage_management_policy" "test" { storage_account_id = azurerm_storage_management_policy.test.storage_account_id +depends_on = [azurerm_storage_management_policy.test] } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 0b83d00fd020..d3dd3c0bc2dd 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -1,7 +1,6 @@ package storage import ( - "bytes" "fmt" "regexp" "time" @@ -86,7 +85,6 @@ func resourceStorageManagementPolicy() *schema.Resource { "blob_index_match_tag": { Type: schema.TypeSet, Optional: true, - Set: resourceStorageManagementPolicyBlobIndexMatchHash, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { @@ -471,10 +469,8 @@ func expandAzureRmStorageBlobIndexMatch(blobIndexMatches []interface{}) *[]stora return &results } -func flattenAzureRmStorageBlobIndexMatch(blobIndexMatches *[]storage.TagFilter) *schema.Set { - result := &schema.Set{ - F: resourceStorageManagementPolicyBlobIndexMatchHash, - } +func flattenAzureRmStorageBlobIndexMatch(blobIndexMatches *[]storage.TagFilter) []map[string]interface{} { + result := make([]map[string]interface{}, 0) if blobIndexMatches == nil || len(*blobIndexMatches) == 0 { return result @@ -491,7 +487,7 @@ func flattenAzureRmStorageBlobIndexMatch(blobIndexMatches *[]storage.TagFilter) if blobIndexMatch.Value != nil { value = *blobIndexMatch.Value } - result.Add(map[string]interface{}{ + result = append(result, map[string]interface{}{ "name": name, "operation": op, "value": value, @@ -499,26 +495,3 @@ func flattenAzureRmStorageBlobIndexMatch(blobIndexMatches *[]storage.TagFilter) } return result } - -func resourceStorageManagementPolicyBlobIndexMatchHash(v interface{}) int { - var buf bytes.Buffer - - if m, ok := v.(storage.TagFilter); ok { - var name, op, value string - if m.Name != nil { - name = *m.Name - } - - if m.Op != nil { - op = *m.Op - } - - if m.Value != nil { - value = *m.Value - } - - buf.WriteString(fmt.Sprintf("%s-%s-%s", name, op, value)) - } - - return schema.HashString(buf.String()) -} From b8ec965c6f08e4562ee8224c8aa24fb8ebf67eb8 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Tue, 23 Mar 2021 14:32:30 +0800 Subject: [PATCH 08/29] update --- .../storage/storage_management_policy_data_source_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go index c38fc2eb7ed7..886e3c68d6ba 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go @@ -110,7 +110,6 @@ resource "azurerm_storage_management_policy" "test" { data "azurerm_storage_management_policy" "test" { storage_account_id = azurerm_storage_management_policy.test.storage_account_id -depends_on = [azurerm_storage_management_policy.test] } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } @@ -159,7 +158,6 @@ resource "azurerm_storage_management_policy" "test" { data "azurerm_storage_management_policy" "test" { storage_account_id = azurerm_storage_management_policy.test.storage_account_id -depends_on = [azurerm_storage_management_policy.test] } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } From 3728889950f31fbf9be2e6d86c4a45d759570a9d Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 24 Mar 2021 14:01:13 +0800 Subject: [PATCH 09/29] update --- .../machine_learning_workspace_resource.go | 2 +- .../services/storage/client/client.go | 2 +- .../services/storage/client/helpers.go | 2 +- ...e_account_customer_managed_key_resource.go | 2 +- ...ount_customer_managed_key_resource_test.go | 2 +- .../storage/storage_account_data_source.go | 2 +- .../storage_account_network_rules_resource.go | 2 +- .../storage/storage_account_resource.go | 10 +- .../storage_account_resource_migration.go | 2 +- .../storage_container_resource_test.go | 1 + .../storage_encryption_scope_resource.go | 2 +- .../storage_encryption_scope_resource_test.go | 2 +- ...rage_management_policy_data_source_test.go | 5 - .../storage_management_policy_resource.go | 2 +- ...storage_management_policy_resource_test.go | 26 - .../storage/CHANGELOG.md | 2 +- .../storage/accounts.go | 82 ++- .../storage/blobcontainers.go | 26 +- .../storage/blobinventorypolicies.go | 422 ++++++++++++ .../storage/blobservices.go | 14 +- .../storage/client.go | 2 +- .../2021-01-01/storage/deletedaccounts.go | 247 +++++++ .../storage/encryptionscopes.go | 8 +- .../storage/enums.go | 81 ++- .../storage/fileservices.go | 6 +- .../storage/fileshares.go | 44 +- .../storage/managementpolicies.go | 6 +- .../storage/models.go | 601 +++++++++++++++++- .../storage/objectreplicationpolicies.go | 8 +- .../storage/operations.go | 2 +- .../storage/privateendpointconnections.go | 8 +- .../storage/privatelinkresources.go | 2 +- .../storage/queue.go | 10 +- .../storage/queueservices.go | 6 +- .../storage/skus.go | 2 +- .../storage/table.go | 10 +- .../storage/tableservices.go | 6 +- .../storage/usages.go | 2 +- .../storage/version.go | 2 +- vendor/modules.txt | 2 +- 40 files changed, 1517 insertions(+), 148 deletions(-) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/CHANGELOG.md (50%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/accounts.go (96%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/blobcontainers.go (99%) create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobinventorypolicies.go rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/blobservices.go (94%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/client.go (98%) create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/deletedaccounts.go rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/encryptionscopes.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/enums.go (90%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/fileservices.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/fileshares.go (96%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/managementpolicies.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/models.go (86%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/objectreplicationpolicies.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/operations.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/privateendpointconnections.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/privatelinkresources.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/queue.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/queueservices.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/skus.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/table.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/tableservices.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/usages.go (99%) rename vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/{2019-06-01 => 2021-01-01}/storage/version.go (94%) diff --git a/azurerm/internal/services/machinelearning/machine_learning_workspace_resource.go b/azurerm/internal/services/machinelearning/machine_learning_workspace_resource.go index 47908147431f..16ac8fea8ba1 100644 --- a/azurerm/internal/services/machinelearning/machine_learning_workspace_resource.go +++ b/azurerm/internal/services/machinelearning/machine_learning_workspace_resource.go @@ -7,7 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2019-05-01/containerregistry" "github.com/Azure/azure-sdk-for-go/services/machinelearningservices/mgmt/2020-04-01/machinelearningservices" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" diff --git a/azurerm/internal/services/storage/client/client.go b/azurerm/internal/services/storage/client/client.go index db8fca04e500..d2175e875ebf 100644 --- a/azurerm/internal/services/storage/client/client.go +++ b/azurerm/internal/services/storage/client/client.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/Azure/azure-sdk-for-go/services/storagesync/mgmt/2020-03-01/storagesync" "github.com/Azure/go-autorest/autorest" az "github.com/Azure/go-autorest/autorest/azure" diff --git a/azurerm/internal/services/storage/client/helpers.go b/azurerm/internal/services/storage/client/helpers.go index 357d0352ea5b..7aa97d21b1e7 100644 --- a/azurerm/internal/services/storage/client/helpers.go +++ b/azurerm/internal/services/storage/client/helpers.go @@ -6,7 +6,7 @@ import ( "log" "sync" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parse" ) diff --git a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource.go b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource.go index 3aa3751c1a97..021025e89728 100644 --- a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource.go +++ b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" diff --git a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go index 97e93045a661..6f543a513ec2 100644 --- a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go +++ b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" diff --git a/azurerm/internal/services/storage/storage_account_data_source.go b/azurerm/internal/services/storage/storage_account_data_source.go index 2f8a387029ab..cba0c156ed51 100644 --- a/azurerm/internal/services/storage/storage_account_data_source.go +++ b/azurerm/internal/services/storage/storage_account_data_source.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" azautorest "github.com/Azure/go-autorest/autorest" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" diff --git a/azurerm/internal/services/storage/storage_account_network_rules_resource.go b/azurerm/internal/services/storage/storage_account_network_rules_resource.go index 1de040bf537e..f6f87cb7dfd6 100644 --- a/azurerm/internal/services/storage/storage_account_network_rules_resource.go +++ b/azurerm/internal/services/storage/storage_account_network_rules_resource.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" diff --git a/azurerm/internal/services/storage/storage_account_resource.go b/azurerm/internal/services/storage/storage_account_resource.go index 02c15bb5e83e..176aeacab591 100644 --- a/azurerm/internal/services/storage/storage_account_resource.go +++ b/azurerm/internal/services/storage/storage_account_resource.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" azautorest "github.com/Azure/go-autorest/autorest" autorestAzure "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/go-azure-helpers/response" @@ -229,7 +229,7 @@ func resourceStorageAccount() *schema.Resource { Required: true, DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ - "SystemAssigned", + string(storage.IdentityTypeSystemAssigned), }, true), }, "principal_id": { @@ -1973,7 +1973,7 @@ func expandAzureRmStorageAccountIdentity(d *schema.ResourceData) *storage.Identi identity := identities[0].(map[string]interface{}) identityType := identity["type"].(string) return &storage.Identity{ - Type: &identityType, + Type: storage.IdentityType(identityType), } } @@ -1983,8 +1983,8 @@ func flattenAzureRmStorageAccountIdentity(identity *storage.Identity) []interfac } result := make(map[string]interface{}) - if identity.Type != nil { - result["type"] = *identity.Type + if identity.Type != "" { + result["type"] = string(identity.Type) } if identity.PrincipalID != nil { result["principal_id"] = *identity.PrincipalID diff --git a/azurerm/internal/services/storage/storage_account_resource_migration.go b/azurerm/internal/services/storage/storage_account_resource_migration.go index edb96125c098..7d0fc2294733 100644 --- a/azurerm/internal/services/storage/storage_account_resource_migration.go +++ b/azurerm/internal/services/storage/storage_account_resource_migration.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/terraform" ) diff --git a/azurerm/internal/services/storage/storage_container_resource_test.go b/azurerm/internal/services/storage/storage_container_resource_test.go index 9e4a3cdd7999..8b9503e35577 100644 --- a/azurerm/internal/services/storage/storage_container_resource_test.go +++ b/azurerm/internal/services/storage/storage_container_resource_test.go @@ -394,6 +394,7 @@ resource "azurerm_storage_account" "test" { location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" +allow_blob_public_access = true tags = { environment = "staging" diff --git a/azurerm/internal/services/storage/storage_encryption_scope_resource.go b/azurerm/internal/services/storage/storage_encryption_scope_resource.go index e1011d307304..49a60244bc17 100644 --- a/azurerm/internal/services/storage/storage_encryption_scope_resource.go +++ b/azurerm/internal/services/storage/storage_encryption_scope_resource.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" diff --git a/azurerm/internal/services/storage/storage_encryption_scope_resource_test.go b/azurerm/internal/services/storage/storage_encryption_scope_resource_test.go index 61fa06c5ace2..44a1b02692dc 100644 --- a/azurerm/internal/services/storage/storage_encryption_scope_resource_test.go +++ b/azurerm/internal/services/storage/storage_encryption_scope_resource_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go index 886e3c68d6ba..23dc5bbc5b5b 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go @@ -23,9 +23,7 @@ func TestAccDataSourceStorageManagementPolicy_basic(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -50,10 +48,7 @@ func TestAccDataSourceStorageManagementPolicy_blobTypes(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.932666486").HasValue("appendBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index aebf8be34914..a451511e40b7 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -7,7 +7,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 27f7334c6533..4b4218b0e49e 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -30,9 +30,7 @@ func TestAccStorageManagementPolicy_basic(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -60,9 +58,7 @@ func TestAccStorageManagementPolicy_singleAction(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -88,9 +84,7 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -108,9 +102,7 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("30"), @@ -138,9 +130,7 @@ func TestAccStorageManagementPolicy_multipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -154,10 +144,7 @@ func TestAccStorageManagementPolicy_multipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.4102595489").HasValue("container2/prefix1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.1837232667").HasValue("container2/prefix2"), check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), @@ -187,9 +174,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -203,10 +188,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.4102595489").HasValue("container2/prefix1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.1837232667").HasValue("container2/prefix2"), check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), @@ -228,9 +210,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -244,10 +224,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.1.enabled").HasValue("true"), // check updated check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.4102595489").HasValue("container2/prefix1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.1837232667").HasValue("container2/prefix2"), check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("12"), // check updated @@ -275,10 +252,7 @@ func TestAccStorageManagementPolicy_blobTypes(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.932666486").HasValue("appendBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/CHANGELOG.md b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/CHANGELOG.md similarity index 50% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/CHANGELOG.md rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/CHANGELOG.md index 398860a5fcd2..fa289a6fc0a4 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/CHANGELOG.md +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/CHANGELOG.md @@ -1,4 +1,4 @@ -Generated from https://github.com/Azure/azure-rest-api-specs/tree/3c764635e7d442b3e74caf593029fcd440b3ef82//specification/storage/resource-manager/readme.md tag: `package-2019-06` +Generated from https://github.com/Azure/azure-rest-api-specs/tree/92ab22b49bd085116af0c61fada2c6c360702e9e/specification/storage/resource-manager/readme.md tag: `package-2021-01` Code generator @microsoft.azure/autorest.go@2.1.175 diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/accounts.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/accounts.go similarity index 96% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/accounts.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/accounts.go index 9fdb2e674470..85485adf75ee 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/accounts.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/accounts.go @@ -94,7 +94,7 @@ func (client AccountsClient) CheckNameAvailabilityPreparer(ctx context.Context, "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -159,8 +159,6 @@ func (client AccountsClient) Create(ctx context.Context, resourceGroupName strin {TargetValue: parameters, Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: true, Chain: nil}, {Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.Identity", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.Identity.Type", Name: validation.Null, Rule: true, Chain: nil}}}, {Target: "parameters.AccountPropertiesCreateParameters", Name: validation.Null, Rule: false, Chain: []validation.Constraint{{Target: "parameters.AccountPropertiesCreateParameters.CustomDomain", Name: validation.Null, Rule: false, Chain: []validation.Constraint{{Target: "parameters.AccountPropertiesCreateParameters.CustomDomain.Name", Name: validation.Null, Rule: true, Chain: nil}}}, @@ -203,7 +201,7 @@ func (client AccountsClient) CreatePreparer(ctx context.Context, resourceGroupNa "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -328,7 +326,7 @@ func (client AccountsClient) DeletePreparer(ctx context.Context, resourceGroupNa "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -413,7 +411,7 @@ func (client AccountsClient) FailoverPreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -528,7 +526,7 @@ func (client AccountsClient) GetPropertiesPreparer(ctx context.Context, resource "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -614,7 +612,7 @@ func (client AccountsClient) ListPreparer(ctx context.Context) (*http.Request, e "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -745,7 +743,7 @@ func (client AccountsClient) ListAccountSASPreparer(ctx context.Context, resourc "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -783,13 +781,13 @@ func (client AccountsClient) ListAccountSASResponder(resp *http.Response) (resul // Parameters: // resourceGroupName - the name of the resource group within the user's subscription. The name is case // insensitive. -func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResult, err error) { +func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResultPage, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListByResourceGroup") defer func() { sc := -1 - if result.Response.Response != nil { - sc = result.Response.Response.StatusCode + if result.alr.Response.Response != nil { + sc = result.alr.Response.Response.StatusCode } tracing.EndSpan(ctx, sc, err) }() @@ -804,6 +802,7 @@ func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGr return result, validation.NewError("storage.AccountsClient", "ListByResourceGroup", err.Error()) } + result.fn = client.listByResourceGroupNextResults req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) if err != nil { err = autorest.NewErrorWithError(err, "storage.AccountsClient", "ListByResourceGroup", nil, "Failure preparing request") @@ -812,16 +811,20 @@ func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGr resp, err := client.ListByResourceGroupSender(req) if err != nil { - result.Response = autorest.Response{Response: resp} + result.alr.Response = autorest.Response{Response: resp} err = autorest.NewErrorWithError(err, "storage.AccountsClient", "ListByResourceGroup", resp, "Failure sending request") return } - result, err = client.ListByResourceGroupResponder(resp) + result.alr, err = client.ListByResourceGroupResponder(resp) if err != nil { err = autorest.NewErrorWithError(err, "storage.AccountsClient", "ListByResourceGroup", resp, "Failure responding to request") return } + if result.alr.hasNextLink() && result.alr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } return } @@ -833,7 +836,7 @@ func (client AccountsClient) ListByResourceGroupPreparer(ctx context.Context, re "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -864,6 +867,43 @@ func (client AccountsClient) ListByResourceGroupResponder(resp *http.Response) ( return } +// listByResourceGroupNextResults retrieves the next set of results, if any. +func (client AccountsClient) listByResourceGroupNextResults(ctx context.Context, lastResults AccountListResult) (result AccountListResult, err error) { + req, err := lastResults.accountListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "storage.AccountsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.AccountsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client AccountsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result AccountListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListByResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) + return +} + // ListKeys lists the access keys or Kerberos keys (if active directory enabled) for the specified storage account. // Parameters: // resourceGroupName - the name of the resource group within the user's subscription. The name is case @@ -925,7 +965,7 @@ func (client AccountsClient) ListKeysPreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1024,7 +1064,7 @@ func (client AccountsClient) ListServiceSASPreparer(ctx context.Context, resourc "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1120,7 +1160,7 @@ func (client AccountsClient) RegenerateKeyPreparer(ctx context.Context, resource "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1210,7 +1250,7 @@ func (client AccountsClient) RestoreBlobRangesPreparer(ctx context.Context, reso "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1335,7 +1375,7 @@ func (client AccountsClient) RevokeUserDelegationKeysPreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1431,7 +1471,7 @@ func (client AccountsClient) UpdatePreparer(ctx context.Context, resourceGroupNa "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/blobcontainers.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobcontainers.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/blobcontainers.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobcontainers.go index f82f06e34129..c8efdaac62b0 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/blobcontainers.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobcontainers.go @@ -113,7 +113,7 @@ func (client BlobContainersClient) ClearLegalHoldPreparer(ctx context.Context, r "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -217,7 +217,7 @@ func (client BlobContainersClient) CreatePreparer(ctx context.Context, resourceG "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -326,7 +326,7 @@ func (client BlobContainersClient) CreateOrUpdateImmutabilityPolicyPreparer(ctx "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -433,7 +433,7 @@ func (client BlobContainersClient) DeletePreparer(ctx context.Context, resourceG "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -537,7 +537,7 @@ func (client BlobContainersClient) DeleteImmutabilityPolicyPreparer(ctx context. "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -644,7 +644,7 @@ func (client BlobContainersClient) ExtendImmutabilityPolicyPreparer(ctx context. "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -748,7 +748,7 @@ func (client BlobContainersClient) GetPreparer(ctx context.Context, resourceGrou "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -851,7 +851,7 @@ func (client BlobContainersClient) GetImmutabilityPolicyPreparer(ctx context.Con "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -955,7 +955,7 @@ func (client BlobContainersClient) LeasePreparer(ctx context.Context, resourceGr "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1060,7 +1060,7 @@ func (client BlobContainersClient) ListPreparer(ctx context.Context, resourceGro "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1208,7 +1208,7 @@ func (client BlobContainersClient) LockImmutabilityPolicyPreparer(ctx context.Co "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1311,7 +1311,7 @@ func (client BlobContainersClient) SetLegalHoldPreparer(ctx context.Context, res "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -1414,7 +1414,7 @@ func (client BlobContainersClient) UpdatePreparer(ctx context.Context, resourceG "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobinventorypolicies.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobinventorypolicies.go new file mode 100644 index 000000000000..573208aaa87c --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobinventorypolicies.go @@ -0,0 +1,422 @@ +package storage + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// BlobInventoryPoliciesClient is the the Azure Storage Management API. +type BlobInventoryPoliciesClient struct { + BaseClient +} + +// NewBlobInventoryPoliciesClient creates an instance of the BlobInventoryPoliciesClient client. +func NewBlobInventoryPoliciesClient(subscriptionID string) BlobInventoryPoliciesClient { + return NewBlobInventoryPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewBlobInventoryPoliciesClientWithBaseURI creates an instance of the BlobInventoryPoliciesClient client using a +// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, +// Azure stack). +func NewBlobInventoryPoliciesClientWithBaseURI(baseURI string, subscriptionID string) BlobInventoryPoliciesClient { + return BlobInventoryPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate sets the blob inventory policy to the specified storage account. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. The name is case +// insensitive. +// accountName - the name of the storage account within the specified resource group. Storage account names +// must be between 3 and 24 characters in length and use numbers and lower-case letters only. +// properties - the blob inventory policy set to a storage account. +func (client BlobInventoryPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, accountName string, properties BlobInventoryPolicy) (result BlobInventoryPolicy, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlobInventoryPoliciesClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: properties, + Constraints: []validation.Constraint{{Target: "properties.BlobInventoryPolicyProperties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "properties.BlobInventoryPolicyProperties.Policy", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "properties.BlobInventoryPolicyProperties.Policy.Enabled", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "properties.BlobInventoryPolicyProperties.Policy.Destination", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "properties.BlobInventoryPolicyProperties.Policy.Type", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "properties.BlobInventoryPolicyProperties.Policy.Rules", Name: validation.Null, Rule: true, Chain: nil}, + }}, + }}}}}); err != nil { + return result, validation.NewError("storage.BlobInventoryPoliciesClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, accountName, properties) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client BlobInventoryPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, properties BlobInventoryPolicy) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "blobInventoryPolicyName": autorest.Encode("path", "default"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/inventoryPolicies/{blobInventoryPolicyName}", pathParameters), + autorest.WithJSON(properties), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client BlobInventoryPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client BlobInventoryPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result BlobInventoryPolicy, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes the blob inventory policy associated with the specified storage account. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. The name is case +// insensitive. +// accountName - the name of the storage account within the specified resource group. Storage account names +// must be between 3 and 24 characters in length and use numbers and lower-case letters only. +func (client BlobInventoryPoliciesClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlobInventoryPoliciesClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("storage.BlobInventoryPoliciesClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client BlobInventoryPoliciesClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "blobInventoryPolicyName": autorest.Encode("path", "default"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/inventoryPolicies/{blobInventoryPolicyName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client BlobInventoryPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client BlobInventoryPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets the blob inventory policy associated with the specified storage account. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. The name is case +// insensitive. +// accountName - the name of the storage account within the specified resource group. Storage account names +// must be between 3 and 24 characters in length and use numbers and lower-case letters only. +func (client BlobInventoryPoliciesClient) Get(ctx context.Context, resourceGroupName string, accountName string) (result BlobInventoryPolicy, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlobInventoryPoliciesClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("storage.BlobInventoryPoliciesClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client BlobInventoryPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "blobInventoryPolicyName": autorest.Encode("path", "default"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/inventoryPolicies/{blobInventoryPolicyName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client BlobInventoryPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client BlobInventoryPoliciesClient) GetResponder(resp *http.Response) (result BlobInventoryPolicy, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List gets the blob inventory policy associated with the specified storage account. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. The name is case +// insensitive. +// accountName - the name of the storage account within the specified resource group. Storage account names +// must be between 3 and 24 characters in length and use numbers and lower-case letters only. +func (client BlobInventoryPoliciesClient) List(ctx context.Context, resourceGroupName string, accountName string) (result ListBlobInventoryPolicy, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlobInventoryPoliciesClient.List") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("storage.BlobInventoryPoliciesClient", "List", err.Error()) + } + + req, err := client.ListPreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.BlobInventoryPoliciesClient", "List", resp, "Failure responding to request") + return + } + + return +} + +// ListPreparer prepares the List request. +func (client BlobInventoryPoliciesClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/inventoryPolicies", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client BlobInventoryPoliciesClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client BlobInventoryPoliciesClient) ListResponder(resp *http.Response) (result ListBlobInventoryPolicy, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/blobservices.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobservices.go similarity index 94% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/blobservices.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobservices.go index 95ae7c080c7d..047d8f9d2950 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/blobservices.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/blobservices.go @@ -104,7 +104,7 @@ func (client BlobServicesClient) GetServicePropertiesPreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -195,7 +195,7 @@ func (client BlobServicesClient) ListPreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -264,6 +264,12 @@ func (client BlobServicesClient) SetServiceProperties(ctx context.Context, resou {Target: "parameters.BlobServicePropertiesProperties.DeleteRetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, }}, }}, + {Target: "parameters.BlobServicePropertiesProperties.ChangeFeed", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.ChangeFeed.RetentionInDays", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.ChangeFeed.RetentionInDays", Name: validation.InclusiveMaximum, Rule: int64(146000), Chain: nil}, + {Target: "parameters.BlobServicePropertiesProperties.ChangeFeed.RetentionInDays", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, + }}, + }}, {Target: "parameters.BlobServicePropertiesProperties.RestorePolicy", Name: validation.Null, Rule: false, Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.RestorePolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil}, {Target: "parameters.BlobServicePropertiesProperties.RestorePolicy.Days", Name: validation.Null, Rule: false, @@ -277,6 +283,8 @@ func (client BlobServicesClient) SetServiceProperties(ctx context.Context, resou {Target: "parameters.BlobServicePropertiesProperties.ContainerDeleteRetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, }}, }}, + {Target: "parameters.BlobServicePropertiesProperties.LastAccessTimeTrackingPolicy", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.BlobServicePropertiesProperties.LastAccessTimeTrackingPolicy.Enable", Name: validation.Null, Rule: true, Chain: nil}}}, }}}}}); err != nil { return result, validation.NewError("storage.BlobServicesClient", "SetServiceProperties", err.Error()) } @@ -312,7 +320,7 @@ func (client BlobServicesClient) SetServicePropertiesPreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/client.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/client.go similarity index 98% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/client.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/client.go index af6ab21c698f..8bb2ffc30cdc 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/client.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/client.go @@ -1,4 +1,4 @@ -// Package storage implements the Azure ARM Storage service API version 2019-06-01. +// Package storage implements the Azure ARM Storage service API version 2021-01-01. // // The Azure Storage Management API. package storage diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/deletedaccounts.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/deletedaccounts.go new file mode 100644 index 000000000000..9d28115e6d81 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/deletedaccounts.go @@ -0,0 +1,247 @@ +package storage + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// DeletedAccountsClient is the the Azure Storage Management API. +type DeletedAccountsClient struct { + BaseClient +} + +// NewDeletedAccountsClient creates an instance of the DeletedAccountsClient client. +func NewDeletedAccountsClient(subscriptionID string) DeletedAccountsClient { + return NewDeletedAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewDeletedAccountsClientWithBaseURI creates an instance of the DeletedAccountsClient client using a custom endpoint. +// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewDeletedAccountsClientWithBaseURI(baseURI string, subscriptionID string) DeletedAccountsClient { + return DeletedAccountsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get properties of specified deleted account resource. +// Parameters: +// deletedAccountName - name of the deleted storage account. +// location - the location of the deleted storage account. +func (client DeletedAccountsClient) Get(ctx context.Context, deletedAccountName string, location string) (result DeletedAccount, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeletedAccountsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: deletedAccountName, + Constraints: []validation.Constraint{{Target: "deletedAccountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, + {Target: "deletedAccountName", Name: validation.MinLength, Rule: 3, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("storage.DeletedAccountsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, deletedAccountName, location) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client DeletedAccountsClient) GetPreparer(ctx context.Context, deletedAccountName string, location string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "deletedAccountName": autorest.Encode("path", deletedAccountName), + "location": autorest.Encode("path", location), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Storage/locations/{location}/deletedAccounts/{deletedAccountName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client DeletedAccountsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client DeletedAccountsClient) GetResponder(resp *http.Response) (result DeletedAccount, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List lists deleted accounts under the subscription. +func (client DeletedAccountsClient) List(ctx context.Context) (result DeletedAccountListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeletedAccountsClient.List") + defer func() { + sc := -1 + if result.dalr.Response.Response != nil { + sc = result.dalr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("storage.DeletedAccountsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.dalr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "List", resp, "Failure sending request") + return + } + + result.dalr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "List", resp, "Failure responding to request") + return + } + if result.dalr.hasNextLink() && result.dalr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client DeletedAccountsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Storage/deletedAccounts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client DeletedAccountsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client DeletedAccountsClient) ListResponder(resp *http.Response) (result DeletedAccountListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client DeletedAccountsClient) listNextResults(ctx context.Context, lastResults DeletedAccountListResult) (result DeletedAccountListResult, err error) { + req, err := lastResults.deletedAccountListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "storage.DeletedAccountsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client DeletedAccountsClient) ListComplete(ctx context.Context) (result DeletedAccountListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeletedAccountsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/encryptionscopes.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/encryptionscopes.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/encryptionscopes.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/encryptionscopes.go index adc6f516bb77..94c80309245a 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/encryptionscopes.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/encryptionscopes.go @@ -110,7 +110,7 @@ func (client EncryptionScopesClient) GetPreparer(ctx context.Context, resourceGr "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -206,7 +206,7 @@ func (client EncryptionScopesClient) ListPreparer(ctx context.Context, resourceG "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -343,7 +343,7 @@ func (client EncryptionScopesClient) PatchPreparer(ctx context.Context, resource "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -446,7 +446,7 @@ func (client EncryptionScopesClient) PutPreparer(ctx context.Context, resourceGr "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/enums.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/enums.go similarity index 90% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/enums.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/enums.go index dffd553cefc0..259d6dce7e9c 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/enums.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/enums.go @@ -132,6 +132,25 @@ func PossibleBypassValues() []Bypass { return []Bypass{AzureServices, Logging, Metrics, None} } +// CreatedByType enumerates the values for created by type. +type CreatedByType string + +const ( + // Application ... + Application CreatedByType = "Application" + // Key ... + Key CreatedByType = "Key" + // ManagedIdentity ... + ManagedIdentity CreatedByType = "ManagedIdentity" + // User ... + User CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns an array of possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{Application, Key, ManagedIdentity, User} +} + // DefaultAction enumerates the values for default action. type DefaultAction string @@ -209,6 +228,19 @@ func PossibleEncryptionScopeStateValues() []EncryptionScopeState { return []EncryptionScopeState{Disabled, Enabled} } +// ExtendedLocationTypes enumerates the values for extended location types. +type ExtendedLocationTypes string + +const ( + // EdgeZone ... + EdgeZone ExtendedLocationTypes = "EdgeZone" +) + +// PossibleExtendedLocationTypesValues returns an array of possible values for the ExtendedLocationTypes const type. +func PossibleExtendedLocationTypesValues() []ExtendedLocationTypes { + return []ExtendedLocationTypes{EdgeZone} +} + // GeoReplicationStatus enumerates the values for geo replication status. type GeoReplicationStatus string @@ -254,6 +286,25 @@ func PossibleHTTPProtocolValues() []HTTPProtocol { return []HTTPProtocol{HTTPS, Httpshttp} } +// IdentityType enumerates the values for identity type. +type IdentityType string + +const ( + // IdentityTypeNone ... + IdentityTypeNone IdentityType = "None" + // IdentityTypeSystemAssigned ... + IdentityTypeSystemAssigned IdentityType = "SystemAssigned" + // IdentityTypeSystemAssignedUserAssigned ... + IdentityTypeSystemAssignedUserAssigned IdentityType = "SystemAssigned,UserAssigned" + // IdentityTypeUserAssigned ... + IdentityTypeUserAssigned IdentityType = "UserAssigned" +) + +// PossibleIdentityTypeValues returns an array of possible values for the IdentityType const type. +func PossibleIdentityTypeValues() []IdentityType { + return []IdentityType{IdentityTypeNone, IdentityTypeSystemAssigned, IdentityTypeSystemAssignedUserAssigned, IdentityTypeUserAssigned} +} + // ImmutabilityPolicyState enumerates the values for immutability policy state. type ImmutabilityPolicyState string @@ -450,11 +501,13 @@ type ListSharesExpand string const ( // ListSharesExpandDeleted ... ListSharesExpandDeleted ListSharesExpand = "deleted" + // ListSharesExpandSnapshots ... + ListSharesExpandSnapshots ListSharesExpand = "snapshots" ) // PossibleListSharesExpandValues returns an array of possible values for the ListSharesExpand const type. func PossibleListSharesExpandValues() []ListSharesExpand { - return []ListSharesExpand{ListSharesExpandDeleted} + return []ListSharesExpand{ListSharesExpandDeleted, ListSharesExpandSnapshots} } // MinimumTLSVersion enumerates the values for minimum tls version. @@ -474,6 +527,19 @@ func PossibleMinimumTLSVersionValues() []MinimumTLSVersion { return []MinimumTLSVersion{TLS10, TLS11, TLS12} } +// Name enumerates the values for name. +type Name string + +const ( + // AccessTimeTracking ... + AccessTimeTracking Name = "AccessTimeTracking" +) + +// PossibleNameValues returns an array of possible values for the Name const type. +func PossibleNameValues() []Name { + return []Name{AccessTimeTracking} +} + // Permissions enumerates the values for permissions. type Permissions string @@ -572,6 +638,19 @@ func PossiblePublicAccessValues() []PublicAccess { return []PublicAccess{PublicAccessBlob, PublicAccessContainer, PublicAccessNone} } +// PutSharesExpand enumerates the values for put shares expand. +type PutSharesExpand string + +const ( + // Snapshots ... + Snapshots PutSharesExpand = "snapshots" +) + +// PossiblePutSharesExpandValues returns an array of possible values for the PutSharesExpand const type. +func PossiblePutSharesExpandValues() []PutSharesExpand { + return []PutSharesExpand{Snapshots} +} + // Reason enumerates the values for reason. type Reason string diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/fileservices.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/fileservices.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/fileservices.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/fileservices.go index 5b17abd7b305..5363cbed0cfe 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/fileservices.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/fileservices.go @@ -104,7 +104,7 @@ func (client FileServicesClient) GetServicePropertiesPreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -195,7 +195,7 @@ func (client FileServicesClient) ListPreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -299,7 +299,7 @@ func (client FileServicesClient) SetServicePropertiesPreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/fileshares.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/fileshares.go similarity index 96% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/fileshares.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/fileshares.go index 952efa860cce..2f8df86047be 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/fileshares.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/fileshares.go @@ -53,7 +53,8 @@ func NewFileSharesClientWithBaseURI(baseURI string, subscriptionID string) FileS // between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) // character must be immediately preceded and followed by a letter or number. // fileShare - properties of the file share to create. -func (client FileSharesClient) Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, fileShare FileShare) (result FileShare, err error) { +// expand - optional, used to create a snapshot. +func (client FileSharesClient) Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, fileShare FileShare, expand PutSharesExpand) (result FileShare, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/FileSharesClient.Create") defer func() { @@ -87,7 +88,7 @@ func (client FileSharesClient) Create(ctx context.Context, resourceGroupName str return result, validation.NewError("storage.FileSharesClient", "Create", err.Error()) } - req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, shareName, fileShare) + req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, shareName, fileShare, expand) if err != nil { err = autorest.NewErrorWithError(err, "storage.FileSharesClient", "Create", nil, "Failure preparing request") return @@ -110,7 +111,7 @@ func (client FileSharesClient) Create(ctx context.Context, resourceGroupName str } // CreatePreparer prepares the Create request. -func (client FileSharesClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, fileShare FileShare) (*http.Request, error) { +func (client FileSharesClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, fileShare FileShare, expand PutSharesExpand) (*http.Request, error) { pathParameters := map[string]interface{}{ "accountName": autorest.Encode("path", accountName), "resourceGroupName": autorest.Encode("path", resourceGroupName), @@ -118,10 +119,13 @@ func (client FileSharesClient) CreatePreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } + if len(string(expand)) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } preparer := autorest.CreatePreparer( autorest.AsContentType("application/json; charset=utf-8"), @@ -160,7 +164,8 @@ func (client FileSharesClient) CreateResponder(resp *http.Response) (result File // shareName - the name of the file share within the specified storage account. File share names must be // between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) // character must be immediately preceded and followed by a letter or number. -func (client FileSharesClient) Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string) (result autorest.Response, err error) { +// xMsSnapshot - optional, used to delete a snapshot. +func (client FileSharesClient) Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, xMsSnapshot string) (result autorest.Response, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/FileSharesClient.Delete") defer func() { @@ -187,7 +192,7 @@ func (client FileSharesClient) Delete(ctx context.Context, resourceGroupName str return result, validation.NewError("storage.FileSharesClient", "Delete", err.Error()) } - req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, shareName) + req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, shareName, xMsSnapshot) if err != nil { err = autorest.NewErrorWithError(err, "storage.FileSharesClient", "Delete", nil, "Failure preparing request") return @@ -210,7 +215,7 @@ func (client FileSharesClient) Delete(ctx context.Context, resourceGroupName str } // DeletePreparer prepares the Delete request. -func (client FileSharesClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string) (*http.Request, error) { +func (client FileSharesClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, xMsSnapshot string) (*http.Request, error) { pathParameters := map[string]interface{}{ "accountName": autorest.Encode("path", accountName), "resourceGroupName": autorest.Encode("path", resourceGroupName), @@ -218,7 +223,7 @@ func (client FileSharesClient) DeletePreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -228,6 +233,10 @@ func (client FileSharesClient) DeletePreparer(ctx context.Context, resourceGroup autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/fileServices/default/shares/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters)) + if len(xMsSnapshot) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("x-ms-snapshot", autorest.String(xMsSnapshot))) + } return preparer.Prepare((&http.Request{}).WithContext(ctx)) } @@ -258,7 +267,8 @@ func (client FileSharesClient) DeleteResponder(resp *http.Response) (result auto // between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) // character must be immediately preceded and followed by a letter or number. // expand - optional, used to expand the properties within share's properties. -func (client FileSharesClient) Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, expand GetShareExpand) (result FileShare, err error) { +// xMsSnapshot - optional, used to retrieve properties of a snapshot. +func (client FileSharesClient) Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, expand GetShareExpand, xMsSnapshot string) (result FileShare, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/FileSharesClient.Get") defer func() { @@ -285,7 +295,7 @@ func (client FileSharesClient) Get(ctx context.Context, resourceGroupName string return result, validation.NewError("storage.FileSharesClient", "Get", err.Error()) } - req, err := client.GetPreparer(ctx, resourceGroupName, accountName, shareName, expand) + req, err := client.GetPreparer(ctx, resourceGroupName, accountName, shareName, expand, xMsSnapshot) if err != nil { err = autorest.NewErrorWithError(err, "storage.FileSharesClient", "Get", nil, "Failure preparing request") return @@ -308,7 +318,7 @@ func (client FileSharesClient) Get(ctx context.Context, resourceGroupName string } // GetPreparer prepares the Get request. -func (client FileSharesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, expand GetShareExpand) (*http.Request, error) { +func (client FileSharesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, expand GetShareExpand, xMsSnapshot string) (*http.Request, error) { pathParameters := map[string]interface{}{ "accountName": autorest.Encode("path", accountName), "resourceGroupName": autorest.Encode("path", resourceGroupName), @@ -316,7 +326,7 @@ func (client FileSharesClient) GetPreparer(ctx context.Context, resourceGroupNam "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -329,6 +339,10 @@ func (client FileSharesClient) GetPreparer(ctx context.Context, resourceGroupNam autorest.WithBaseURL(client.BaseURI), autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/fileServices/default/shares/{shareName}", pathParameters), autorest.WithQueryParameters(queryParameters)) + if len(xMsSnapshot) > 0 { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithHeader("x-ms-snapshot", autorest.String(xMsSnapshot))) + } return preparer.Prepare((&http.Request{}).WithContext(ctx)) } @@ -418,7 +432,7 @@ func (client FileSharesClient) ListPreparer(ctx context.Context, resourceGroupNa "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -565,7 +579,7 @@ func (client FileSharesClient) RestorePreparer(ctx context.Context, resourceGrou "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -666,7 +680,7 @@ func (client FileSharesClient) UpdatePreparer(ctx context.Context, resourceGroup "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/managementpolicies.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/managementpolicies.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/managementpolicies.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/managementpolicies.go index 2eb496019d8e..f21aa1f7fa25 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/managementpolicies.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/managementpolicies.go @@ -110,7 +110,7 @@ func (client ManagementPoliciesClient) CreateOrUpdatePreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -204,7 +204,7 @@ func (client ManagementPoliciesClient) DeletePreparer(ctx context.Context, resou "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -295,7 +295,7 @@ func (client ManagementPoliciesClient) GetPreparer(ctx context.Context, resource "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/models.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/models.go similarity index 86% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/models.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/models.go index 9df759dbfe11..cce9349943d2 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/models.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/models.go @@ -29,7 +29,7 @@ import ( ) // The package's fully qualified name. -const fqdn = "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" +const fqdn = "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" // Account the storage account. type Account struct { @@ -40,6 +40,8 @@ type Account struct { Kind Kind `json:"kind,omitempty"` // Identity - The identity of the resource. Identity *Identity `json:"identity,omitempty"` + // ExtendedLocation - The extendedLocation of the resource. + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` // AccountProperties - Properties of the storage account. *AccountProperties `json:"properties,omitempty"` // Tags - Resource tags. @@ -60,6 +62,9 @@ func (a Account) MarshalJSON() ([]byte, error) { if a.Identity != nil { objectMap["identity"] = a.Identity } + if a.ExtendedLocation != nil { + objectMap["extendedLocation"] = a.ExtendedLocation + } if a.AccountProperties != nil { objectMap["properties"] = a.AccountProperties } @@ -108,6 +113,15 @@ func (a *Account) UnmarshalJSON(body []byte) error { } a.Identity = &identity } + case "extendedLocation": + if v != nil { + var extendedLocation ExtendedLocation + err = json.Unmarshal(*v, &extendedLocation) + if err != nil { + return err + } + a.ExtendedLocation = &extendedLocation + } case "properties": if v != nil { var accountProperties AccountProperties @@ -185,6 +199,8 @@ type AccountCreateParameters struct { Kind Kind `json:"kind,omitempty"` // Location - Required. Gets or sets the location of the resource. This will be one of the supported and registered Azure Geo Regions (e.g. West US, East US, Southeast Asia, etc.). The geo region of a resource cannot be changed once it is created, but if an identical geo region is specified on update, the request will succeed. Location *string `json:"location,omitempty"` + // ExtendedLocation - Optional. Set the extended location of the resource. If not set, the storage account will be created in Azure main region. Otherwise it will be created in the specified extended location + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` // Tags - Gets or sets a list of key value pairs that describe the resource. These tags can be used for viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key with a length no greater than 128 characters and a value with a length no greater than 256 characters. Tags map[string]*string `json:"tags"` // Identity - The identity of the resource. @@ -205,6 +221,9 @@ func (acp AccountCreateParameters) MarshalJSON() ([]byte, error) { if acp.Location != nil { objectMap["location"] = acp.Location } + if acp.ExtendedLocation != nil { + objectMap["extendedLocation"] = acp.ExtendedLocation + } if acp.Tags != nil { objectMap["tags"] = acp.Tags } @@ -253,6 +272,15 @@ func (acp *AccountCreateParameters) UnmarshalJSON(body []byte) error { } acp.Location = &location } + case "extendedLocation": + if v != nil { + var extendedLocation ExtendedLocation + err = json.Unmarshal(*v, &extendedLocation) + if err != nil { + return err + } + acp.ExtendedLocation = &extendedLocation + } case "tags": if v != nil { var tags map[string]*string @@ -542,6 +570,10 @@ type AccountProperties struct { AllowBlobPublicAccess *bool `json:"allowBlobPublicAccess,omitempty"` // MinimumTLSVersion - Set the minimum TLS version to be permitted on requests to storage. The default interpretation is TLS 1.0 for this property. Possible values include: 'TLS10', 'TLS11', 'TLS12' MinimumTLSVersion MinimumTLSVersion `json:"minimumTlsVersion,omitempty"` + // AllowSharedKeyAccess - Indicates whether the storage account permits requests to be authorized with the account access key via Shared Key. If false, then all requests, including shared access signatures, must be authorized with Azure Active Directory (Azure AD). The default value is null, which is equivalent to true. + AllowSharedKeyAccess *bool `json:"allowSharedKeyAccess,omitempty"` + // EnableNfsV3 - NFS 3.0 protocol support enabled if set to true. + EnableNfsV3 *bool `json:"isNfsV3Enabled,omitempty"` } // MarshalJSON is the custom marshaler for AccountProperties. @@ -568,6 +600,12 @@ func (ap AccountProperties) MarshalJSON() ([]byte, error) { if ap.MinimumTLSVersion != "" { objectMap["minimumTlsVersion"] = ap.MinimumTLSVersion } + if ap.AllowSharedKeyAccess != nil { + objectMap["allowSharedKeyAccess"] = ap.AllowSharedKeyAccess + } + if ap.EnableNfsV3 != nil { + objectMap["isNfsV3Enabled"] = ap.EnableNfsV3 + } return json.Marshal(objectMap) } @@ -595,6 +633,10 @@ type AccountPropertiesCreateParameters struct { AllowBlobPublicAccess *bool `json:"allowBlobPublicAccess,omitempty"` // MinimumTLSVersion - Set the minimum TLS version to be permitted on requests to storage. The default interpretation is TLS 1.0 for this property. Possible values include: 'TLS10', 'TLS11', 'TLS12' MinimumTLSVersion MinimumTLSVersion `json:"minimumTlsVersion,omitempty"` + // AllowSharedKeyAccess - Indicates whether the storage account permits requests to be authorized with the account access key via Shared Key. If false, then all requests, including shared access signatures, must be authorized with Azure Active Directory (Azure AD). The default value is null, which is equivalent to true. + AllowSharedKeyAccess *bool `json:"allowSharedKeyAccess,omitempty"` + // EnableNfsV3 - NFS 3.0 protocol support enabled if set to true. + EnableNfsV3 *bool `json:"isNfsV3Enabled,omitempty"` } // AccountPropertiesUpdateParameters the parameters used when updating a storage account. @@ -619,6 +661,8 @@ type AccountPropertiesUpdateParameters struct { AllowBlobPublicAccess *bool `json:"allowBlobPublicAccess,omitempty"` // MinimumTLSVersion - Set the minimum TLS version to be permitted on requests to storage. The default interpretation is TLS 1.0 for this property. Possible values include: 'TLS10', 'TLS11', 'TLS12' MinimumTLSVersion MinimumTLSVersion `json:"minimumTlsVersion,omitempty"` + // AllowSharedKeyAccess - Indicates whether the storage account permits requests to be authorized with the account access key via Shared Key. If false, then all requests, including shared access signatures, must be authorized with Azure Active Directory (Azure AD). The default value is null, which is equivalent to true. + AllowSharedKeyAccess *bool `json:"allowSharedKeyAccess,omitempty"` } // AccountRegenerateKeyParameters the parameters used to regenerate the storage account key. @@ -890,6 +934,151 @@ func (bc *BlobContainer) UnmarshalJSON(body []byte) error { return nil } +// BlobInventoryPolicy the storage account blob inventory policy. +type BlobInventoryPolicy struct { + autorest.Response `json:"-"` + // BlobInventoryPolicyProperties - Returns the storage account blob inventory policy rules. + *BlobInventoryPolicyProperties `json:"properties,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for BlobInventoryPolicy. +func (bip BlobInventoryPolicy) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if bip.BlobInventoryPolicyProperties != nil { + objectMap["properties"] = bip.BlobInventoryPolicyProperties + } + if bip.SystemData != nil { + objectMap["systemData"] = bip.SystemData + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for BlobInventoryPolicy struct. +func (bip *BlobInventoryPolicy) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var blobInventoryPolicyProperties BlobInventoryPolicyProperties + err = json.Unmarshal(*v, &blobInventoryPolicyProperties) + if err != nil { + return err + } + bip.BlobInventoryPolicyProperties = &blobInventoryPolicyProperties + } + case "systemData": + if v != nil { + var systemData SystemData + err = json.Unmarshal(*v, &systemData) + if err != nil { + return err + } + bip.SystemData = &systemData + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + bip.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + bip.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + bip.Type = &typeVar + } + } + } + + return nil +} + +// BlobInventoryPolicyDefinition an object that defines the blob inventory rule. Each definition consists +// of a set of filters. +type BlobInventoryPolicyDefinition struct { + // Filters - An object that defines the filter set. + Filters *BlobInventoryPolicyFilter `json:"filters,omitempty"` +} + +// BlobInventoryPolicyFilter an object that defines the blob inventory rule filter conditions. +type BlobInventoryPolicyFilter struct { + // PrefixMatch - An array of strings for blob prefixes to be matched. + PrefixMatch *[]string `json:"prefixMatch,omitempty"` + // BlobTypes - An array of predefined enum values. Valid values include blockBlob, appendBlob, pageBlob. Hns accounts does not support pageBlobs. + BlobTypes *[]string `json:"blobTypes,omitempty"` + // IncludeBlobVersions - Includes blob versions in blob inventory when value set to true. + IncludeBlobVersions *bool `json:"includeBlobVersions,omitempty"` + // IncludeSnapshots - Includes blob snapshots in blob inventory when value set to true. + IncludeSnapshots *bool `json:"includeSnapshots,omitempty"` +} + +// BlobInventoryPolicyProperties the storage account blob inventory policy properties. +type BlobInventoryPolicyProperties struct { + // LastModifiedTime - READ-ONLY; Returns the last modified date and time of the blob inventory policy. + LastModifiedTime *date.Time `json:"lastModifiedTime,omitempty"` + // Policy - The storage account blob inventory policy object. It is composed of policy rules. + Policy *BlobInventoryPolicySchema `json:"policy,omitempty"` +} + +// MarshalJSON is the custom marshaler for BlobInventoryPolicyProperties. +func (bipp BlobInventoryPolicyProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if bipp.Policy != nil { + objectMap["policy"] = bipp.Policy + } + return json.Marshal(objectMap) +} + +// BlobInventoryPolicyRule an object that wraps the blob inventory rule. Each rule is uniquely defined by +// name. +type BlobInventoryPolicyRule struct { + // Enabled - Rule is enabled when set to true. + Enabled *bool `json:"enabled,omitempty"` + // Name - A rule name can contain any combination of alpha numeric characters. Rule name is case-sensitive. It must be unique within a policy. + Name *string `json:"name,omitempty"` + // Definition - An object that defines the blob inventory policy rule. + Definition *BlobInventoryPolicyDefinition `json:"definition,omitempty"` +} + +// BlobInventoryPolicySchema the storage account blob inventory policy rules. +type BlobInventoryPolicySchema struct { + // Enabled - Policy is enabled if set to true. + Enabled *bool `json:"enabled,omitempty"` + // Destination - Container name where blob inventory files are stored. Must be pre-created. + Destination *string `json:"destination,omitempty"` + // Type - The valid value is Inventory + Type *string `json:"type,omitempty"` + // Rules - The storage account blob inventory policy rules. The rule is applied when it is enabled. + Rules *[]BlobInventoryPolicyRule `json:"rules,omitempty"` +} + // BlobRestoreParameters blob restore parameters type BlobRestoreParameters struct { // TimeToRestore - Restore blob to the specified time. @@ -1028,12 +1217,16 @@ type BlobServicePropertiesProperties struct { RestorePolicy *RestorePolicyProperties `json:"restorePolicy,omitempty"` // ContainerDeleteRetentionPolicy - The blob service properties for container soft delete. ContainerDeleteRetentionPolicy *DeleteRetentionPolicy `json:"containerDeleteRetentionPolicy,omitempty"` + // LastAccessTimeTrackingPolicy - The blob service property to configure last access time based tracking policy. + LastAccessTimeTrackingPolicy *LastAccessTimeTrackingPolicy `json:"lastAccessTimeTrackingPolicy,omitempty"` } // ChangeFeed the blob service properties for change feed events. type ChangeFeed struct { // Enabled - Indicates whether change feed event logging is enabled for the Blob service. Enabled *bool `json:"enabled,omitempty"` + // RetentionInDays - Indicates the duration of changeFeed retention in days. Minimum value is 1 day and maximum value is 146000 days (400 years). A null value indicates an infinite retention of the change feed. + RetentionInDays *int32 `json:"retentionInDays,omitempty"` } // CheckNameAvailabilityResult the CheckNameAvailability operation response. @@ -1152,10 +1345,260 @@ type DateAfterCreation struct { DaysAfterCreationGreaterThan *float64 `json:"daysAfterCreationGreaterThan,omitempty"` } -// DateAfterModification object to define the number of days after last modification. +// DateAfterModification object to define the number of days after object last modification Or last access. +// Properties daysAfterModificationGreaterThan and daysAfterLastAccessTimeGreaterThan are mutually +// exclusive. type DateAfterModification struct { // DaysAfterModificationGreaterThan - Value indicating the age in days after last modification DaysAfterModificationGreaterThan *float64 `json:"daysAfterModificationGreaterThan,omitempty"` + // DaysAfterLastAccessTimeGreaterThan - Value indicating the age in days after last blob access. This property can only be used in conjunction with last access time tracking policy + DaysAfterLastAccessTimeGreaterThan *float64 `json:"daysAfterLastAccessTimeGreaterThan,omitempty"` +} + +// DeletedAccount deleted storage account +type DeletedAccount struct { + autorest.Response `json:"-"` + // DeletedAccountProperties - Properties of the deleted account. + *DeletedAccountProperties `json:"properties,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for DeletedAccount. +func (da DeletedAccount) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if da.DeletedAccountProperties != nil { + objectMap["properties"] = da.DeletedAccountProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for DeletedAccount struct. +func (da *DeletedAccount) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var deletedAccountProperties DeletedAccountProperties + err = json.Unmarshal(*v, &deletedAccountProperties) + if err != nil { + return err + } + da.DeletedAccountProperties = &deletedAccountProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + da.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + da.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + da.Type = &typeVar + } + } + } + + return nil +} + +// DeletedAccountListResult the response from the List Deleted Accounts operation. +type DeletedAccountListResult struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Gets the list of deleted accounts and their properties. + Value *[]DeletedAccount `json:"value,omitempty"` + // NextLink - READ-ONLY; Request URL that can be used to query next page of deleted accounts. Returned when total number of requested deleted accounts exceed maximum page size. + NextLink *string `json:"nextLink,omitempty"` +} + +// DeletedAccountListResultIterator provides access to a complete listing of DeletedAccount values. +type DeletedAccountListResultIterator struct { + i int + page DeletedAccountListResultPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DeletedAccountListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeletedAccountListResultIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DeletedAccountListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DeletedAccountListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DeletedAccountListResultIterator) Response() DeletedAccountListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DeletedAccountListResultIterator) Value() DeletedAccount { + if !iter.page.NotDone() { + return DeletedAccount{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the DeletedAccountListResultIterator type. +func NewDeletedAccountListResultIterator(page DeletedAccountListResultPage) DeletedAccountListResultIterator { + return DeletedAccountListResultIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (dalr DeletedAccountListResult) IsEmpty() bool { + return dalr.Value == nil || len(*dalr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (dalr DeletedAccountListResult) hasNextLink() bool { + return dalr.NextLink != nil && len(*dalr.NextLink) != 0 +} + +// deletedAccountListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dalr DeletedAccountListResult) deletedAccountListResultPreparer(ctx context.Context) (*http.Request, error) { + if !dalr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dalr.NextLink))) +} + +// DeletedAccountListResultPage contains a page of DeletedAccount values. +type DeletedAccountListResultPage struct { + fn func(context.Context, DeletedAccountListResult) (DeletedAccountListResult, error) + dalr DeletedAccountListResult +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DeletedAccountListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DeletedAccountListResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.dalr) + if err != nil { + return err + } + page.dalr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DeletedAccountListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DeletedAccountListResultPage) NotDone() bool { + return !page.dalr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DeletedAccountListResultPage) Response() DeletedAccountListResult { + return page.dalr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DeletedAccountListResultPage) Values() []DeletedAccount { + if page.dalr.IsEmpty() { + return nil + } + return *page.dalr.Value +} + +// Creates a new instance of the DeletedAccountListResultPage type. +func NewDeletedAccountListResultPage(cur DeletedAccountListResult, getNextPage func(context.Context, DeletedAccountListResult) (DeletedAccountListResult, error)) DeletedAccountListResultPage { + return DeletedAccountListResultPage{ + fn: getNextPage, + dalr: cur, + } +} + +// DeletedAccountProperties attributes of a deleted storage account. +type DeletedAccountProperties struct { + // StorageAccountResourceID - READ-ONLY; Full resource id of the original storage account. + StorageAccountResourceID *string `json:"storageAccountResourceId,omitempty"` + // Location - READ-ONLY; Location of the deleted account. + Location *string `json:"location,omitempty"` + // RestoreReference - READ-ONLY; Can be used to attempt recovering this deleted account via PutStorageAccount API. + RestoreReference *string `json:"restoreReference,omitempty"` + // CreationTime - READ-ONLY; Creation time of the deleted account. + CreationTime *string `json:"creationTime,omitempty"` + // DeletionTime - READ-ONLY; Deletion time of the deleted account. + DeletionTime *string `json:"deletionTime,omitempty"` } // DeletedShare the deleted share to be restored. @@ -1192,6 +1635,14 @@ type Encryption struct { RequireInfrastructureEncryption *bool `json:"requireInfrastructureEncryption,omitempty"` // KeyVaultProperties - Properties provided by key vault. KeyVaultProperties *KeyVaultProperties `json:"keyvaultproperties,omitempty"` + // EncryptionIdentity - The identity to be used with service-side encryption at rest. + EncryptionIdentity *EncryptionIdentity `json:"identity,omitempty"` +} + +// EncryptionIdentity encryption identity for the storage account. +type EncryptionIdentity struct { + // EncryptionUserAssignedIdentity - Resource identifier of the UserAssigned identity to be associated with server-side encryption on the storage account. + EncryptionUserAssignedIdentity *string `json:"userAssignedIdentity,omitempty"` } // EncryptionScope the Encryption Scope resource. @@ -1272,6 +1723,19 @@ func (es *EncryptionScope) UnmarshalJSON(body []byte) error { type EncryptionScopeKeyVaultProperties struct { // KeyURI - The object identifier for a key vault key object. When applied, the encryption scope will use the key referenced by the identifier to enable customer-managed key support on this encryption scope. KeyURI *string `json:"keyUri,omitempty"` + // CurrentVersionedKeyIdentifier - READ-ONLY; The object identifier of the current versioned Key Vault Key in use. + CurrentVersionedKeyIdentifier *string `json:"currentVersionedKeyIdentifier,omitempty"` + // LastKeyRotationTimestamp - READ-ONLY; Timestamp of last rotation of the Key Vault Key. + LastKeyRotationTimestamp *date.Time `json:"lastKeyRotationTimestamp,omitempty"` +} + +// MarshalJSON is the custom marshaler for EncryptionScopeKeyVaultProperties. +func (eskvp EncryptionScopeKeyVaultProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if eskvp.KeyURI != nil { + objectMap["keyUri"] = eskvp.KeyURI + } + return json.Marshal(objectMap) } // EncryptionScopeListResult list of encryption scopes requested, and if paging is required, a URL to the @@ -1446,6 +1910,8 @@ type EncryptionScopeProperties struct { LastModifiedTime *date.Time `json:"lastModifiedTime,omitempty"` // KeyVaultProperties - The key vault properties for the encryption scope. This is a required field if encryption scope 'source' attribute is set to 'Microsoft.KeyVault'. KeyVaultProperties *EncryptionScopeKeyVaultProperties `json:"keyVaultProperties,omitempty"` + // RequireInfrastructureEncryption - A boolean indicating whether or not the service applies a secondary layer of encryption with platform managed keys for data at rest. + RequireInfrastructureEncryption *bool `json:"requireInfrastructureEncryption,omitempty"` } // MarshalJSON is the custom marshaler for EncryptionScopeProperties. @@ -1460,6 +1926,9 @@ func (esp EncryptionScopeProperties) MarshalJSON() ([]byte, error) { if esp.KeyVaultProperties != nil { objectMap["keyVaultProperties"] = esp.KeyVaultProperties } + if esp.RequireInfrastructureEncryption != nil { + objectMap["requireInfrastructureEncryption"] = esp.RequireInfrastructureEncryption + } return json.Marshal(objectMap) } @@ -1532,12 +2001,26 @@ func (e Endpoints) MarshalJSON() ([]byte, error) { // ErrorResponse an error response from the storage resource provider. type ErrorResponse struct { + // Error - Azure Storage Resource Provider error response body. + Error *ErrorResponseBody `json:"error,omitempty"` +} + +// ErrorResponseBody error response body contract. +type ErrorResponseBody struct { // Code - An identifier for the error. Codes are invariant and are intended to be consumed programmatically. Code *string `json:"code,omitempty"` // Message - A message describing the error, intended to be suitable for display in a user interface. Message *string `json:"message,omitempty"` } +// ExtendedLocation the complex type of the extended location. +type ExtendedLocation struct { + // Name - The name of the extended location. + Name *string `json:"name,omitempty"` + // Type - The type of the extended location. Possible values include: 'EdgeZone' + Type ExtendedLocationTypes `json:"type,omitempty"` +} + // FileServiceItems ... type FileServiceItems struct { autorest.Response `json:"-"` @@ -1635,6 +2118,8 @@ type FileServicePropertiesProperties struct { Cors *CorsRules `json:"cors,omitempty"` // ShareDeleteRetentionPolicy - The file service properties for share soft delete. ShareDeleteRetentionPolicy *DeleteRetentionPolicy `json:"shareDeleteRetentionPolicy,omitempty"` + // ProtocolSettings - Protocol settings for file service + ProtocolSettings *ProtocolSettings `json:"protocolSettings,omitempty"` } // FileShare properties of the file share, including Id, resource name, resource type, Etag. @@ -1992,6 +2477,8 @@ type FileShareProperties struct { AccessTierStatus *string `json:"accessTierStatus,omitempty"` // ShareUsageBytes - READ-ONLY; The approximate size of the data stored on the share. Note that this value may not include all recently created or recently resized files. ShareUsageBytes *int64 `json:"shareUsageBytes,omitempty"` + // SnapshotTime - READ-ONLY; Creation time of share snapshot returned in the response of list shares with expand param "snapshots". + SnapshotTime *date.Time `json:"snapshotTime,omitempty"` } // MarshalJSON is the custom marshaler for FileShareProperties. @@ -2032,16 +2519,21 @@ type Identity struct { PrincipalID *string `json:"principalId,omitempty"` // TenantID - READ-ONLY; The tenant ID of resource. TenantID *string `json:"tenantId,omitempty"` - // Type - The identity type. - Type *string `json:"type,omitempty"` + // Type - The identity type. Possible values include: 'IdentityTypeNone', 'IdentityTypeSystemAssigned', 'IdentityTypeUserAssigned', 'IdentityTypeSystemAssignedUserAssigned' + Type IdentityType `json:"type,omitempty"` + // UserAssignedIdentities - Gets or sets a list of key value pairs that describe the set of User Assigned identities that will be used with this storage account. The key is the ARM resource identifier of the identity. Only 1 User Assigned identity is permitted here. + UserAssignedIdentities map[string]*UserAssignedIdentity `json:"userAssignedIdentities"` } // MarshalJSON is the custom marshaler for Identity. func (i Identity) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - if i.Type != nil { + if i.Type != "" { objectMap["type"] = i.Type } + if i.UserAssignedIdentities != nil { + objectMap["userAssignedIdentities"] = i.UserAssignedIdentities + } return json.Marshal(objectMap) } @@ -2250,6 +2742,18 @@ func (kvp KeyVaultProperties) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// LastAccessTimeTrackingPolicy the blob service properties for Last access time based tracking policy. +type LastAccessTimeTrackingPolicy struct { + // Enable - When set to true last access time based tracking is enabled. + Enable *bool `json:"enable,omitempty"` + // Name - Name of the policy. The valid value is AccessTimeTracking. This field is currently read only. Possible values include: 'AccessTimeTracking' + Name Name `json:"name,omitempty"` + // TrackingGranularityInDays - The field specifies blob object tracking granularity in days, typically how often the blob object should be tracked.This field is currently read only with value as 1 + TrackingGranularityInDays *int32 `json:"trackingGranularityInDays,omitempty"` + // BlobType - An array of predefined supported blob types. Only blockBlob is the supported value. This field is currently read only + BlobType *[]string `json:"blobType,omitempty"` +} + // LeaseContainerRequest lease Container request schema. type LeaseContainerRequest struct { // Action - Specifies the lease action. Can be one of the available actions. Possible values include: 'Acquire', 'Renew', 'Change', 'Release', 'Break' @@ -2315,6 +2819,13 @@ type ListAccountSasResponse struct { AccountSasToken *string `json:"accountSasToken,omitempty"` } +// ListBlobInventoryPolicy list of blob inventory policies returned. +type ListBlobInventoryPolicy struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; List of blob inventory policies. + Value *[]BlobInventoryPolicy `json:"value,omitempty"` +} + // ListContainerItem the blob container properties be listed out. type ListContainerItem struct { // ContainerProperties - The blob container properties be listed out. @@ -3063,6 +3574,8 @@ type ManagementPolicyAction struct { BaseBlob *ManagementPolicyBaseBlob `json:"baseBlob,omitempty"` // Snapshot - The management policy action for snapshot Snapshot *ManagementPolicySnapShot `json:"snapshot,omitempty"` + // Version - The management policy action for version + Version *ManagementPolicyVersion `json:"version,omitempty"` } // ManagementPolicyBaseBlob management policy action for base blob. @@ -3073,6 +3586,8 @@ type ManagementPolicyBaseBlob struct { TierToArchive *DateAfterModification `json:"tierToArchive,omitempty"` // Delete - The function to delete the blob Delete *DateAfterModification `json:"delete,omitempty"` + // EnableAutoTierToHotFromCool - This property enables auto tiering of a blob from cool to hot on a blob access. This property requires tierToCool.daysAfterLastAccessTimeGreaterThan. + EnableAutoTierToHotFromCool *bool `json:"enableAutoTierToHotFromCool,omitempty"` } // ManagementPolicyDefinition an object that defines the Lifecycle rule. Each definition is made up with a @@ -3089,7 +3604,7 @@ type ManagementPolicyDefinition struct { type ManagementPolicyFilter struct { // PrefixMatch - An array of strings for prefixes to be match. PrefixMatch *[]string `json:"prefixMatch,omitempty"` - // BlobTypes - An array of predefined enum values. Only blockBlob is supported. + // BlobTypes - An array of predefined enum values. Currently blockBlob supports all tiering and delete actions. Only delete actions are supported for appendBlob. BlobTypes *[]string `json:"blobTypes,omitempty"` // BlobIndexMatch - An array of blob index tag based filters, there can be at most 10 tag filters BlobIndexMatch *[]TagFilter `json:"blobIndexMatch,omitempty"` @@ -3133,10 +3648,24 @@ type ManagementPolicySchema struct { // ManagementPolicySnapShot management policy action for snapshot. type ManagementPolicySnapShot struct { + // TierToCool - The function to tier blob snapshot to cool storage. Support blob snapshot currently at Hot tier + TierToCool *DateAfterCreation `json:"tierToCool,omitempty"` + // TierToArchive - The function to tier blob snapshot to archive storage. Support blob snapshot currently at Hot or Cool tier + TierToArchive *DateAfterCreation `json:"tierToArchive,omitempty"` // Delete - The function to delete the blob snapshot Delete *DateAfterCreation `json:"delete,omitempty"` } +// ManagementPolicyVersion management policy action for blob version. +type ManagementPolicyVersion struct { + // TierToCool - The function to tier blob version to cool storage. Support blob version currently at Hot tier + TierToCool *DateAfterCreation `json:"tierToCool,omitempty"` + // TierToArchive - The function to tier blob version to archive storage. Support blob version currently at Hot or Cool tier + TierToArchive *DateAfterCreation `json:"tierToArchive,omitempty"` + // Delete - The function to delete the blob version + Delete *DateAfterCreation `json:"delete,omitempty"` +} + // MetricSpecification metric specification of operation. type MetricSpecification struct { // Name - Name of metric specification. @@ -3159,10 +3688,18 @@ type MetricSpecification struct { ResourceIDDimensionNameOverride *string `json:"resourceIdDimensionNameOverride,omitempty"` } +// Multichannel multichannel setting. Applies to Premium FileStorage only. +type Multichannel struct { + // Enabled - Indicates whether multichannel is enabled + Enabled *bool `json:"enabled,omitempty"` +} + // NetworkRuleSet network rule set type NetworkRuleSet struct { // Bypass - Specifies whether traffic is bypassed for Logging/Metrics/AzureServices. Possible values are any combination of Logging|Metrics|AzureServices (For example, "Logging, Metrics"), or None to bypass none of those traffics. Possible values include: 'None', 'Logging', 'Metrics', 'AzureServices' Bypass Bypass `json:"bypass,omitempty"` + // ResourceAccessRules - Sets the resource access rules + ResourceAccessRules *[]ResourceAccessRule `json:"resourceAccessRules,omitempty"` // VirtualNetworkRules - Sets the virtual network rules VirtualNetworkRules *[]VirtualNetworkRule `json:"virtualNetworkRules,omitempty"` // IPRules - Sets the IP ACL rules @@ -3616,6 +4153,12 @@ type PrivateLinkServiceConnectionState struct { ActionRequired *string `json:"actionRequired,omitempty"` } +// ProtocolSettings protocol settings for file service +type ProtocolSettings struct { + // Smb - Setting for SMB protocol + Smb *SmbSetting `json:"smb,omitempty"` +} + // ProxyResource the resource model definition for a Azure Resource Manager proxy resource. It will not // have tags and a location type ProxyResource struct { @@ -3806,6 +4349,14 @@ type Resource struct { Type *string `json:"type,omitempty"` } +// ResourceAccessRule resource Access Rule. +type ResourceAccessRule struct { + // TenantID - Tenant Id + TenantID *string `json:"tenantId,omitempty"` + // ResourceID - Resource Id + ResourceID *string `json:"resourceId,omitempty"` +} + // RestorePolicyProperties the blob service properties for blob restore policy type RestorePolicyProperties struct { // Enabled - Blob restore is enabled if set to true. @@ -3963,6 +4514,36 @@ type SkuListResult struct { Value *[]SkuInformation `json:"value,omitempty"` } +// SmbSetting setting for SMB protocol +type SmbSetting struct { + // Multichannel - Multichannel setting. Applies to Premium FileStorage only. + Multichannel *Multichannel `json:"multichannel,omitempty"` + // Versions - SMB protocol versions supported by server. Valid values are SMB2.1, SMB3.0, SMB3.1.1. Should be passed as a string with delimiter ';'. + Versions *string `json:"versions,omitempty"` + // AuthenticationMethods - SMB authentication methods supported by server. Valid values are NTLMv2, Kerberos. Should be passed as a string with delimiter ';'. + AuthenticationMethods *string `json:"authenticationMethods,omitempty"` + // KerberosTicketEncryption - Kerberos ticket encryption supported by server. Valid values are RC4-HMAC, AES-256. Should be passed as a string with delimiter ';' + KerberosTicketEncryption *string `json:"kerberosTicketEncryption,omitempty"` + // ChannelEncryption - SMB channel encryption supported by server. Valid values are AES-128-CCM, AES-128-GCM, AES-256-GCM. Should be passed as a string with delimiter ';'. + ChannelEncryption *string `json:"channelEncryption,omitempty"` +} + +// SystemData metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // CreatedBy - The identity that created the resource. + CreatedBy *string `json:"createdBy,omitempty"` + // CreatedByType - The type of identity that created the resource. Possible values include: 'User', 'Application', 'ManagedIdentity', 'Key' + CreatedByType CreatedByType `json:"createdByType,omitempty"` + // CreatedAt - The timestamp of resource creation (UTC). + CreatedAt *date.Time `json:"createdAt,omitempty"` + // LastModifiedBy - The identity that last modified the resource. + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + // LastModifiedByType - The type of identity that last modified the resource. Possible values include: 'User', 'Application', 'ManagedIdentity', 'Key' + LastModifiedByType CreatedByType `json:"lastModifiedByType,omitempty"` + // LastModifiedAt - The timestamp of resource last modification (UTC) + LastModifiedAt *date.Time `json:"lastModifiedAt,omitempty"` +} + // Table properties of the table, including Id, resource name, resource type. type Table struct { autorest.Response `json:"-"` @@ -4215,6 +4796,14 @@ type UsageName struct { LocalizedValue *string `json:"localizedValue,omitempty"` } +// UserAssignedIdentity userAssignedIdentity for the resource. +type UserAssignedIdentity struct { + // PrincipalID - READ-ONLY; The principal ID of the identity. + PrincipalID *string `json:"principalId,omitempty"` + // ClientID - READ-ONLY; The client ID of the identity. + ClientID *string `json:"clientId,omitempty"` +} + // VirtualNetworkRule virtual Network rule. type VirtualNetworkRule struct { // VirtualNetworkResourceID - Resource ID of a subnet, for example: /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}. diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/objectreplicationpolicies.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/objectreplicationpolicies.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/objectreplicationpolicies.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/objectreplicationpolicies.go index 961a61725dd0..4d8de1311513 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/objectreplicationpolicies.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/objectreplicationpolicies.go @@ -114,7 +114,7 @@ func (client ObjectReplicationPoliciesClient) CreateOrUpdatePreparer(ctx context "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -211,7 +211,7 @@ func (client ObjectReplicationPoliciesClient) DeletePreparer(ctx context.Context "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -305,7 +305,7 @@ func (client ObjectReplicationPoliciesClient) GetPreparer(ctx context.Context, r "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -396,7 +396,7 @@ func (client ObjectReplicationPoliciesClient) ListPreparer(ctx context.Context, "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/operations.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/operations.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/operations.go index 3761d2ec80f9..11cdaae6d648 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/operations.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/operations.go @@ -77,7 +77,7 @@ func (client OperationsClient) List(ctx context.Context) (result OperationListRe // ListPreparer prepares the List request. func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/privateendpointconnections.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/privateendpointconnections.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/privateendpointconnections.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/privateendpointconnections.go index b98f386f3ece..4e4e38585a51 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/privateendpointconnections.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/privateendpointconnections.go @@ -106,7 +106,7 @@ func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -199,7 +199,7 @@ func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -290,7 +290,7 @@ func (client PrivateEndpointConnectionsClient) ListPreparer(ctx context.Context, "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -388,7 +388,7 @@ func (client PrivateEndpointConnectionsClient) PutPreparer(ctx context.Context, "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/privatelinkresources.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/privatelinkresources.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/privatelinkresources.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/privatelinkresources.go index caeff89a2b6e..a4d14543ba05 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/privatelinkresources.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/privatelinkresources.go @@ -103,7 +103,7 @@ func (client PrivateLinkResourcesClient) ListByStorageAccountPreparer(ctx contex "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/queue.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/queue.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/queue.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/queue.go index d7eb622859a1..2896bda2f317 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/queue.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/queue.go @@ -110,7 +110,7 @@ func (client QueueClient) CreatePreparer(ctx context.Context, resourceGroupName "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -210,7 +210,7 @@ func (client QueueClient) DeletePreparer(ctx context.Context, resourceGroupName "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -307,7 +307,7 @@ func (client QueueClient) GetPreparer(ctx context.Context, resourceGroupName str "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -406,7 +406,7 @@ func (client QueueClient) ListPreparer(ctx context.Context, resourceGroupName st "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -548,7 +548,7 @@ func (client QueueClient) UpdatePreparer(ctx context.Context, resourceGroupName "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/queueservices.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/queueservices.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/queueservices.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/queueservices.go index 88b1824cde6d..e4b8b0bc294f 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/queueservices.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/queueservices.go @@ -104,7 +104,7 @@ func (client QueueServicesClient) GetServicePropertiesPreparer(ctx context.Conte "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -195,7 +195,7 @@ func (client QueueServicesClient) ListPreparer(ctx context.Context, resourceGrou "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -290,7 +290,7 @@ func (client QueueServicesClient) SetServicePropertiesPreparer(ctx context.Conte "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/skus.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/skus.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/skus.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/skus.go index f7ba31c5bbfa..f21121f38a7a 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/skus.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/skus.go @@ -88,7 +88,7 @@ func (client SkusClient) ListPreparer(ctx context.Context) (*http.Request, error "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/table.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/table.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/table.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/table.go index 7b0971675280..278b4af2bd25 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/table.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/table.go @@ -109,7 +109,7 @@ func (client TableClient) CreatePreparer(ctx context.Context, resourceGroupName "tableName": autorest.Encode("path", tableName), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -207,7 +207,7 @@ func (client TableClient) DeletePreparer(ctx context.Context, resourceGroupName "tableName": autorest.Encode("path", tableName), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -304,7 +304,7 @@ func (client TableClient) GetPreparer(ctx context.Context, resourceGroupName str "tableName": autorest.Encode("path", tableName), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -400,7 +400,7 @@ func (client TableClient) ListPreparer(ctx context.Context, resourceGroupName st "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -535,7 +535,7 @@ func (client TableClient) UpdatePreparer(ctx context.Context, resourceGroupName "tableName": autorest.Encode("path", tableName), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/tableservices.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/tableservices.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/tableservices.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/tableservices.go index 3a6896ded419..c321ac49343f 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/tableservices.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/tableservices.go @@ -104,7 +104,7 @@ func (client TableServicesClient) GetServicePropertiesPreparer(ctx context.Conte "tableServiceName": autorest.Encode("path", "default"), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -195,7 +195,7 @@ func (client TableServicesClient) ListPreparer(ctx context.Context, resourceGrou "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } @@ -290,7 +290,7 @@ func (client TableServicesClient) SetServicePropertiesPreparer(ctx context.Conte "tableServiceName": autorest.Encode("path", "default"), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/usages.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/usages.go similarity index 99% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/usages.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/usages.go index 4a2dbee945de..f167323a1394 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/usages.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/usages.go @@ -91,7 +91,7 @@ func (client UsagesClient) ListByLocationPreparer(ctx context.Context, location "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - const APIVersion = "2019-06-01" + const APIVersion = "2021-01-01" queryParameters := map[string]interface{}{ "api-version": APIVersion, } diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/version.go b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/version.go similarity index 94% rename from vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/version.go rename to vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/version.go index 78053be11000..92496f6c3d1e 100644 --- a/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage/version.go +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage/version.go @@ -21,7 +21,7 @@ import "github.com/Azure/azure-sdk-for-go/version" // UserAgent returns the UserAgent string to use when sending http.Requests. func UserAgent() string { - return "Azure-SDK-For-Go/" + Version() + " storage/2019-06-01" + return "Azure-SDK-For-Go/" + Version() + " storage/2021-01-01" } // Version returns the semantic version (see http://semver.org) of the client. diff --git a/vendor/modules.txt b/vendor/modules.txt index dd42b05ef7df..32c7cd16e663 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -113,7 +113,7 @@ github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources github.com/Azure/azure-sdk-for-go/services/search/mgmt/2020-03-13/search github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus github.com/Azure/azure-sdk-for-go/services/signalr/mgmt/2020-05-01/signalr -github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage +github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache github.com/Azure/azure-sdk-for-go/services/storagesync/mgmt/2020-03-01/storagesync github.com/Azure/azure-sdk-for-go/services/streamanalytics/mgmt/2016-03-01/streamanalytics From 91096c5f744534e4ae0aa9547a0dcede7c904a4f Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 24 Mar 2021 14:15:04 +0800 Subject: [PATCH 10/29] update --- .../storage_account_customer_managed_key_resource_test.go | 4 ++-- .../internal/services/storage/storage_blob_resource_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go index 6f543a513ec2..3569ed2d4e52 100644 --- a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go +++ b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go @@ -18,14 +18,14 @@ import ( type StorageAccountCustomerManagedKeyResource struct{} func TestAccStorageAccountCustomerManagedKey_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_storage_account_customer_managed_key", "test") + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") r := StorageAccountCustomerManagedKeyResource{} data.ResourceTest(t, r, []resource.TestStep{ { Config: r.basic(data), Check: resource.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), + check.That("azurerm_storage_account_customer_managed_key.test").ExistsInAzure(r), ), }, data.ImportStep(), diff --git a/azurerm/internal/services/storage/storage_blob_resource_test.go b/azurerm/internal/services/storage/storage_blob_resource_test.go index 16fd4cefc237..fc5010c37e11 100644 --- a/azurerm/internal/services/storage/storage_blob_resource_test.go +++ b/azurerm/internal/services/storage/storage_blob_resource_test.go @@ -337,7 +337,7 @@ func TestAccStorageBlob_pageFromExistingBlob(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.ImportStep("parallelism", "size", "type"), + data.ImportStep("parallelism", "size", "type", "source_uri"), }) } @@ -361,7 +361,7 @@ func TestAccStorageBlob_pageFromLocalFile(t *testing.T) { data.CheckWithClient(r.blobMatchesFile(blobs.PageBlob, sourceBlob.Name())), ), }, - data.ImportStep("parallelism", "size", "type"), + data.ImportStep("parallelism", "size", "type", "source"), }) } From 4ec4dfb0864a254b867e155271d917cd14258923 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 24 Mar 2021 14:17:51 +0800 Subject: [PATCH 11/29] fmt --- .../services/storage/storage_container_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/storage_container_resource_test.go b/azurerm/internal/services/storage/storage_container_resource_test.go index 8b9503e35577..cd15a966d717 100644 --- a/azurerm/internal/services/storage/storage_container_resource_test.go +++ b/azurerm/internal/services/storage/storage_container_resource_test.go @@ -394,7 +394,7 @@ resource "azurerm_storage_account" "test" { location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" -allow_blob_public_access = true + allow_blob_public_access = true tags = { environment = "staging" From 50905a69ede2d867c5299a385cc8ddb249d6cdfc Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 24 Mar 2021 14:28:54 +0800 Subject: [PATCH 12/29] update --- .../storage_account_customer_managed_key_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go index 3569ed2d4e52..4235759d81af 100644 --- a/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go +++ b/azurerm/internal/services/storage/storage_account_customer_managed_key_resource_test.go @@ -101,7 +101,7 @@ func TestAccStorageAccountCustomerManagedKey_testKeyVersion(t *testing.T) { } func (r StorageAccountCustomerManagedKeyResource) accountHasDefaultSettings(ctx context.Context, client *clients.Client, state *terraform.InstanceState) error { - accountId, err := storageParse.StorageAccountID(state.Attributes["storage_account_id"]) + accountId, err := storageParse.StorageAccountID(state.Attributes["id"]) if err != nil { return err } From 1a29cd847e4470d707ebffe1b63300e37f1a22fb Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Thu, 25 Mar 2021 09:53:49 +0800 Subject: [PATCH 13/29] update acctest --- ...rage_management_policy_data_source_test.go | 5 ---- ...storage_management_policy_resource_test.go | 26 ------------------- 2 files changed, 31 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go index 886e3c68d6ba..23dc5bbc5b5b 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source_test.go @@ -23,9 +23,7 @@ func TestAccDataSourceStorageManagementPolicy_basic(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -50,10 +48,7 @@ func TestAccDataSourceStorageManagementPolicy_blobTypes(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.932666486").HasValue("appendBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 706122f32b85..743b9d86109c 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -30,9 +30,7 @@ func TestAccStorageManagementPolicy_basic(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -60,9 +58,7 @@ func TestAccStorageManagementPolicy_singleAction(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -88,9 +84,7 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -108,9 +102,7 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("30"), @@ -138,9 +130,7 @@ func TestAccStorageManagementPolicy_multipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -154,10 +144,7 @@ func TestAccStorageManagementPolicy_multipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.4102595489").HasValue("container2/prefix1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.1837232667").HasValue("container2/prefix2"), check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), @@ -187,9 +174,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -203,10 +188,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.4102595489").HasValue("container2/prefix1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.1837232667").HasValue("container2/prefix2"), check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), @@ -228,9 +210,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), @@ -244,10 +224,7 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { check.That(data.ResourceName).Key("rule.1.enabled").HasValue("true"), // check updated check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.4102595489").HasValue("container2/prefix1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.1837232667").HasValue("container2/prefix2"), check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.1068358194").HasValue("blockBlob"), check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("12"), // check updated @@ -275,10 +252,7 @@ func TestAccStorageManagementPolicy_blobTypes(t *testing.T) { check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.3439697764").HasValue("container1/prefix1"), check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.1068358194").HasValue("blockBlob"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.932666486").HasValue("appendBlob"), check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), From 1b81a29e090f2c6555f7f94c56de60d083d555bd Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 26 Mar 2021 16:55:28 +0800 Subject: [PATCH 14/29] update --- .../storage_management_policy_resource.go | 483 ++++++++++++------ ...storage_management_policy_resource_test.go | 316 ++++++------ 2 files changed, 490 insertions(+), 309 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index e0497117de29..db86a51d00c8 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -5,8 +5,6 @@ import ( "regexp" "time" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-01-01/storage" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -128,23 +126,45 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tier_to_cool_after_days_since_modification_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, + Optional: true, + Default: nil, + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "tier_to_cool_after_days_since_last_access_time_greater_than": { + Type: schema.TypeFloat, Optional: true, Default: nil, - ValidateFunc: validation.IntAtLeast(0), + ValidateFunc: validation.FloatBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Optional: true, Default: nil, - ValidateFunc: validation.IntAtLeast(0), + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "tier_to_archive_after_days_since_last_access_time_greater_than": { + Type: schema.TypeFloat, + Optional: true, + Default: nil, + ValidateFunc: validation.FloatBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, + Optional: true, + Default: nil, + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "delete_after_days_since_last_access_time_greater_than": { + Type: schema.TypeFloat, Optional: true, Default: nil, - ValidateFunc: validation.IntAtLeast(0), + ValidateFunc: validation.FloatBetween(0, 99999), }, + "enable_auto_tier_to_hot_from_cool": { + Type: schema.TypeBool, + Optional: true, + Default: false}, }, }, }, @@ -155,9 +175,43 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_after_days_since_creation_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, + Optional: true, + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "tier_to_archive_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Optional: true, + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "tier_to_cool_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Optional: true, + ValidateFunc: validation.FloatBetween(0, 99999), + }, + }, + }, + }, + "version": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "delete_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, Optional: true, - ValidateFunc: validation.IntAtLeast(0), + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "tier_to_archive_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Optional: true, + ValidateFunc: validation.FloatBetween(0, 99999), + }, + "tier_to_cool_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Optional: true, + ValidateFunc: validation.FloatBetween(0, 99999), }, }, }, @@ -190,16 +244,10 @@ func resourceStorageManagementPolicyCreateOrUpdate(d *schema.ResourceData, meta parameters := storage.ManagementPolicy{ Name: &name, - } - - armRules, err := expandStorageManagementPolicyRules(d) - if err != nil { - return fmt.Errorf("Error expanding Azure Storage Management Policy Rules %q: %+v", storageAccountId, err) - } - - parameters.ManagementPolicyProperties = &storage.ManagementPolicyProperties{ - Policy: &storage.ManagementPolicySchema{ - Rules: armRules, + ManagementPolicyProperties: &storage.ManagementPolicyProperties{ + Policy: &storage.ManagementPolicySchema{ + Rules: expandStorageManagementPolicyRules(d.Get("rule").([]interface{})), + }, }, } @@ -274,179 +322,284 @@ func resourceStorageManagementPolicyDelete(d *schema.ResourceData, meta interfac } // nolint unparam -func expandStorageManagementPolicyRules(d *schema.ResourceData) (*[]storage.ManagementPolicyRule, error) { - var result []storage.ManagementPolicyRule - - rules := d.Get("rule").([]interface{}) +func expandStorageManagementPolicyRules(inputs []interface{}) *[]storage.ManagementPolicyRule { + result := make([]storage.ManagementPolicyRule, 0) + if len(inputs) == 0 { + return &result + } - for k, v := range rules { - if v != nil { - result = append(result, expandStorageManagementPolicyRule(d, k)) + for _, input := range inputs { + v := input.(map[string]interface{}) + rule := storage.ManagementPolicyRule{ + Name: utils.String(v["name"].(string)), + Enabled: utils.Bool(v["enabled"].(bool)), + Type: utils.String("Lifecycle"), + Definition: &storage.ManagementPolicyDefinition{ + Actions: expandStorageManagementPolicyActions(v["actions"].([]interface{})), + Filters: expandStorageManagementPolicyFilters(v["filters"].([]interface{})), + }, } + result = append(result, rule) } - return &result, nil + return &result } -func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) storage.ManagementPolicyRule { - name := d.Get(fmt.Sprintf("rule.%d.name", ruleIndex)).(string) - enabled := d.Get(fmt.Sprintf("rule.%d.enabled", ruleIndex)).(bool) - typeVal := "Lifecycle" - - definition := storage.ManagementPolicyDefinition{ - Filters: &storage.ManagementPolicyFilter{}, - Actions: &storage.ManagementPolicyAction{}, - } - filtersRef := d.Get(fmt.Sprintf("rule.%d.filters", ruleIndex)).([]interface{}) - if len(filtersRef) == 1 { - if filtersRef[0] != nil { - filterRef := filtersRef[0].(map[string]interface{}) - - prefixMatches := []string{} - prefixMatchesRef := filterRef["prefix_match"].(*schema.Set) - if prefixMatchesRef != nil { - for _, prefixMatchRef := range prefixMatchesRef.List() { - prefixMatches = append(prefixMatches, prefixMatchRef.(string)) - } - } - definition.Filters.PrefixMatch = &prefixMatches - - blobTypes := []string{} - blobTypesRef := filterRef["blob_types"].(*schema.Set) - if blobTypesRef != nil { - for _, blobTypeRef := range blobTypesRef.List() { - blobTypes = append(blobTypes, blobTypeRef.(string)) - } - } - definition.Filters.BlobTypes = &blobTypes +func expandStorageManagementPolicyFilters(inputs []interface{}) *storage.ManagementPolicyFilter { + if len(inputs) == 0 { + return nil + } + input := inputs[0].(map[string]interface{}) - definition.Filters.BlobIndexMatch = expandAzureRmStorageBlobIndexMatch(filterRef["blob_index_match_tag"].(*schema.Set).List()) - } + return &storage.ManagementPolicyFilter{ + PrefixMatch: utils.ExpandStringSlice(input["prefix_match"].(*schema.Set).List()), + BlobTypes: utils.ExpandStringSlice(input["blob_types"].(*schema.Set).List()), + BlobIndexMatch: expandAzureRmStorageBlobIndexMatch(input["blob_index_match_tag"].(*schema.Set).List()), } - if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions", ruleIndex)); ok { - if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob", ruleIndex)); ok { - baseBlob := &storage.ManagementPolicyBaseBlob{} - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", ruleIndex)); ok { - if v != nil { - baseBlob.TierToCool = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(float64(v.(int))), - } - } - } - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", ruleIndex)); ok { - if v != nil { - baseBlob.TierToArchive = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(float64(v.(int))), - } - } - } - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", ruleIndex)); ok { - if v != nil { - baseBlob.Delete = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(float64(v.(int))), - } - } - } - definition.Actions.BaseBlob = baseBlob - } +} - if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot", ruleIndex)); ok { - snapshot := &storage.ManagementPolicySnapShot{} - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", ruleIndex)); ok { - v2 := float64(v.(int)) - snapshot.Delete = &storage.DateAfterCreation{DaysAfterCreationGreaterThan: &v2} - } - definition.Actions.Snapshot = snapshot - } +func expandStorageManagementPolicyActions(inputs []interface{}) *storage.ManagementPolicyAction { + if len(inputs) == 0 { + return nil } + input := inputs[0].(map[string]interface{}) - rule := storage.ManagementPolicyRule{ - Name: &name, - Enabled: &enabled, - Type: &typeVal, - Definition: &definition, + return &storage.ManagementPolicyAction{ + BaseBlob: expandStorageManagementPolicyActionsBaseBlob(input["base_blob"].([]interface{})), + Snapshot: expandStorageManagementPolicyActionsSnapshot(input["snapshot"].([]interface{})), + Version: expandStorageManagementPolicyActionsVersion(input["version"].([]interface{})), + } +} + +func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage.ManagementPolicyBaseBlob { + if len(inputs) == 0 { + return nil + } + input := inputs[0].(map[string]interface{}) + + return &storage.ManagementPolicyBaseBlob{ + EnableAutoTierToHotFromCool: utils.Bool(input["enable_auto_tier_to_hot_from_cool"].(bool)), + Delete: &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(input["delete_after_days_since_modification_greater_than"].(float64)), + DaysAfterLastAccessTimeGreaterThan: utils.Float(input["delete_after_days_since_last_access_time_greater_than"].(float64)), + }, + TierToArchive: &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_modification_greater_than"].(float64)), + DaysAfterLastAccessTimeGreaterThan: utils.Float(input["tier_to_archive_after_days_since_last_access_time_greater_than"].(float64)), + }, + TierToCool: &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_modification_greater_than"].(float64)), + DaysAfterLastAccessTimeGreaterThan: utils.Float(input["tier_to_cool_after_days_since_last_access_time_greater_than"].(float64)), + }, + } +} + +func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage.ManagementPolicySnapShot { + if len(inputs) == 0 { + return nil + } + input := inputs[0].(map[string]interface{}) + + return &storage.ManagementPolicySnapShot{ + Delete: &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(input["delete_after_days_since_creation_greater_than"].(float64)), + }, + TierToArchive: &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_creation_greater_than"].(float64)), + }, + TierToCool: &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_creation_greater_than"].(float64)), + }, + } +} + +func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage.ManagementPolicyVersion { + if len(inputs) == 0 { + return nil + } + input := inputs[0].(map[string]interface{}) + + return &storage.ManagementPolicyVersion{ + Delete: &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(input["delete_after_days_since_creation_greater_than"].(float64)), + }, + TierToArchive: &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_creation_greater_than"].(float64)), + }, + TierToCool: &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_creation_greater_than"].(float64)), + }, } - return rule } func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRule) []interface{} { rules := make([]interface{}, 0) - if armRules == nil { + if armRules == nil || len(*armRules) == 0 { return rules } - for _, armRule := range *armRules { - rule := make(map[string]interface{}) + for _, armRule := range *armRules { + var name string if armRule.Name != nil { - rule["name"] = *armRule.Name + name = *armRule.Name } + var enabled bool if armRule.Enabled != nil { - rule["enabled"] = *armRule.Enabled + enabled = *armRule.Enabled } - armDefinition := armRule.Definition - if armDefinition != nil { - armFilter := armDefinition.Filters - if armFilter != nil { - filter := make(map[string]interface{}) - if armFilter.PrefixMatch != nil { - prefixMatches := make([]interface{}, 0) - for _, armPrefixMatch := range *armFilter.PrefixMatch { - prefixMatches = append(prefixMatches, armPrefixMatch) - } - filter["prefix_match"] = prefixMatches - } - if armFilter.BlobTypes != nil { - blobTypes := make([]interface{}, 0) - for _, armBlobType := range *armFilter.BlobTypes { - blobTypes = append(blobTypes, armBlobType) - } - filter["blob_types"] = blobTypes - } - - filter["blob_index_match_tag"] = flattenAzureRmStorageBlobIndexMatch(armFilter.BlobIndexMatch) - - rule["filters"] = [1]interface{}{filter} - } + var filters, actions []interface{} + if armRule.Definition != nil { + filters = flattenStorageManagementPolicyFilters(armRule.Definition.Filters) + actions = flattenStorageManagementPolicyActions(armRule.Definition.Actions) + } - armAction := armDefinition.Actions - if armAction != nil { - action := make(map[string]interface{}) - armActionBaseBlob := armAction.BaseBlob - if armActionBaseBlob != nil { - baseBlob := make(map[string]interface{}) - if armActionBaseBlob.TierToCool != nil && armActionBaseBlob.TierToCool.DaysAfterModificationGreaterThan != nil { - intTemp := int(*armActionBaseBlob.TierToCool.DaysAfterModificationGreaterThan) - baseBlob["tier_to_cool_after_days_since_modification_greater_than"] = intTemp - } - if armActionBaseBlob.TierToArchive != nil && armActionBaseBlob.TierToArchive.DaysAfterModificationGreaterThan != nil { - intTemp := int(*armActionBaseBlob.TierToArchive.DaysAfterModificationGreaterThan) - baseBlob["tier_to_archive_after_days_since_modification_greater_than"] = intTemp - } - if armActionBaseBlob.Delete != nil && armActionBaseBlob.Delete.DaysAfterModificationGreaterThan != nil { - intTemp := int(*armActionBaseBlob.Delete.DaysAfterModificationGreaterThan) - baseBlob["delete_after_days_since_modification_greater_than"] = intTemp - } - action["base_blob"] = [1]interface{}{baseBlob} - } - - armActionSnaphost := armAction.Snapshot - if armActionSnaphost != nil { - snapshot := make(map[string]interface{}) - if armActionSnaphost.Delete != nil && armActionSnaphost.Delete.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionSnaphost.Delete.DaysAfterCreationGreaterThan) - snapshot["delete_after_days_since_creation_greater_than"] = intTemp - } - action["snapshot"] = [1]interface{}{snapshot} - } - - rule["actions"] = [1]interface{}{action} - } + rules = append(rules, map[string]interface{}{ + "name": name, + "enabled": enabled, + "filters": filters, + "actions": actions, + }) + } + return rules +} + +func flattenStorageManagementPolicyFilters(filters *storage.ManagementPolicyFilter) []interface{} { + if filters == nil { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "prefix_match": utils.FlattenStringSlice((*filters).PrefixMatch), + "blob_types": utils.FlattenStringSlice((*filters).BlobTypes), + "blob_index_match_tag": flattenAzureRmStorageBlobIndexMatch((*filters).BlobIndexMatch), + }, + } +} + +func flattenStorageManagementPolicyActions(actions *storage.ManagementPolicyAction) []interface{} { + if actions == nil { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "base_blob": flattenStorageManagementPolicyActionsBaseBlob((*actions).BaseBlob), + "snapshot": flattenStorageManagementPolicyActionsSnapshot((*actions).Snapshot), + "version": flattenStorageManagementPolicyActionsVersion((*actions).Version), + }, + } +} + +func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementPolicyBaseBlob) []interface{} { + if baseBlob == nil { + return []interface{}{} + } + + var deleteModification, deleteAccess, archiveModification, archiveAccess, coolModification, coolAccess float64 + var enableAutoCool bool + if v := baseBlob.Delete; v != nil { + if v.DaysAfterLastAccessTimeGreaterThan != nil { + deleteModification = *v.DaysAfterModificationGreaterThan + } + if v.DaysAfterLastAccessTimeGreaterThan != nil { + deleteAccess = *v.DaysAfterLastAccessTimeGreaterThan + } + } + if v := baseBlob.TierToArchive; v != nil { + if v.DaysAfterLastAccessTimeGreaterThan != nil { + archiveModification = *v.DaysAfterModificationGreaterThan + } + if v.DaysAfterLastAccessTimeGreaterThan != nil { + archiveAccess = *v.DaysAfterLastAccessTimeGreaterThan + } + } + if v := baseBlob.TierToCool; v != nil { + if v.DaysAfterLastAccessTimeGreaterThan != nil { + coolModification = *v.DaysAfterModificationGreaterThan + } + if v.DaysAfterLastAccessTimeGreaterThan != nil { + coolAccess = *v.DaysAfterLastAccessTimeGreaterThan } + } - rules = append(rules, rule) + if baseBlob.EnableAutoTierToHotFromCool != nil { + enableAutoCool = *baseBlob.EnableAutoTierToHotFromCool } - return rules + return []interface{}{ + map[string]interface{}{ + "delete_after_days_since_modification_greater_than": deleteModification, + "delete_after_days_since_last_access_time_greater_than": deleteAccess, + "tier_to_archive_after_days_since_modification_greater_than": archiveModification, + "tier_to_archive_after_days_since_last_access_time_greater_than": archiveAccess, + "tier_to_cool_after_days_since_modification_greater_than": coolModification, + "tier_to_cool_after_days_since_last_access_time_greater_than": coolAccess, + "enable_auto_tier_to_hot_from_cool": enableAutoCool, + }, + } +} + +func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementPolicySnapShot) []interface{} { + if snapshot == nil { + return []interface{}{} + } + + var deleteCreation, archiveCreation, coolCreation float64 + if v := snapshot.Delete; v != nil { + if v.DaysAfterCreationGreaterThan != nil { + deleteCreation = *v.DaysAfterCreationGreaterThan + } + } + if v := snapshot.TierToArchive; v != nil { + if v.DaysAfterCreationGreaterThan != nil { + archiveCreation = *v.DaysAfterCreationGreaterThan + } + } + if v := snapshot.TierToCool; v != nil { + if v.DaysAfterCreationGreaterThan != nil { + coolCreation = *v.DaysAfterCreationGreaterThan + } + } + + return []interface{}{ + map[string]interface{}{ + "delete_after_days_since_creation_greater_than": deleteCreation, + "tier_to_archive_after_days_since_creation_greater_than": archiveCreation, + "tier_to_cool_after_days_since_creation_greater_than": coolCreation, + }, + } +} + +func flattenStorageManagementPolicyActionsVersion(version *storage.ManagementPolicyVersion) []interface{} { + if version == nil { + return []interface{}{} + } + + var deleteCreation, archiveCreation, coolCreation float64 + if v := version.Delete; v != nil { + if v.DaysAfterCreationGreaterThan != nil { + deleteCreation = *v.DaysAfterCreationGreaterThan + } + } + if v := version.TierToArchive; v != nil { + if v.DaysAfterCreationGreaterThan != nil { + archiveCreation = *v.DaysAfterCreationGreaterThan + } + } + if v := version.TierToCool; v != nil { + if v.DaysAfterCreationGreaterThan != nil { + coolCreation = *v.DaysAfterCreationGreaterThan + } + } + + return []interface{}{ + map[string]interface{}{ + "delete_after_days_since_creation_greater_than": deleteCreation, + "tier_to_archive_after_days_since_creation_greater_than": archiveCreation, + "tier_to_cool_after_days_since_creation_greater_than": coolCreation, + }, + } } func expandAzureRmStorageBlobIndexMatch(blobIndexMatches []interface{}) *[]storage.TagFilter { diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 743b9d86109c..d955b0e46f60 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -25,19 +25,6 @@ func TestAccStorageManagementPolicy_basic(t *testing.T) { Config: r.basic(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -53,17 +40,6 @@ func TestAccStorageManagementPolicy_singleAction(t *testing.T) { Config: r.singleAction(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.name").HasValue("singleActionRule"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -79,17 +55,6 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { Config: r.singleAction(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.name").HasValue("singleActionRule"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -97,17 +62,6 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { Config: r.singleActionUpdate(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.name").HasValue("singleActionRule"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("30"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -123,35 +77,6 @@ func TestAccStorageManagementPolicy_multipleRule(t *testing.T) { Config: r.multipleRule(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("2"), - - // Rule1 - check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), - - // Rule2 - check.That(data.ResourceName).Key("rule.1.name").HasValue("rule2"), - check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), - check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("51"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("101"), - check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("31"), ), }, data.ImportStep(), @@ -167,35 +92,6 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { Config: r.multipleRule(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("2"), - - // Rule1 - check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), - - // Rule2 - check.That(data.ResourceName).Key("rule.1.name").HasValue("rule2"), - check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), - check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("51"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("101"), - check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("31"), ), }, data.ImportStep(), @@ -203,35 +99,6 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { Config: r.multipleRuleUpdated(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("2"), - - // Rule1 - check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), - - // Rule2 - check.That(data.ResourceName).Key("rule.1.name").HasValue("rule2"), - check.That(data.ResourceName).Key("rule.1.enabled").HasValue("true"), // check updated - check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("12"), // check updated - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("52"), // check updated - check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("102"), // check updated - check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("32"), // check updated ), }, data.ImportStep(), @@ -247,17 +114,6 @@ func TestAccStorageManagementPolicy_blobTypes(t *testing.T) { Config: r.blobTypes(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("rule.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), - check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), - check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("2"), - check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), - check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -293,6 +149,57 @@ func TestAccStorageManagementPolicy_blobIndexMatch(t *testing.T) { }) } +func TestAccStorageManagementPolicy_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + r := StorageManagementPolicyResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccStorageManagementPolicy_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + r := StorageManagementPolicyResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.completeUpdate(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r StorageManagementPolicyResource) Exists(ctx context.Context, client *clients.Client, state *terraform.InstanceState) (*bool, error) { storageAccountId := state.Attributes["storage_account_id"] id, err := parse.StorageAccountID(storageAccountId) @@ -711,3 +618,124 @@ resource "azurerm_storage_management_policy" "test" { } `, r.blobIndexMatchTemplate(data)) } + +func (r StorageManagementPolicyResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = azurerm_resource_group.test.name + + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "test" { + storage_account_id = azurerm_storage_account.test.id + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + blob_index_match_tag { + name = "tag1" + value = "val1" + } + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10.4 + tier_to_cool_after_days_since_last_access_time_greater_than = 2.45 + tier_to_archive_after_days_since_modification_greater_than = 50.89 + tier_to_archive_after_days_since_last_access_time_greater_than = 78.33 + delete_after_days_since_modification_greater_than = 100.13 + delete_after_days_since_last_access_time_greater_than = 50.78 + enable_auto_tier_to_hot_from_cool = true + } + snapshot { + delete_after_days_since_creation_greater_than = 30.3 + tier_to_archive_after_days_since_creation_greater_than = 90.8 + tier_to_cool_after_days_since_creation_greater_than = 23.8 + } + version { + delete_after_days_since_creation_greater_than = 3.4 + tier_to_archive_after_days_since_creation_greater_than = 9.8 + tier_to_cool_after_days_since_creation_greater_than = 90.3 + } + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func (r StorageManagementPolicyResource) completeUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = azurerm_resource_group.test.name + + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "test" { + storage_account_id = azurerm_storage_account.test.id + + rule { + name = "rule2" + enabled = true + filters { + prefix_match = ["container2/prefix2"] + blob_types = ["blockBlob", "appendBlob"] + blob_index_match_tag { + name = "tag2" + value = "val2" + } + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 11.4 + tier_to_cool_after_days_since_last_access_time_greater_than = 3.45 + tier_to_archive_after_days_since_modification_greater_than = 51.89 + tier_to_archive_after_days_since_last_access_time_greater_than = 79.33 + delete_after_days_since_modification_greater_than = 101.13 + delete_after_days_since_last_access_time_greater_than = 51.78 + } + snapshot { + delete_after_days_since_creation_greater_than = 31.3 + tier_to_archive_after_days_since_creation_greater_than = 91.8 + tier_to_cool_after_days_since_creation_greater_than = 24.8 + } + version { + delete_after_days_since_creation_greater_than = 4.4 + tier_to_archive_after_days_since_creation_greater_than = 10.8 + tier_to_cool_after_days_since_creation_greater_than = 91.3 + } + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} From af20341912ae45f530572dbe173560be5a74d751 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 29 Mar 2021 09:52:17 +0800 Subject: [PATCH 15/29] update --- .../storage_management_policy_resource.go | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index db86a51d00c8..8e239675f7dc 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -375,22 +375,29 @@ func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage return nil } input := inputs[0].(map[string]interface{}) - - return &storage.ManagementPolicyBaseBlob{ + result := storage.ManagementPolicyBaseBlob{ EnableAutoTierToHotFromCool: utils.Bool(input["enable_auto_tier_to_hot_from_cool"].(bool)), Delete: &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(input["delete_after_days_since_modification_greater_than"].(float64)), - DaysAfterLastAccessTimeGreaterThan: utils.Float(input["delete_after_days_since_last_access_time_greater_than"].(float64)), }, TierToArchive: &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_modification_greater_than"].(float64)), - DaysAfterLastAccessTimeGreaterThan: utils.Float(input["tier_to_archive_after_days_since_last_access_time_greater_than"].(float64)), }, TierToCool: &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_modification_greater_than"].(float64)), - DaysAfterLastAccessTimeGreaterThan: utils.Float(input["tier_to_cool_after_days_since_last_access_time_greater_than"].(float64)), }, } + + if v,ok:= input["delete_after_days_since_last_access_time_greater_than"];ok&&v!=""{ + result.Delete.DaysAfterLastAccessTimeGreaterThan = utils.Float(v.(float64)) + } + if v,ok:= input["tier_to_archive_after_days_since_last_access_time_greater_than"];ok&&v!=""{ + result.TierToArchive.DaysAfterLastAccessTimeGreaterThan = utils.Float(v.(float64)) + } + if v,ok:= input["tier_to_cool_after_days_since_last_access_time_greater_than"];ok&&v!=""{ + result.TierToCool.DaysAfterLastAccessTimeGreaterThan = utils.Float(v.(float64)) + } + return &result } func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage.ManagementPolicySnapShot { @@ -499,7 +506,7 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP var deleteModification, deleteAccess, archiveModification, archiveAccess, coolModification, coolAccess float64 var enableAutoCool bool if v := baseBlob.Delete; v != nil { - if v.DaysAfterLastAccessTimeGreaterThan != nil { + if v.DaysAfterModificationGreaterThan != nil { deleteModification = *v.DaysAfterModificationGreaterThan } if v.DaysAfterLastAccessTimeGreaterThan != nil { @@ -507,7 +514,7 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP } } if v := baseBlob.TierToArchive; v != nil { - if v.DaysAfterLastAccessTimeGreaterThan != nil { + if v.DaysAfterModificationGreaterThan != nil { archiveModification = *v.DaysAfterModificationGreaterThan } if v.DaysAfterLastAccessTimeGreaterThan != nil { @@ -515,7 +522,7 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP } } if v := baseBlob.TierToCool; v != nil { - if v.DaysAfterLastAccessTimeGreaterThan != nil { + if v.DaysAfterModificationGreaterThan != nil { coolModification = *v.DaysAfterModificationGreaterThan } if v.DaysAfterLastAccessTimeGreaterThan != nil { From e51c09aecbcfc661e76c938fa548a12fe3bdf8e9 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 29 Mar 2021 14:57:32 +0800 Subject: [PATCH 16/29] all pass --- .../storage_management_policy_data_source.go | 46 ++++- .../storage_management_policy_resource.go | 174 ++++++++---------- ...storage_management_policy_resource_test.go | 29 +-- .../d/storage_management_policy.html.markdown | 25 ++- .../r/storage_management_policy.html.markdown | 34 +++- 5 files changed, 173 insertions(+), 135 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source.go b/azurerm/internal/services/storage/storage_management_policy_data_source.go index 84267555b09b..b0784f5fce03 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source.go @@ -55,7 +55,7 @@ func dataSourceStorageManagementPolicy() *schema.Resource { }, "blob_index_match_tag": { - Type: schema.TypeSet, + Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -90,15 +90,15 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tier_to_cool_after_days_since_modification_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Computed: true, }, "tier_to_archive_after_days_since_modification_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Computed: true, }, "delete_after_days_since_modification_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, Computed: true, }, }, @@ -110,7 +110,36 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_after_days_since_creation_greater_than": { - Type: schema.TypeInt, + Type: schema.TypeFloat, + Computed: true, + }, + "tier_to_archive_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Computed: true, + }, + "tier_to_cool_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + }, + }, + }, + "version": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "delete_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Computed: true, + }, + "tier_to_archive_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, + Computed: true, + }, + "tier_to_cool_after_days_since_creation_greater_than": { + Type: schema.TypeFloat, Computed: true, }, }, @@ -146,11 +175,10 @@ func dataSourceStorageManagementPolicyRead(d *schema.ResourceData, meta interfac } d.SetId(*result.ID) - if result.Policy != nil { - policy := result.Policy - if policy.Rules != nil { + if props := result.ManagementPolicyProperties; props != nil { + if policy := props.Policy; policy != nil { if err := d.Set("rule", flattenStorageManagementPolicyRules(policy.Rules)); err != nil { - return fmt.Errorf("Error flattening `rule`: %+v", err) + return fmt.Errorf("flattening `rule`: %+v", err) } } } diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 8e239675f7dc..8195c3a665a2 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -128,43 +128,21 @@ func resourceStorageManagementPolicy() *schema.Resource { "tier_to_cool_after_days_since_modification_greater_than": { Type: schema.TypeFloat, Optional: true, - Default: nil, - ValidateFunc: validation.FloatBetween(0, 99999), - }, - "tier_to_cool_after_days_since_last_access_time_greater_than": { - Type: schema.TypeFloat, - Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { Type: schema.TypeFloat, Optional: true, - Default: nil, - ValidateFunc: validation.FloatBetween(0, 99999), - }, - "tier_to_archive_after_days_since_last_access_time_greater_than": { - Type: schema.TypeFloat, - Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { Type: schema.TypeFloat, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, - "delete_after_days_since_last_access_time_greater_than": { - Type: schema.TypeFloat, - Optional: true, - Default: nil, - ValidateFunc: validation.FloatBetween(0, 99999), - }, - "enable_auto_tier_to_hot_from_cool": { - Type: schema.TypeBool, - Optional: true, - Default: false}, }, }, }, @@ -177,16 +155,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "delete_after_days_since_creation_greater_than": { Type: schema.TypeFloat, Optional: true, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, "tier_to_archive_after_days_since_creation_greater_than": { Type: schema.TypeFloat, Optional: true, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, "tier_to_cool_after_days_since_creation_greater_than": { Type: schema.TypeFloat, Optional: true, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, }, @@ -201,16 +182,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "delete_after_days_since_creation_greater_than": { Type: schema.TypeFloat, Optional: true, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, "tier_to_archive_after_days_since_creation_greater_than": { Type: schema.TypeFloat, Optional: true, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, "tier_to_cool_after_days_since_creation_greater_than": { Type: schema.TypeFloat, Optional: true, + Default: -1, ValidateFunc: validation.FloatBetween(0, 99999), }, }, @@ -242,23 +226,28 @@ func resourceStorageManagementPolicyCreateOrUpdate(d *schema.ResourceData, meta name := "default" // The name of the Storage Account Management Policy. It should always be 'default' (from https://docs.microsoft.com/en-us/rest/api/storagerp/managementpolicies/createorupdate) + rules, err := expandStorageManagementPolicyRules(d.Get("rule").([]interface{})) + if err != nil { + return err + } + parameters := storage.ManagementPolicy{ Name: &name, ManagementPolicyProperties: &storage.ManagementPolicyProperties{ Policy: &storage.ManagementPolicySchema{ - Rules: expandStorageManagementPolicyRules(d.Get("rule").([]interface{})), + Rules: rules, }, }, } result, err := client.CreateOrUpdate(ctx, resourceGroupName, storageAccountName, parameters) if err != nil { - return fmt.Errorf("Error creating Azure Storage Management Policy %q: %+v", storageAccountId, err) + return fmt.Errorf("creating Azure Storage Management Policy %q: %+v", storageAccountId, err) } result, err = client.Get(ctx, resourceGroupName, storageAccountName) if err != nil { - return fmt.Errorf("Error getting created Azure Storage Management Policy %q: %+v", storageAccountId, err) + return fmt.Errorf("getting created Azure Storage Management Policy %q: %+v", storageAccountId, err) } d.SetId(*result.ID) @@ -293,7 +282,7 @@ func resourceStorageManagementPolicyRead(d *schema.ResourceData, meta interface{ policy := result.Policy if rules := policy.Rules; rules != nil { if err := d.Set("rule", flattenStorageManagementPolicyRules(policy.Rules)); err != nil { - return fmt.Errorf("Error flattening `rule`: %+v", err) + return fmt.Errorf("flattening `rule`: %+v", err) } } } @@ -322,10 +311,10 @@ func resourceStorageManagementPolicyDelete(d *schema.ResourceData, meta interfac } // nolint unparam -func expandStorageManagementPolicyRules(inputs []interface{}) *[]storage.ManagementPolicyRule { +func expandStorageManagementPolicyRules(inputs []interface{}) (*[]storage.ManagementPolicyRule, error) { result := make([]storage.ManagementPolicyRule, 0) if len(inputs) == 0 { - return &result + return &result, nil } for _, input := range inputs { @@ -339,9 +328,12 @@ func expandStorageManagementPolicyRules(inputs []interface{}) *[]storage.Managem Filters: expandStorageManagementPolicyFilters(v["filters"].([]interface{})), }, } + if (rule.Definition.Actions.Version != nil || rule.Definition.Actions.Snapshot != nil) && rule.Definition.Filters.BlobIndexMatch != nil { + return nil, fmt.Errorf("`blob_index_match_tag` is not supported as a filter for versions and snapshots") + } result = append(result, rule) } - return &result + return &result, nil } func expandStorageManagementPolicyFilters(inputs []interface{}) *storage.ManagementPolicyFilter { @@ -375,28 +367,24 @@ func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage return nil } input := inputs[0].(map[string]interface{}) - result := storage.ManagementPolicyBaseBlob{ - EnableAutoTierToHotFromCool: utils.Bool(input["enable_auto_tier_to_hot_from_cool"].(bool)), - Delete: &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(input["delete_after_days_since_modification_greater_than"].(float64)), - }, - TierToArchive: &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_modification_greater_than"].(float64)), - }, - TierToCool: &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_modification_greater_than"].(float64)), - }, - } + result := storage.ManagementPolicyBaseBlob{} - if v,ok:= input["delete_after_days_since_last_access_time_greater_than"];ok&&v!=""{ - result.Delete.DaysAfterLastAccessTimeGreaterThan = utils.Float(v.(float64)) + if v, ok := input["delete_after_days_since_modification_greater_than"].(float64); ok && v != -1 { + result.Delete = &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(v), + } } - if v,ok:= input["tier_to_archive_after_days_since_last_access_time_greater_than"];ok&&v!=""{ - result.TierToArchive.DaysAfterLastAccessTimeGreaterThan = utils.Float(v.(float64)) + if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(float64); ok && v != -1 { + result.TierToArchive = &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(v), + } } - if v,ok:= input["tier_to_cool_after_days_since_last_access_time_greater_than"];ok&&v!=""{ - result.TierToCool.DaysAfterLastAccessTimeGreaterThan = utils.Float(v.(float64)) + if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(float64); ok && v != -1 { + result.TierToCool = &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(v), + } } + return &result } @@ -406,17 +394,25 @@ func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage } input := inputs[0].(map[string]interface{}) - return &storage.ManagementPolicySnapShot{ - Delete: &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(input["delete_after_days_since_creation_greater_than"].(float64)), - }, - TierToArchive: &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_creation_greater_than"].(float64)), - }, - TierToCool: &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_creation_greater_than"].(float64)), - }, + result := storage.ManagementPolicySnapShot{} + + if v, ok := input["delete_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + result.Delete = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(v), + } + } + if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + result.TierToArchive = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(v), + } } + if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + result.TierToCool = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(v), + } + } + + return &result } func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage.ManagementPolicyVersion { @@ -425,17 +421,25 @@ func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage. } input := inputs[0].(map[string]interface{}) - return &storage.ManagementPolicyVersion{ - Delete: &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(input["delete_after_days_since_creation_greater_than"].(float64)), - }, - TierToArchive: &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(input["tier_to_archive_after_days_since_creation_greater_than"].(float64)), - }, - TierToCool: &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(input["tier_to_cool_after_days_since_creation_greater_than"].(float64)), - }, + result := storage.ManagementPolicyVersion{} + + if v, ok := input["delete_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + result.Delete = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(v), + } + } + if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + result.TierToArchive = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(v), + } } + if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + result.TierToCool = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(v), + } + } + + return &result } func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRule) []interface{} { @@ -503,46 +507,28 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP return []interface{}{} } - var deleteModification, deleteAccess, archiveModification, archiveAccess, coolModification, coolAccess float64 - var enableAutoCool bool + deleteModification, archiveModification, coolModification := float64(-1), float64(-1), float64(-1) if v := baseBlob.Delete; v != nil { if v.DaysAfterModificationGreaterThan != nil { deleteModification = *v.DaysAfterModificationGreaterThan } - if v.DaysAfterLastAccessTimeGreaterThan != nil { - deleteAccess = *v.DaysAfterLastAccessTimeGreaterThan - } } if v := baseBlob.TierToArchive; v != nil { if v.DaysAfterModificationGreaterThan != nil { archiveModification = *v.DaysAfterModificationGreaterThan } - if v.DaysAfterLastAccessTimeGreaterThan != nil { - archiveAccess = *v.DaysAfterLastAccessTimeGreaterThan - } } if v := baseBlob.TierToCool; v != nil { if v.DaysAfterModificationGreaterThan != nil { coolModification = *v.DaysAfterModificationGreaterThan } - if v.DaysAfterLastAccessTimeGreaterThan != nil { - coolAccess = *v.DaysAfterLastAccessTimeGreaterThan - } - } - - if baseBlob.EnableAutoTierToHotFromCool != nil { - enableAutoCool = *baseBlob.EnableAutoTierToHotFromCool } return []interface{}{ map[string]interface{}{ - "delete_after_days_since_modification_greater_than": deleteModification, - "delete_after_days_since_last_access_time_greater_than": deleteAccess, - "tier_to_archive_after_days_since_modification_greater_than": archiveModification, - "tier_to_archive_after_days_since_last_access_time_greater_than": archiveAccess, - "tier_to_cool_after_days_since_modification_greater_than": coolModification, - "tier_to_cool_after_days_since_last_access_time_greater_than": coolAccess, - "enable_auto_tier_to_hot_from_cool": enableAutoCool, + "delete_after_days_since_modification_greater_than": deleteModification, + "tier_to_archive_after_days_since_modification_greater_than": archiveModification, + "tier_to_cool_after_days_since_modification_greater_than": coolModification, }, } } @@ -552,7 +538,7 @@ func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementP return []interface{}{} } - var deleteCreation, archiveCreation, coolCreation float64 + deleteCreation, archiveCreation, coolCreation := float64(-1), float64(-1), float64(-1) if v := snapshot.Delete; v != nil { if v.DaysAfterCreationGreaterThan != nil { deleteCreation = *v.DaysAfterCreationGreaterThan @@ -583,7 +569,7 @@ func flattenStorageManagementPolicyActionsVersion(version *storage.ManagementPol return []interface{}{} } - var deleteCreation, archiveCreation, coolCreation float64 + deleteCreation, archiveCreation, coolCreation := float64(-1), float64(-1), float64(-1) if v := version.Delete; v != nil { if v.DaysAfterCreationGreaterThan != nil { deleteCreation = *v.DaysAfterCreationGreaterThan diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index d955b0e46f60..b4b0c1ec1ab7 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -649,20 +649,12 @@ resource "azurerm_storage_management_policy" "test" { filters { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] - blob_index_match_tag { - name = "tag1" - value = "val1" - } } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10.4 - tier_to_cool_after_days_since_last_access_time_greater_than = 2.45 - tier_to_archive_after_days_since_modification_greater_than = 50.89 - tier_to_archive_after_days_since_last_access_time_greater_than = 78.33 - delete_after_days_since_modification_greater_than = 100.13 - delete_after_days_since_last_access_time_greater_than = 50.78 - enable_auto_tier_to_hot_from_cool = true + tier_to_cool_after_days_since_modification_greater_than = 10.4 + tier_to_archive_after_days_since_modification_greater_than = 50.89 + delete_after_days_since_modification_greater_than = 100.13 } snapshot { delete_after_days_since_creation_greater_than = 30.3 @@ -709,20 +701,13 @@ resource "azurerm_storage_management_policy" "test" { enabled = true filters { prefix_match = ["container2/prefix2"] - blob_types = ["blockBlob", "appendBlob"] - blob_index_match_tag { - name = "tag2" - value = "val2" - } + blob_types = ["blockBlob"] } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 11.4 - tier_to_cool_after_days_since_last_access_time_greater_than = 3.45 - tier_to_archive_after_days_since_modification_greater_than = 51.89 - tier_to_archive_after_days_since_last_access_time_greater_than = 79.33 - delete_after_days_since_modification_greater_than = 101.13 - delete_after_days_since_last_access_time_greater_than = 51.78 + tier_to_cool_after_days_since_modification_greater_than = 11.4 + tier_to_archive_after_days_since_modification_greater_than = 51.89 + delete_after_days_since_modification_greater_than = 101.13 } snapshot { delete_after_days_since_creation_greater_than = 31.3 diff --git a/website/docs/d/storage_management_policy.html.markdown b/website/docs/d/storage_management_policy.html.markdown index 3b270accb395..55a7ec39747c 100644 --- a/website/docs/d/storage_management_policy.html.markdown +++ b/website/docs/d/storage_management_policy.html.markdown @@ -49,13 +49,14 @@ The following arguments are supported: * `prefix_match` - An array of strings for prefixes to be matched. * `blob_types` - An array of predefined values. Valid options are `blockBlob` and `appendBlob`. - +* `blob_index_match_tag` - A `blob_index_match_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. --- `actions` supports the following: * `base_blob` - A `base_blob` block as documented below. * `snapshot` - A `snapshot` block as documented below. +* `version` - A `version` block as documented below. --- @@ -69,7 +70,27 @@ The following arguments are supported: `snapshot` supports the following: -* `delete_after_days_since_creation_greater_than` - The age in days after create to delete the snapshot. +* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. +* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to archive storage. +* `tier_to_cool_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to cool storage. + +--- + +`version` supports the following: + +* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob version. +* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob version to archive storage. +* `tier_to_cool_after_days_since_creation_greater_than` - The age in days creation create to tier blob version to cool storage. + + +--- + +`blob_index_match_tag` supports the following: + +* `name` - The filter tag name used for tag based filtering for blob objects. +* `operation` - The comparison operator which is used for object comparison and filtering. Possible value is `==`. Defaults to `==`. +* `value` - The filter tag value used for tag based filtering for blob objects. + ## Timeouts diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index b46c90fef42f..182b28f4367f 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -63,12 +63,19 @@ resource "azurerm_storage_management_policy" "example" { } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 11 - tier_to_archive_after_days_since_modification_greater_than = 51 - delete_after_days_since_modification_greater_than = 101 + tier_to_cool_after_days_since_modification_greater_than = 10.4 + tier_to_archive_after_days_since_modification_greater_than = 50.89 + delete_after_days_since_modification_greater_than = 100.13 } snapshot { - delete_after_days_since_creation_greater_than = 31 + delete_after_days_since_creation_greater_than = 30.3 + tier_to_archive_after_days_since_creation_greater_than = 90.8 + tier_to_cool_after_days_since_creation_greater_than = 23.8 + } + version { + delete_after_days_since_creation_greater_than = 3.4 + tier_to_archive_after_days_since_creation_greater_than = 9.8 + tier_to_cool_after_days_since_creation_greater_than = 90.3 } } } @@ -106,20 +113,31 @@ The following arguments are supported: * `base_blob` - A `base_blob` block as documented below. * `snapshot` - A `snapshot` block as documented below. +* `version` - A `version` block as documented below. --- `base_blob` supports the following: -* `tier_to_cool_after_days_since_modification_greater_than` - The age in days after last modification to tier blobs to cool storage. Supports blob currently at Hot tier. Must be at least 0. -* `tier_to_archive_after_days_since_modification_greater_than` - The age in days after last modification to tier blobs to archive storage. Supports blob currently at Hot or Cool tier. Must be at least 0. -* `delete_after_days_since_modification_greater_than` - The age in days after last modification to delete the blob. Must be at least 0. +* `tier_to_cool_after_days_since_modification_greater_than` - The age in days after last modification to tier blobs to cool storage. Supports blob currently at Hot tier. Must be between 0 and 99999. +* `tier_to_archive_after_days_since_modification_greater_than` - The age in days after last modification to tier blobs to archive storage. Supports blob currently at Hot or Cool tier. Must be between 0 and 99999. +* `delete_after_days_since_modification_greater_than` - The age in days after last modification to delete the blob. Must be between 0 and 99999. --- `snapshot` supports the following: -* `delete_after_days_since_creation_greater_than` - The age in days after create to delete the snaphot. Must be at least 0. +* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. Must be between 0 and 99999. +* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to archive storage. Must be between 0 and 99999. +* `tier_to_cool_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to cool storage. Must be between 0 and 99999. + +--- + +`version` supports the following: + +* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob version. Must be between 0 and 99999. +* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob version to archive storage. Must be between 0 and 99999. +* `tier_to_cool_after_days_since_creation_greater_than` - The age in days creation create to tier blob version to cool storage. Must be between 0 and 99999. --- From 31afa4fa3615bacfd4e009bcaee07228104981b2 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 31 Mar 2021 10:35:27 +0800 Subject: [PATCH 17/29] lint --- .../storage/storage_management_policy_resource.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 8195c3a665a2..4a94b5806b29 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -481,9 +481,9 @@ func flattenStorageManagementPolicyFilters(filters *storage.ManagementPolicyFilt return []interface{}{ map[string]interface{}{ - "prefix_match": utils.FlattenStringSlice((*filters).PrefixMatch), - "blob_types": utils.FlattenStringSlice((*filters).BlobTypes), - "blob_index_match_tag": flattenAzureRmStorageBlobIndexMatch((*filters).BlobIndexMatch), + "prefix_match": utils.FlattenStringSlice(filters.PrefixMatch), + "blob_types": utils.FlattenStringSlice(filters.BlobTypes), + "blob_index_match_tag": flattenAzureRmStorageBlobIndexMatch(filters.BlobIndexMatch), }, } } @@ -495,9 +495,9 @@ func flattenStorageManagementPolicyActions(actions *storage.ManagementPolicyActi return []interface{}{ map[string]interface{}{ - "base_blob": flattenStorageManagementPolicyActionsBaseBlob((*actions).BaseBlob), - "snapshot": flattenStorageManagementPolicyActionsSnapshot((*actions).Snapshot), - "version": flattenStorageManagementPolicyActionsVersion((*actions).Version), + "base_blob": flattenStorageManagementPolicyActionsBaseBlob(actions.BaseBlob), + "snapshot": flattenStorageManagementPolicyActionsSnapshot(actions.Snapshot), + "version": flattenStorageManagementPolicyActionsVersion(actions.Version), }, } } From de1b5e257aaba82848a4dd63d03ae20686b28fd7 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 7 Apr 2021 13:59:21 +0800 Subject: [PATCH 18/29] update --- .../storage_management_policy_data_source.go | 18 +- .../storage_management_policy_resource.go | 96 +++++----- ...storage_management_policy_resource_test.go | 180 ++++++++++++++++-- .../r/storage_management_policy.html.markdown | 18 +- 4 files changed, 228 insertions(+), 84 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source.go b/azurerm/internal/services/storage/storage_management_policy_data_source.go index b0784f5fce03..bd93c1fb8cba 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source.go @@ -90,15 +90,15 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tier_to_cool_after_days_since_modification_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, "tier_to_archive_after_days_since_modification_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, "delete_after_days_since_modification_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, }, @@ -110,15 +110,15 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, "tier_to_archive_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, "tier_to_cool_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Computed: true, }, @@ -131,15 +131,15 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, "tier_to_archive_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, "tier_to_cool_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Computed: true, }, }, diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 4a94b5806b29..fc9cf17f169a 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -126,22 +126,22 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tier_to_cool_after_days_since_modification_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, }, }, @@ -153,22 +153,22 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_cool_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, }, }, @@ -180,22 +180,22 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "delete_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_cool_after_days_since_creation_greater_than": { - Type: schema.TypeFloat, + Type: schema.TypeInt, Optional: true, Default: -1, - ValidateFunc: validation.FloatBetween(0, 99999), + ValidateFunc: validation.IntBetween(0, 99999), }, }, }, @@ -369,19 +369,19 @@ func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage input := inputs[0].(map[string]interface{}) result := storage.ManagementPolicyBaseBlob{} - if v, ok := input["delete_after_days_since_modification_greater_than"].(float64); ok && v != -1 { + if v, ok := input["delete_after_days_since_modification_greater_than"].(int); ok && v != -1 { result.Delete = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(v), + DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(float64); ok && v != -1 { + if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(int); ok && v != -1 { result.TierToArchive = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(v), + DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(float64); ok && v != -1 { + if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(int); ok && v != -1 { result.TierToCool = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(v), + DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } @@ -396,19 +396,19 @@ func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage result := storage.ManagementPolicySnapShot{} - if v, ok := input["delete_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.Delete = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(v), + DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.TierToArchive = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(v), + DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.TierToCool = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(v), + DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } @@ -423,19 +423,19 @@ func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage. result := storage.ManagementPolicyVersion{} - if v, ok := input["delete_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.Delete = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(v), + DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.TierToArchive = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(v), + DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(float64); ok && v != -1 { + if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.TierToCool = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(v), + DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } @@ -507,20 +507,20 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP return []interface{}{} } - deleteModification, archiveModification, coolModification := float64(-1), float64(-1), float64(-1) + deleteModification, archiveModification, coolModification := -1, -1, -1 if v := baseBlob.Delete; v != nil { if v.DaysAfterModificationGreaterThan != nil { - deleteModification = *v.DaysAfterModificationGreaterThan + deleteModification = int(*v.DaysAfterModificationGreaterThan) } } if v := baseBlob.TierToArchive; v != nil { if v.DaysAfterModificationGreaterThan != nil { - archiveModification = *v.DaysAfterModificationGreaterThan + archiveModification = int(*v.DaysAfterModificationGreaterThan) } } if v := baseBlob.TierToCool; v != nil { if v.DaysAfterModificationGreaterThan != nil { - coolModification = *v.DaysAfterModificationGreaterThan + coolModification = int(*v.DaysAfterModificationGreaterThan) } } @@ -538,20 +538,20 @@ func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementP return []interface{}{} } - deleteCreation, archiveCreation, coolCreation := float64(-1), float64(-1), float64(-1) + deleteCreation, archiveCreation, coolCreation := -1, -1, -1 if v := snapshot.Delete; v != nil { if v.DaysAfterCreationGreaterThan != nil { - deleteCreation = *v.DaysAfterCreationGreaterThan + deleteCreation = int(*v.DaysAfterCreationGreaterThan) } } if v := snapshot.TierToArchive; v != nil { if v.DaysAfterCreationGreaterThan != nil { - archiveCreation = *v.DaysAfterCreationGreaterThan + archiveCreation = int(*v.DaysAfterCreationGreaterThan) } } if v := snapshot.TierToCool; v != nil { if v.DaysAfterCreationGreaterThan != nil { - coolCreation = *v.DaysAfterCreationGreaterThan + coolCreation = int(*v.DaysAfterCreationGreaterThan) } } @@ -569,20 +569,20 @@ func flattenStorageManagementPolicyActionsVersion(version *storage.ManagementPol return []interface{}{} } - deleteCreation, archiveCreation, coolCreation := float64(-1), float64(-1), float64(-1) + deleteCreation, archiveCreation, coolCreation := -1, -1, -1 if v := version.Delete; v != nil { if v.DaysAfterCreationGreaterThan != nil { - deleteCreation = *v.DaysAfterCreationGreaterThan + deleteCreation = int(*v.DaysAfterCreationGreaterThan) } } if v := version.TierToArchive; v != nil { if v.DaysAfterCreationGreaterThan != nil { - archiveCreation = *v.DaysAfterCreationGreaterThan + archiveCreation = int(*v.DaysAfterCreationGreaterThan) } } if v := version.TierToCool; v != nil { if v.DaysAfterCreationGreaterThan != nil { - coolCreation = *v.DaysAfterCreationGreaterThan + coolCreation = int(*v.DaysAfterCreationGreaterThan) } } diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index b4b0c1ec1ab7..5ddbb72fcb64 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -25,6 +25,19 @@ func TestAccStorageManagementPolicy_basic(t *testing.T) { Config: r.basic(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -40,6 +53,17 @@ func TestAccStorageManagementPolicy_singleAction(t *testing.T) { Config: r.singleAction(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.name").HasValue("singleActionRule"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -55,6 +79,17 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { Config: r.singleAction(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.name").HasValue("singleActionRule"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -62,6 +97,17 @@ func TestAccStorageManagementPolicy_singleActionUpdate(t *testing.T) { Config: r.singleActionUpdate(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.name").HasValue("singleActionRule"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("30"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -77,6 +123,35 @@ func TestAccStorageManagementPolicy_multipleRule(t *testing.T) { Config: r.multipleRule(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("2"), + + // Rule1 + check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), + + // Rule2 + check.That(data.ResourceName).Key("rule.1.name").HasValue("rule2"), + check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), + check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), + check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("51"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("101"), + check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("31"), ), }, data.ImportStep(), @@ -92,6 +167,35 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { Config: r.multipleRule(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("2"), + + // Rule1 + check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), + + // Rule2 + check.That(data.ResourceName).Key("rule.1.name").HasValue("rule2"), + check.That(data.ResourceName).Key("rule.1.enabled").HasValue("false"), + check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), + check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("11"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("51"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("101"), + check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("31"), ), }, data.ImportStep(), @@ -99,6 +203,35 @@ func TestAccStorageManagementPolicy_updateMultipleRule(t *testing.T) { Config: r.multipleRuleUpdated(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("2"), + + // Rule1 + check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("10"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("50"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), + + // Rule2 + check.That(data.ResourceName).Key("rule.1.name").HasValue("rule2"), + check.That(data.ResourceName).Key("rule.1.enabled").HasValue("true"), // check updated + check.That(data.ResourceName).Key("rule.1.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.filters.0.prefix_match.#").HasValue("2"), + check.That(data.ResourceName).Key("rule.1.filters.0.blob_types.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than").HasValue("12"), // check updated + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than").HasValue("52"), // check updated + check.That(data.ResourceName).Key("rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("102"), // check updated + check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("32"), // check updated ), }, data.ImportStep(), @@ -114,6 +247,17 @@ func TestAccStorageManagementPolicy_blobTypes(t *testing.T) { Config: r.blobTypes(data), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.name").HasValue("rule1"), + check.That(data.ResourceName).Key("rule.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("rule.0.filters.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.prefix_match.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.filters.0.blob_types.#").HasValue("2"), + check.That(data.ResourceName).Key("rule.0.actions.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than").HasValue("100"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than").HasValue("30"), ), }, data.ImportStep(), @@ -652,19 +796,19 @@ resource "azurerm_storage_management_policy" "test" { } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10.4 - tier_to_archive_after_days_since_modification_greater_than = 50.89 - delete_after_days_since_modification_greater_than = 100.13 + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 } snapshot { - delete_after_days_since_creation_greater_than = 30.3 - tier_to_archive_after_days_since_creation_greater_than = 90.8 - tier_to_cool_after_days_since_creation_greater_than = 23.8 + delete_after_days_since_creation_greater_than = 30 + tier_to_archive_after_days_since_creation_greater_than = 90 + tier_to_cool_after_days_since_creation_greater_than = 23 } version { - delete_after_days_since_creation_greater_than = 3.4 - tier_to_archive_after_days_since_creation_greater_than = 9.8 - tier_to_cool_after_days_since_creation_greater_than = 90.3 + delete_after_days_since_creation_greater_than = 3 + tier_to_archive_after_days_since_creation_greater_than = 9 + tier_to_cool_after_days_since_creation_greater_than = 90 } } } @@ -705,19 +849,19 @@ resource "azurerm_storage_management_policy" "test" { } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 11.4 - tier_to_archive_after_days_since_modification_greater_than = 51.89 - delete_after_days_since_modification_greater_than = 101.13 + tier_to_cool_after_days_since_modification_greater_than = 11 + tier_to_archive_after_days_since_modification_greater_than = 51 + delete_after_days_since_modification_greater_than = 101 } snapshot { - delete_after_days_since_creation_greater_than = 31.3 - tier_to_archive_after_days_since_creation_greater_than = 91.8 - tier_to_cool_after_days_since_creation_greater_than = 24.8 + delete_after_days_since_creation_greater_than = 31 + tier_to_archive_after_days_since_creation_greater_than = 91 + tier_to_cool_after_days_since_creation_greater_than = 24 } version { - delete_after_days_since_creation_greater_than = 4.4 - tier_to_archive_after_days_since_creation_greater_than = 10.8 - tier_to_cool_after_days_since_creation_greater_than = 91.3 + delete_after_days_since_creation_greater_than = 4 + tier_to_archive_after_days_since_creation_greater_than = 10 + tier_to_cool_after_days_since_creation_greater_than = 91 } } } diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index 182b28f4367f..31de3c8f4d02 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -63,19 +63,19 @@ resource "azurerm_storage_management_policy" "example" { } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10.4 - tier_to_archive_after_days_since_modification_greater_than = 50.89 - delete_after_days_since_modification_greater_than = 100.13 + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 } snapshot { - delete_after_days_since_creation_greater_than = 30.3 - tier_to_archive_after_days_since_creation_greater_than = 90.8 - tier_to_cool_after_days_since_creation_greater_than = 23.8 + delete_after_days_since_creation_greater_than = 30 + tier_to_archive_after_days_since_creation_greater_than = 90 + tier_to_cool_after_days_since_creation_greater_than = 23 } version { - delete_after_days_since_creation_greater_than = 3.4 - tier_to_archive_after_days_since_creation_greater_than = 9.8 - tier_to_cool_after_days_since_creation_greater_than = 90.3 + delete_after_days_since_creation_greater_than = 3 + tier_to_archive_after_days_since_creation_greater_than = 9 + tier_to_cool_after_days_since_creation_greater_than = 90 } } } From e335244fd644dce257109ca50bb6899de91c9998 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 7 Apr 2021 14:13:22 +0800 Subject: [PATCH 19/29] update --- website/docs/r/storage_management_policy.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index 31de3c8f4d02..d4d5b53c73bf 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -63,12 +63,12 @@ resource "azurerm_storage_management_policy" "example" { } actions { base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10 - tier_to_archive_after_days_since_modification_greater_than = 50 - delete_after_days_since_modification_greater_than = 100 + tier_to_cool_after_days_since_modification_greater_than = 11 + tier_to_archive_after_days_since_modification_greater_than = 51 + delete_after_days_since_modification_greater_than = 101 } snapshot { - delete_after_days_since_creation_greater_than = 30 + delete_after_days_since_creation_greater_than = 31 tier_to_archive_after_days_since_creation_greater_than = 90 tier_to_cool_after_days_since_creation_greater_than = 23 } From b5e613721971999fb4fce3ec02aef613830877f6 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 10:05:16 +0800 Subject: [PATCH 20/29] update --- .../storage_management_policy_data_source.go | 16 ++--- .../storage_management_policy_resource.go | 61 +++++++++---------- ...storage_management_policy_resource_test.go | 28 ++++----- .../d/storage_management_policy.html.markdown | 14 ++--- .../r/storage_management_policy.html.markdown | 30 ++++----- 5 files changed, 74 insertions(+), 75 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_data_source.go b/azurerm/internal/services/storage/storage_management_policy_data_source.go index bd93c1fb8cba..ee93f5096705 100644 --- a/azurerm/internal/services/storage/storage_management_policy_data_source.go +++ b/azurerm/internal/services/storage/storage_management_policy_data_source.go @@ -54,7 +54,7 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Set: schema.HashString, }, - "blob_index_match_tag": { + "match_blob_index_tag": { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ @@ -109,17 +109,17 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "delete_after_days_since_creation_greater_than": { + "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Computed: true, }, - "tier_to_archive_after_days_since_creation_greater_than": { + "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, + Optional: true, Computed: true, }, - "tier_to_cool_after_days_since_creation_greater_than": { + "delete_after_days_since_creation_greater_than": { Type: schema.TypeInt, - Optional: true, Computed: true, }, }, @@ -130,15 +130,15 @@ func dataSourceStorageManagementPolicy() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "delete_after_days_since_creation_greater_than": { + "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Computed: true, }, - "tier_to_archive_after_days_since_creation_greater_than": { + "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Computed: true, }, - "tier_to_cool_after_days_since_creation_greater_than": { + "delete_after_days_since_creation": { Type: schema.TypeInt, Computed: true, }, diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index fc9cf17f169a..aad202e9122b 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -82,7 +82,7 @@ func resourceStorageManagementPolicy() *schema.Resource { Set: schema.HashString, }, - "blob_index_match_tag": { + "match_blob_index_tag": { Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ @@ -128,19 +128,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "tier_to_cool_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -152,22 +152,21 @@ func resourceStorageManagementPolicy() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "delete_after_days_since_creation_greater_than": { + "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Optional: true, Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, - "tier_to_archive_after_days_since_creation_greater_than": { + "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Optional: true, Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, - "tier_to_cool_after_days_since_creation_greater_than": { + "delete_after_days_since_creation_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -179,19 +178,19 @@ func resourceStorageManagementPolicy() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "delete_after_days_since_creation_greater_than": { + "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Optional: true, Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, - "tier_to_archive_after_days_since_creation_greater_than": { + "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Optional: true, Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, - "tier_to_cool_after_days_since_creation_greater_than": { + "delete_after_days_since_creation": { Type: schema.TypeInt, Optional: true, Default: -1, @@ -329,7 +328,7 @@ func expandStorageManagementPolicyRules(inputs []interface{}) (*[]storage.Manage }, } if (rule.Definition.Actions.Version != nil || rule.Definition.Actions.Snapshot != nil) && rule.Definition.Filters.BlobIndexMatch != nil { - return nil, fmt.Errorf("`blob_index_match_tag` is not supported as a filter for versions and snapshots") + return nil, fmt.Errorf("`match_blob_index_tag` is not supported as a filter for versions and snapshots") } result = append(result, rule) } @@ -345,7 +344,7 @@ func expandStorageManagementPolicyFilters(inputs []interface{}) *storage.Managem return &storage.ManagementPolicyFilter{ PrefixMatch: utils.ExpandStringSlice(input["prefix_match"].(*schema.Set).List()), BlobTypes: utils.ExpandStringSlice(input["blob_types"].(*schema.Set).List()), - BlobIndexMatch: expandAzureRmStorageBlobIndexMatch(input["blob_index_match_tag"].(*schema.Set).List()), + BlobIndexMatch: expandAzureRmStorageBlobIndexMatch(input["match_blob_index_tag"].(*schema.Set).List()), } } @@ -369,17 +368,17 @@ func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage input := inputs[0].(map[string]interface{}) result := storage.ManagementPolicyBaseBlob{} - if v, ok := input["delete_after_days_since_modification_greater_than"].(int); ok && v != -1 { + if v, ok := input["delete_after_days_since_modification_greater_than"].(int); ok { result.Delete = &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(int); ok && v != -1 { + if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(int); ok { result.TierToArchive = &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(int); ok && v != -1 { + if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(int); ok { result.TierToCool = &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(float64(v)), } @@ -396,17 +395,17 @@ func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage result := storage.ManagementPolicySnapShot{} - if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok && v != -1 { + if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok { result.Delete = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(int); ok && v != -1 { + if v, ok := input["change_tier_to_archive_after_days_since_creation"].(int); ok && v != -1 { result.TierToArchive = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(int); ok && v != -1 { + if v, ok := input["change_tier_to_cool_after_days_since_creation"].(int); ok && v != -1 { result.TierToCool = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } @@ -423,17 +422,17 @@ func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage. result := storage.ManagementPolicyVersion{} - if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok && v != -1 { + if v, ok := input["delete_after_days_since_creation"].(int); ok && v != -1 { result.Delete = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_creation_greater_than"].(int); ok && v != -1 { + if v, ok := input["change_tier_to_archive_after_days_since_creation"].(int); ok && v != -1 { result.TierToArchive = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_creation_greater_than"].(int); ok && v != -1 { + if v, ok := input["change_tier_to_cool_after_days_since_creation"].(int); ok && v != -1 { result.TierToCool = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } @@ -483,7 +482,7 @@ func flattenStorageManagementPolicyFilters(filters *storage.ManagementPolicyFilt map[string]interface{}{ "prefix_match": utils.FlattenStringSlice(filters.PrefixMatch), "blob_types": utils.FlattenStringSlice(filters.BlobTypes), - "blob_index_match_tag": flattenAzureRmStorageBlobIndexMatch(filters.BlobIndexMatch), + "match_blob_index_tag": flattenAzureRmStorageBlobIndexMatch(filters.BlobIndexMatch), }, } } @@ -507,7 +506,7 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP return []interface{}{} } - deleteModification, archiveModification, coolModification := -1, -1, -1 + deleteModification, archiveModification, coolModification := 0, 0, 0 if v := baseBlob.Delete; v != nil { if v.DaysAfterModificationGreaterThan != nil { deleteModification = int(*v.DaysAfterModificationGreaterThan) @@ -538,7 +537,7 @@ func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementP return []interface{}{} } - deleteCreation, archiveCreation, coolCreation := -1, -1, -1 + deleteCreation, archiveCreation, coolCreation := 0, -1, -1 if v := snapshot.Delete; v != nil { if v.DaysAfterCreationGreaterThan != nil { deleteCreation = int(*v.DaysAfterCreationGreaterThan) @@ -557,9 +556,9 @@ func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementP return []interface{}{ map[string]interface{}{ - "delete_after_days_since_creation_greater_than": deleteCreation, - "tier_to_archive_after_days_since_creation_greater_than": archiveCreation, - "tier_to_cool_after_days_since_creation_greater_than": coolCreation, + "change_tier_to_archive_after_days_since_creation": archiveCreation, + "change_tier_to_cool_after_days_since_creation": coolCreation, + "delete_after_days_since_creation_greater_than": deleteCreation, }, } } @@ -588,9 +587,9 @@ func flattenStorageManagementPolicyActionsVersion(version *storage.ManagementPol return []interface{}{ map[string]interface{}{ - "delete_after_days_since_creation_greater_than": deleteCreation, - "tier_to_archive_after_days_since_creation_greater_than": archiveCreation, - "tier_to_cool_after_days_since_creation_greater_than": coolCreation, + "change_tier_to_archive_after_days_since_creation": archiveCreation, + "change_tier_to_cool_after_days_since_creation": coolCreation, + "delete_after_days_since_creation": deleteCreation, }, } } diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 5ddbb72fcb64..5f6a9ed67dba 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -710,12 +710,12 @@ resource "azurerm_storage_management_policy" "test" { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] - blob_index_match_tag { + match_blob_index_tag { name = "tag1" value = "val1" } - blob_index_match_tag { + match_blob_index_tag { name = "tag2" operation = "==" value = "val2" @@ -801,14 +801,14 @@ resource "azurerm_storage_management_policy" "test" { delete_after_days_since_modification_greater_than = 100 } snapshot { - delete_after_days_since_creation_greater_than = 30 - tier_to_archive_after_days_since_creation_greater_than = 90 - tier_to_cool_after_days_since_creation_greater_than = 23 + change_tier_to_archive_after_days_since_creation = 90 + change_tier_to_cool_after_days_since_creation = 23 + delete_after_days_since_creation_greater_than = 30 } version { - delete_after_days_since_creation_greater_than = 3 - tier_to_archive_after_days_since_creation_greater_than = 9 - tier_to_cool_after_days_since_creation_greater_than = 90 + change_tier_to_archive_after_days_since_creation = 9 + change_tier_to_cool_after_days_since_creation = 90 + delete_after_days_since_creation = 3 } } } @@ -854,14 +854,14 @@ resource "azurerm_storage_management_policy" "test" { delete_after_days_since_modification_greater_than = 101 } snapshot { - delete_after_days_since_creation_greater_than = 31 - tier_to_archive_after_days_since_creation_greater_than = 91 - tier_to_cool_after_days_since_creation_greater_than = 24 + change_tier_to_archive_after_days_since_creation = 91 + change_tier_to_cool_after_days_since_creation = 24 + delete_after_days_since_creation_greater_than = 31 } version { - delete_after_days_since_creation_greater_than = 4 - tier_to_archive_after_days_since_creation_greater_than = 10 - tier_to_cool_after_days_since_creation_greater_than = 91 + change_tier_to_archive_after_days_since_creation = 10 + change_tier_to_cool_after_days_since_creation = 91 + delete_after_days_since_creation = 4 } } } diff --git a/website/docs/d/storage_management_policy.html.markdown b/website/docs/d/storage_management_policy.html.markdown index 55a7ec39747c..127b79028158 100644 --- a/website/docs/d/storage_management_policy.html.markdown +++ b/website/docs/d/storage_management_policy.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: * `prefix_match` - An array of strings for prefixes to be matched. * `blob_types` - An array of predefined values. Valid options are `blockBlob` and `appendBlob`. -* `blob_index_match_tag` - A `blob_index_match_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. +* `match_blob_index_tag` - A `match_blob_index_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. --- `actions` supports the following: @@ -71,21 +71,21 @@ The following arguments are supported: `snapshot` supports the following: * `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. -* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to archive storage. -* `tier_to_cool_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to cool storage. +* `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob snapshot to archive storage. +* `change_tier_to_cool_after_days_since_creation` - The age in days after creation to tier blob snapshot to cool storage. --- `version` supports the following: -* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob version. -* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob version to archive storage. -* `tier_to_cool_after_days_since_creation_greater_than` - The age in days creation create to tier blob version to cool storage. +* `delete_after_days_since_creation` - The age in days after creation to delete the blob version. +* `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob version to archive storage. +* `change_tier_to_cool_after_days_since_creation` - The age in days creation create to tier blob version to cool storage. --- -`blob_index_match_tag` supports the following: +`match_blob_index_tag` supports the following: * `name` - The filter tag name used for tag based filtering for blob objects. * `operation` - The comparison operator which is used for object comparison and filtering. Possible value is `==`. Defaults to `==`. diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index d4d5b53c73bf..0db7c99df70f 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -37,7 +37,7 @@ resource "azurerm_storage_management_policy" "example" { filters { prefix_match = ["container1/prefix1"] blob_types = ["blockBlob"] - blob_index_match_tag { + match_blob_index_tag { name = "tag1" operation = "==" value = "val1" @@ -68,14 +68,14 @@ resource "azurerm_storage_management_policy" "example" { delete_after_days_since_modification_greater_than = 101 } snapshot { - delete_after_days_since_creation_greater_than = 31 - tier_to_archive_after_days_since_creation_greater_than = 90 - tier_to_cool_after_days_since_creation_greater_than = 23 + change_tier_to_archive_after_days_since_creation = 90 + change_tier_to_cool_after_days_since_creation = 23 + delete_after_days_since_creation_greater_than = 31 } version { - delete_after_days_since_creation_greater_than = 3 - tier_to_archive_after_days_since_creation_greater_than = 9 - tier_to_cool_after_days_since_creation_greater_than = 90 + change_tier_to_archive_after_days_since_creation = 9 + change_tier_to_cool_after_days_since_creation = 90 + delete_after_days_since_creation = 3 } } } @@ -105,8 +105,8 @@ The following arguments are supported: * `prefix_match` - An array of strings for prefixes to be matched. * `blob_types` - An array of predefined values. Valid options are `blockBlob` and `appendBlob`. -* `blob_index_match_tag` - A `blob_index_match_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. -~> **NOTE:** This property requires enabling the `blobIndex` feature with [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/) before setting the block `blob_index_match_tag`. +* `match_blob_index_tag` - A `match_blob_index_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. +~> **NOTE:** This property requires enabling the `blobIndex` feature with [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/) before setting the block `match_blob_index_tag`. --- `actions` supports the following: @@ -127,21 +127,21 @@ The following arguments are supported: `snapshot` supports the following: +* `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob snapshot to archive storage. Must be between 0 and 99999. +* `change_tier_to_cool_after_days_since_creation` - The age in days after creation to tier blob snapshot to cool storage. Must be between 0 and 99999. * `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. Must be between 0 and 99999. -* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to archive storage. Must be between 0 and 99999. -* `tier_to_cool_after_days_since_creation_greater_than` - The age in days after creation to tier blob snapshot to cool storage. Must be between 0 and 99999. --- `version` supports the following: -* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob version. Must be between 0 and 99999. -* `tier_to_archive_after_days_since_creation_greater_than` - The age in days after creation to tier blob version to archive storage. Must be between 0 and 99999. -* `tier_to_cool_after_days_since_creation_greater_than` - The age in days creation create to tier blob version to cool storage. Must be between 0 and 99999. +* `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob version to archive storage. Must be between 0 and 99999. +* `change_tier_to_cool_after_days_since_creation` - The age in days creation create to tier blob version to cool storage. Must be between 0 and 99999. +* `delete_after_days_since_creation` - The age in days after creation to delete the blob version. Must be between 0 and 99999. --- -`blob_index_match_tag` supports the following: +`match_blob_index_tag` supports the following: * `name` - The filter tag name used for tag based filtering for blob objects. * `operation` - The comparison operator which is used for object comparison and filtering. Possible value is `==`. Defaults to `==`. From a6b5ca6b28a1603bf30d2df5d04e36e16648c6ac Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 11:16:15 +0800 Subject: [PATCH 21/29] update --- .../storage_management_policy_resource.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index aad202e9122b..ce1b03c87bb5 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -128,19 +128,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "tier_to_cool_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -368,17 +368,17 @@ func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage input := inputs[0].(map[string]interface{}) result := storage.ManagementPolicyBaseBlob{} - if v, ok := input["delete_after_days_since_modification_greater_than"].(int); ok { + if v, ok := input["delete_after_days_since_modification_greater_than"].(int); ok && v != -1 { result.Delete = &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(int); ok { + if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(int); ok && v != -1 { result.TierToArchive = &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(int); ok { + if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(int); ok && v != -1 { result.TierToCool = &storage.DateAfterModification{ DaysAfterModificationGreaterThan: utils.Float(float64(v)), } @@ -395,7 +395,7 @@ func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage result := storage.ManagementPolicySnapShot{} - if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok { + if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok && v != -1 { result.Delete = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v)), } @@ -506,7 +506,7 @@ func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementP return []interface{}{} } - deleteModification, archiveModification, coolModification := 0, 0, 0 + deleteModification, archiveModification, coolModification := -1, -1, -1 if v := baseBlob.Delete; v != nil { if v.DaysAfterModificationGreaterThan != nil { deleteModification = int(*v.DaysAfterModificationGreaterThan) @@ -537,7 +537,7 @@ func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementP return []interface{}{} } - deleteCreation, archiveCreation, coolCreation := 0, -1, -1 + deleteCreation, archiveCreation, coolCreation := -1, -1, -1 if v := snapshot.Delete; v != nil { if v.DaysAfterCreationGreaterThan != nil { deleteCreation = int(*v.DaysAfterCreationGreaterThan) From 2682518b5fe6b23820a55b8ec6e0267fc1e716ba Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 11:20:54 +0800 Subject: [PATCH 22/29] update --- .../storage/storage_management_policy_resource.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index ce1b03c87bb5..adc4cadb3583 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -317,6 +317,9 @@ func expandStorageManagementPolicyRules(inputs []interface{}) (*[]storage.Manage } for _, input := range inputs { + if input == nil { + continue + } v := input.(map[string]interface{}) rule := storage.ManagementPolicyRule{ Name: utils.String(v["name"].(string)), @@ -336,7 +339,7 @@ func expandStorageManagementPolicyRules(inputs []interface{}) (*[]storage.Manage } func expandStorageManagementPolicyFilters(inputs []interface{}) *storage.ManagementPolicyFilter { - if len(inputs) == 0 { + if len(inputs) == 0 || inputs[0] == nil { return nil } input := inputs[0].(map[string]interface{}) @@ -349,7 +352,7 @@ func expandStorageManagementPolicyFilters(inputs []interface{}) *storage.Managem } func expandStorageManagementPolicyActions(inputs []interface{}) *storage.ManagementPolicyAction { - if len(inputs) == 0 { + if len(inputs) == 0 || inputs[0] == nil { return nil } input := inputs[0].(map[string]interface{}) @@ -362,7 +365,7 @@ func expandStorageManagementPolicyActions(inputs []interface{}) *storage.Managem } func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage.ManagementPolicyBaseBlob { - if len(inputs) == 0 { + if len(inputs) == 0 || inputs[0] == nil { return nil } input := inputs[0].(map[string]interface{}) @@ -388,7 +391,7 @@ func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage } func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage.ManagementPolicySnapShot { - if len(inputs) == 0 { + if len(inputs) == 0 || inputs[0] == nil { return nil } input := inputs[0].(map[string]interface{}) @@ -415,7 +418,7 @@ func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage } func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage.ManagementPolicyVersion { - if len(inputs) == 0 { + if len(inputs) == 0 || inputs[0] == nil { return nil } input := inputs[0].(map[string]interface{}) From 37ca9b7c804a70f7c77650e7ab23074f01179596 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 11:24:00 +0800 Subject: [PATCH 23/29] update --- .../services/storage/storage_management_policy_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index adc4cadb3583..007814cd39b3 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -330,7 +330,7 @@ func expandStorageManagementPolicyRules(inputs []interface{}) (*[]storage.Manage Filters: expandStorageManagementPolicyFilters(v["filters"].([]interface{})), }, } - if (rule.Definition.Actions.Version != nil || rule.Definition.Actions.Snapshot != nil) && rule.Definition.Filters.BlobIndexMatch != nil { + if rule.Definition.Actions != nil && rule.Definition.Filters != nil && (rule.Definition.Actions.Version != nil || rule.Definition.Actions.Snapshot != nil) && rule.Definition.Filters.BlobIndexMatch != nil { return nil, fmt.Errorf("`match_blob_index_tag` is not supported as a filter for versions and snapshots") } result = append(result, rule) From 152c668d40adf9a6ee45738172378771cc2f31eb Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 15:01:08 +0800 Subject: [PATCH 24/29] update --- .../storage_management_policy_resource.go | 488 ++++++++---------- 1 file changed, 220 insertions(+), 268 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 007814cd39b3..15ee96dc5bfa 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -128,19 +128,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "tier_to_cool_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -155,13 +155,13 @@ func resourceStorageManagementPolicy() *schema.Resource { "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_creation_greater_than": { @@ -181,19 +181,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: -1, + Default: nil, ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -225,17 +225,18 @@ func resourceStorageManagementPolicyCreateOrUpdate(d *schema.ResourceData, meta name := "default" // The name of the Storage Account Management Policy. It should always be 'default' (from https://docs.microsoft.com/en-us/rest/api/storagerp/managementpolicies/createorupdate) - rules, err := expandStorageManagementPolicyRules(d.Get("rule").([]interface{})) + parameters := storage.ManagementPolicy{ + Name: &name, + } + + armRules, err := expandStorageManagementPolicyRules(d) if err != nil { - return err + return fmt.Errorf("Error expanding Azure Storage Management Policy Rules %q: %+v", storageAccountId, err) } - parameters := storage.ManagementPolicy{ - Name: &name, - ManagementPolicyProperties: &storage.ManagementPolicyProperties{ - Policy: &storage.ManagementPolicySchema{ - Rules: rules, - }, + parameters.ManagementPolicyProperties = &storage.ManagementPolicyProperties{ + Policy: &storage.ManagementPolicySchema{ + Rules: armRules, }, } @@ -310,291 +311,242 @@ func resourceStorageManagementPolicyDelete(d *schema.ResourceData, meta interfac } // nolint unparam -func expandStorageManagementPolicyRules(inputs []interface{}) (*[]storage.ManagementPolicyRule, error) { - result := make([]storage.ManagementPolicyRule, 0) - if len(inputs) == 0 { - return &result, nil - } - - for _, input := range inputs { - if input == nil { - continue - } - v := input.(map[string]interface{}) - rule := storage.ManagementPolicyRule{ - Name: utils.String(v["name"].(string)), - Enabled: utils.Bool(v["enabled"].(bool)), - Type: utils.String("Lifecycle"), - Definition: &storage.ManagementPolicyDefinition{ - Actions: expandStorageManagementPolicyActions(v["actions"].([]interface{})), - Filters: expandStorageManagementPolicyFilters(v["filters"].([]interface{})), - }, - } - if rule.Definition.Actions != nil && rule.Definition.Filters != nil && (rule.Definition.Actions.Version != nil || rule.Definition.Actions.Snapshot != nil) && rule.Definition.Filters.BlobIndexMatch != nil { - return nil, fmt.Errorf("`match_blob_index_tag` is not supported as a filter for versions and snapshots") +func expandStorageManagementPolicyRules(d *schema.ResourceData) (*[]storage.ManagementPolicyRule, error) { + var result []storage.ManagementPolicyRule + + rules := d.Get("rule").([]interface{}) + + for k, v := range rules { + if v != nil { + rule := expandStorageManagementPolicyRule(d, k) + _, blobIndexExist := d.GetOk(fmt.Sprintf("rule.%d.filters.0.match_blob_index_tag", k)) + _, snapshotExist := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot", k)) + _, versionExist := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version", k)) + if blobIndexExist && snapshotExist && versionExist { + return nil, fmt.Errorf("`match_blob_index_tag` is not supported as a filter for versions and snapshots") + } + result = append(result, rule) } - result = append(result, rule) } return &result, nil } -func expandStorageManagementPolicyFilters(inputs []interface{}) *storage.ManagementPolicyFilter { - if len(inputs) == 0 || inputs[0] == nil { - return nil - } - input := inputs[0].(map[string]interface{}) - - return &storage.ManagementPolicyFilter{ - PrefixMatch: utils.ExpandStringSlice(input["prefix_match"].(*schema.Set).List()), - BlobTypes: utils.ExpandStringSlice(input["blob_types"].(*schema.Set).List()), - BlobIndexMatch: expandAzureRmStorageBlobIndexMatch(input["match_blob_index_tag"].(*schema.Set).List()), - } -} - -func expandStorageManagementPolicyActions(inputs []interface{}) *storage.ManagementPolicyAction { - if len(inputs) == 0 || inputs[0] == nil { - return nil - } - input := inputs[0].(map[string]interface{}) - - return &storage.ManagementPolicyAction{ - BaseBlob: expandStorageManagementPolicyActionsBaseBlob(input["base_blob"].([]interface{})), - Snapshot: expandStorageManagementPolicyActionsSnapshot(input["snapshot"].([]interface{})), - Version: expandStorageManagementPolicyActionsVersion(input["version"].([]interface{})), - } -} +func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) storage.ManagementPolicyRule { + name := d.Get(fmt.Sprintf("rule.%d.name", ruleIndex)).(string) + enabled := d.Get(fmt.Sprintf("rule.%d.enabled", ruleIndex)).(bool) + typeVal := "Lifecycle" + + definition := storage.ManagementPolicyDefinition{ + Filters: &storage.ManagementPolicyFilter{}, + Actions: &storage.ManagementPolicyAction{}, + } + filtersRef := d.Get(fmt.Sprintf("rule.%d.filters", ruleIndex)).([]interface{}) + if len(filtersRef) == 1 { + if filtersRef[0] != nil { + filterRef := filtersRef[0].(map[string]interface{}) + + prefixMatches := []string{} + prefixMatchesRef := filterRef["prefix_match"].(*schema.Set) + if prefixMatchesRef != nil { + for _, prefixMatchRef := range prefixMatchesRef.List() { + prefixMatches = append(prefixMatches, prefixMatchRef.(string)) + } + } + definition.Filters.PrefixMatch = &prefixMatches + + blobTypes := []string{} + blobTypesRef := filterRef["blob_types"].(*schema.Set) + if blobTypesRef != nil { + for _, blobTypeRef := range blobTypesRef.List() { + blobTypes = append(blobTypes, blobTypeRef.(string)) + } + } + definition.Filters.BlobTypes = &blobTypes -func expandStorageManagementPolicyActionsBaseBlob(inputs []interface{}) *storage.ManagementPolicyBaseBlob { - if len(inputs) == 0 || inputs[0] == nil { - return nil - } - input := inputs[0].(map[string]interface{}) - result := storage.ManagementPolicyBaseBlob{} + definition.Filters.BlobIndexMatch = expandAzureRmStorageBlobIndexMatch(filterRef["match_blob_index_tag"].(*schema.Set).List()) - if v, ok := input["delete_after_days_since_modification_greater_than"].(int); ok && v != -1 { - result.Delete = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(float64(v)), - } - } - if v, ok := input["tier_to_archive_after_days_since_modification_greater_than"].(int); ok && v != -1 { - result.TierToArchive = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(float64(v)), } } - if v, ok := input["tier_to_cool_after_days_since_modification_greater_than"].(int); ok && v != -1 { - result.TierToCool = &storage.DateAfterModification{ - DaysAfterModificationGreaterThan: utils.Float(float64(v)), + if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions", ruleIndex)); ok { + if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob", ruleIndex)); ok { + baseBlob := &storage.ManagementPolicyBaseBlob{} + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", ruleIndex)); ok { + if v != nil { + baseBlob.TierToCool = &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(float64(v.(int))), + } + } + } + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", ruleIndex)); ok { + if v != nil { + baseBlob.TierToArchive = &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(float64(v.(int))), + } + } + } + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", ruleIndex)); ok { + if v != nil { + baseBlob.Delete = &storage.DateAfterModification{ + DaysAfterModificationGreaterThan: utils.Float(float64(v.(int))), + } + } + } + definition.Actions.BaseBlob = baseBlob } - } - - return &result -} -func expandStorageManagementPolicyActionsSnapshot(inputs []interface{}) *storage.ManagementPolicySnapShot { - if len(inputs) == 0 || inputs[0] == nil { - return nil - } - input := inputs[0].(map[string]interface{}) - - result := storage.ManagementPolicySnapShot{} - - if v, ok := input["delete_after_days_since_creation_greater_than"].(int); ok && v != -1 { - result.Delete = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(float64(v)), - } - } - if v, ok := input["change_tier_to_archive_after_days_since_creation"].(int); ok && v != -1 { - result.TierToArchive = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(float64(v)), - } - } - if v, ok := input["change_tier_to_cool_after_days_since_creation"].(int); ok && v != -1 { - result.TierToCool = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(float64(v)), + if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot", ruleIndex)); ok { + snapshot := &storage.ManagementPolicySnapShot{} + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", ruleIndex)); ok { + v2 := float64(v.(int)) + snapshot.Delete = &storage.DateAfterCreation{DaysAfterCreationGreaterThan: &v2} + } + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot.0.change_tier_to_archive_after_days_since_creation", ruleIndex)); ok { + snapshot.TierToArchive = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), + } + } + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot.0.change_tier_to_cool_after_days_since_creation", ruleIndex)); ok { + snapshot.TierToCool = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), + } + } + definition.Actions.Snapshot = snapshot } - } - return &result -} - -func expandStorageManagementPolicyActionsVersion(inputs []interface{}) *storage.ManagementPolicyVersion { - if len(inputs) == 0 || inputs[0] == nil { - return nil - } - input := inputs[0].(map[string]interface{}) - - result := storage.ManagementPolicyVersion{} - - if v, ok := input["delete_after_days_since_creation"].(int); ok && v != -1 { - result.Delete = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(float64(v)), - } - } - if v, ok := input["change_tier_to_archive_after_days_since_creation"].(int); ok && v != -1 { - result.TierToArchive = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(float64(v)), - } - } - if v, ok := input["change_tier_to_cool_after_days_since_creation"].(int); ok && v != -1 { - result.TierToCool = &storage.DateAfterCreation{ - DaysAfterCreationGreaterThan: utils.Float(float64(v)), + if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version", ruleIndex)); ok { + version := &storage.ManagementPolicyVersion{} + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version.0.delete_after_days_since_creation", ruleIndex)); ok { + version.Delete = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), + } + } + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version.0.change_tier_to_archive_after_days_since_creation", ruleIndex)); ok { + version.TierToArchive = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), + } + } + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version.0.change_tier_to_cool_after_days_since_creation", ruleIndex)); ok { + version.TierToCool = &storage.DateAfterCreation{ + DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), + } + } + definition.Actions.Version = version } } - return &result + rule := storage.ManagementPolicyRule{ + Name: &name, + Enabled: &enabled, + Type: &typeVal, + Definition: &definition, + } + return rule } func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRule) []interface{} { rules := make([]interface{}, 0) - if armRules == nil || len(*armRules) == 0 { + if armRules == nil { return rules } - for _, armRule := range *armRules { - var name string + rule := make(map[string]interface{}) + if armRule.Name != nil { - name = *armRule.Name + rule["name"] = *armRule.Name } - var enabled bool if armRule.Enabled != nil { - enabled = *armRule.Enabled - } - - var filters, actions []interface{} - if armRule.Definition != nil { - filters = flattenStorageManagementPolicyFilters(armRule.Definition.Filters) - actions = flattenStorageManagementPolicyActions(armRule.Definition.Actions) + rule["enabled"] = *armRule.Enabled } - rules = append(rules, map[string]interface{}{ - "name": name, - "enabled": enabled, - "filters": filters, - "actions": actions, - }) - } - return rules -} - -func flattenStorageManagementPolicyFilters(filters *storage.ManagementPolicyFilter) []interface{} { - if filters == nil { - return []interface{}{} - } - - return []interface{}{ - map[string]interface{}{ - "prefix_match": utils.FlattenStringSlice(filters.PrefixMatch), - "blob_types": utils.FlattenStringSlice(filters.BlobTypes), - "match_blob_index_tag": flattenAzureRmStorageBlobIndexMatch(filters.BlobIndexMatch), - }, - } -} - -func flattenStorageManagementPolicyActions(actions *storage.ManagementPolicyAction) []interface{} { - if actions == nil { - return []interface{}{} - } - - return []interface{}{ - map[string]interface{}{ - "base_blob": flattenStorageManagementPolicyActionsBaseBlob(actions.BaseBlob), - "snapshot": flattenStorageManagementPolicyActionsSnapshot(actions.Snapshot), - "version": flattenStorageManagementPolicyActionsVersion(actions.Version), - }, - } -} - -func flattenStorageManagementPolicyActionsBaseBlob(baseBlob *storage.ManagementPolicyBaseBlob) []interface{} { - if baseBlob == nil { - return []interface{}{} - } - - deleteModification, archiveModification, coolModification := -1, -1, -1 - if v := baseBlob.Delete; v != nil { - if v.DaysAfterModificationGreaterThan != nil { - deleteModification = int(*v.DaysAfterModificationGreaterThan) - } - } - if v := baseBlob.TierToArchive; v != nil { - if v.DaysAfterModificationGreaterThan != nil { - archiveModification = int(*v.DaysAfterModificationGreaterThan) - } - } - if v := baseBlob.TierToCool; v != nil { - if v.DaysAfterModificationGreaterThan != nil { - coolModification = int(*v.DaysAfterModificationGreaterThan) - } - } - - return []interface{}{ - map[string]interface{}{ - "delete_after_days_since_modification_greater_than": deleteModification, - "tier_to_archive_after_days_since_modification_greater_than": archiveModification, - "tier_to_cool_after_days_since_modification_greater_than": coolModification, - }, - } -} - -func flattenStorageManagementPolicyActionsSnapshot(snapshot *storage.ManagementPolicySnapShot) []interface{} { - if snapshot == nil { - return []interface{}{} - } + armDefinition := armRule.Definition + if armDefinition != nil { + armFilter := armDefinition.Filters + if armFilter != nil { + filter := make(map[string]interface{}) + if armFilter.PrefixMatch != nil { + prefixMatches := make([]interface{}, 0) + for _, armPrefixMatch := range *armFilter.PrefixMatch { + prefixMatches = append(prefixMatches, armPrefixMatch) + } + filter["prefix_match"] = prefixMatches + } + if armFilter.BlobTypes != nil { + blobTypes := make([]interface{}, 0) + for _, armBlobType := range *armFilter.BlobTypes { + blobTypes = append(blobTypes, armBlobType) + } + filter["blob_types"] = blobTypes + } + + filter["match_blob_index_tag"] = flattenAzureRmStorageBlobIndexMatch(armFilter.BlobIndexMatch) + + rule["filters"] = [1]interface{}{filter} + } - deleteCreation, archiveCreation, coolCreation := -1, -1, -1 - if v := snapshot.Delete; v != nil { - if v.DaysAfterCreationGreaterThan != nil { - deleteCreation = int(*v.DaysAfterCreationGreaterThan) - } - } - if v := snapshot.TierToArchive; v != nil { - if v.DaysAfterCreationGreaterThan != nil { - archiveCreation = int(*v.DaysAfterCreationGreaterThan) - } - } - if v := snapshot.TierToCool; v != nil { - if v.DaysAfterCreationGreaterThan != nil { - coolCreation = int(*v.DaysAfterCreationGreaterThan) + armAction := armDefinition.Actions + if armAction != nil { + action := make(map[string]interface{}) + armActionBaseBlob := armAction.BaseBlob + if armActionBaseBlob != nil { + baseBlob := make(map[string]interface{}) + if armActionBaseBlob.TierToCool != nil && armActionBaseBlob.TierToCool.DaysAfterModificationGreaterThan != nil { + intTemp := int(*armActionBaseBlob.TierToCool.DaysAfterModificationGreaterThan) + baseBlob["tier_to_cool_after_days_since_modification_greater_than"] = intTemp + } + if armActionBaseBlob.TierToArchive != nil && armActionBaseBlob.TierToArchive.DaysAfterModificationGreaterThan != nil { + intTemp := int(*armActionBaseBlob.TierToArchive.DaysAfterModificationGreaterThan) + baseBlob["tier_to_archive_after_days_since_modification_greater_than"] = intTemp + } + if armActionBaseBlob.Delete != nil && armActionBaseBlob.Delete.DaysAfterModificationGreaterThan != nil { + intTemp := int(*armActionBaseBlob.Delete.DaysAfterModificationGreaterThan) + baseBlob["delete_after_days_since_modification_greater_than"] = intTemp + } + action["base_blob"] = [1]interface{}{baseBlob} + } + + armActionSnaphost := armAction.Snapshot + if armActionSnaphost != nil { + snapshot := make(map[string]interface{}) + if armActionSnaphost.Delete != nil && armActionSnaphost.Delete.DaysAfterCreationGreaterThan != nil { + intTemp := int(*armActionSnaphost.Delete.DaysAfterCreationGreaterThan) + snapshot["delete_after_days_since_creation_greater_than"] = intTemp + } + if armActionSnaphost.TierToArchive != nil && armActionSnaphost.TierToArchive.DaysAfterCreationGreaterThan != nil { + intTemp := int(*armActionSnaphost.TierToArchive.DaysAfterCreationGreaterThan) + snapshot["change_tier_to_archive_after_days_since_creation"] = intTemp + } + if armActionSnaphost.TierToCool != nil && armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan != nil { + intTemp := int(*armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan) + snapshot["change_tier_to_cool_after_days_since_creation"] = intTemp + } + action["snapshot"] = [1]interface{}{snapshot} + } + + if armActionVersion := armAction.Version; armActionVersion != nil { + version := make(map[string]interface{}) + if armActionVersion.Delete != nil && armActionVersion.Delete.DaysAfterCreationGreaterThan != nil { + intTemp := int(*armActionVersion.Delete.DaysAfterCreationGreaterThan) + version["delete_after_days_since_creation"] = intTemp + } + if armActionVersion.TierToArchive != nil && armActionVersion.TierToArchive.DaysAfterCreationGreaterThan != nil { + intTemp := int(*armActionVersion.TierToArchive.DaysAfterCreationGreaterThan) + version["change_tier_to_archive_after_days_since_creation"] = intTemp + } + if armActionVersion.TierToCool != nil && armActionVersion.TierToCool.DaysAfterCreationGreaterThan != nil { + intTemp := int(*armActionVersion.TierToCool.DaysAfterCreationGreaterThan) + version["change_tier_to_cool_after_days_since_creation"] = intTemp + } + action["version"] = [1]interface{}{version} + } + + rule["actions"] = [1]interface{}{action} + } } - } - return []interface{}{ - map[string]interface{}{ - "change_tier_to_archive_after_days_since_creation": archiveCreation, - "change_tier_to_cool_after_days_since_creation": coolCreation, - "delete_after_days_since_creation_greater_than": deleteCreation, - }, - } -} - -func flattenStorageManagementPolicyActionsVersion(version *storage.ManagementPolicyVersion) []interface{} { - if version == nil { - return []interface{}{} - } - - deleteCreation, archiveCreation, coolCreation := -1, -1, -1 - if v := version.Delete; v != nil { - if v.DaysAfterCreationGreaterThan != nil { - deleteCreation = int(*v.DaysAfterCreationGreaterThan) - } - } - if v := version.TierToArchive; v != nil { - if v.DaysAfterCreationGreaterThan != nil { - archiveCreation = int(*v.DaysAfterCreationGreaterThan) - } - } - if v := version.TierToCool; v != nil { - if v.DaysAfterCreationGreaterThan != nil { - coolCreation = int(*v.DaysAfterCreationGreaterThan) - } + rules = append(rules, rule) } - return []interface{}{ - map[string]interface{}{ - "change_tier_to_archive_after_days_since_creation": archiveCreation, - "change_tier_to_cool_after_days_since_creation": coolCreation, - "delete_after_days_since_creation": deleteCreation, - }, - } + return rules } func expandAzureRmStorageBlobIndexMatch(blobIndexMatches []interface{}) *[]storage.TagFilter { From e6fb73afae4569f90f132f394ecf50d443086803 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 15:05:54 +0800 Subject: [PATCH 25/29] update --- .../services/storage/storage_management_policy_resource.go | 2 +- website/docs/d/storage_management_policy.html.markdown | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 15ee96dc5bfa..eb1497612317 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -322,7 +322,7 @@ func expandStorageManagementPolicyRules(d *schema.ResourceData) (*[]storage.Mana _, blobIndexExist := d.GetOk(fmt.Sprintf("rule.%d.filters.0.match_blob_index_tag", k)) _, snapshotExist := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot", k)) _, versionExist := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version", k)) - if blobIndexExist && snapshotExist && versionExist { + if blobIndexExist && (snapshotExist || versionExist) { return nil, fmt.Errorf("`match_blob_index_tag` is not supported as a filter for versions and snapshots") } result = append(result, rule) diff --git a/website/docs/d/storage_management_policy.html.markdown b/website/docs/d/storage_management_policy.html.markdown index 127b79028158..bb63b948830f 100644 --- a/website/docs/d/storage_management_policy.html.markdown +++ b/website/docs/d/storage_management_policy.html.markdown @@ -70,18 +70,17 @@ The following arguments are supported: `snapshot` supports the following: -* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. * `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob snapshot to archive storage. * `change_tier_to_cool_after_days_since_creation` - The age in days after creation to tier blob snapshot to cool storage. +* `delete_after_days_since_creation_greater_than` - The age in days after creation to delete the blob snapshot. --- `version` supports the following: -* `delete_after_days_since_creation` - The age in days after creation to delete the blob version. * `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob version to archive storage. * `change_tier_to_cool_after_days_since_creation` - The age in days creation create to tier blob version to cool storage. - +* `delete_after_days_since_creation` - The age in days after creation to delete the blob version. --- From 34763ef32e9706d705c3359fd65aa11091e8e690 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 15:26:52 +0800 Subject: [PATCH 26/29] update --- website/docs/d/storage_management_policy.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/storage_management_policy.html.markdown b/website/docs/d/storage_management_policy.html.markdown index bb63b948830f..b71f0719d479 100644 --- a/website/docs/d/storage_management_policy.html.markdown +++ b/website/docs/d/storage_management_policy.html.markdown @@ -79,7 +79,7 @@ The following arguments are supported: `version` supports the following: * `change_tier_to_archive_after_days_since_creation` - The age in days after creation to tier blob version to archive storage. -* `change_tier_to_cool_after_days_since_creation` - The age in days creation create to tier blob version to cool storage. +* `change_tier_to_cool_after_days_since_creation` - The age in days after creation to tier blob version to cool storage. * `delete_after_days_since_creation` - The age in days after creation to delete the blob version. --- From c556bdac6a742273ae13d96710e421743ff4e1f3 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 21 Apr 2021 21:51:07 +0800 Subject: [PATCH 27/29] update --- .../services/storage/storage_management_policy_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index eb1497612317..995f1c42a5eb 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -364,7 +364,6 @@ func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) st definition.Filters.BlobTypes = &blobTypes definition.Filters.BlobIndexMatch = expandAzureRmStorageBlobIndexMatch(filterRef["match_blob_index_tag"].(*schema.Set).List()) - } } if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions", ruleIndex)); ok { From 66e77d250e65338f0ca2774a61ce5c5dd4930d7f Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 26 Apr 2021 10:01:07 +0800 Subject: [PATCH 28/29] update --- .../storage_management_policy_resource.go | 84 +++++++++++-------- ...storage_management_policy_resource_test.go | 68 +++++++++++++++ 2 files changed, 115 insertions(+), 37 deletions(-) diff --git a/azurerm/internal/services/storage/storage_management_policy_resource.go b/azurerm/internal/services/storage/storage_management_policy_resource.go index 159a92452c07..da3957ecc570 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource.go @@ -129,21 +129,27 @@ func resourceStorageManagementPolicy() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "tier_to_cool_after_days_since_modification_greater_than": { - Type: schema.TypeInt, - Optional: true, - Default: nil, + Type: schema.TypeInt, + Optional: true, + Default: nil, + // todo: default change to -1 to allow value 0 in 3.0 + // for issue https://github.com/terraform-providers/terraform-provider-azurerm/issues/6158 ValidateFunc: validation.IntBetween(0, 99999), }, "tier_to_archive_after_days_since_modification_greater_than": { - Type: schema.TypeInt, - Optional: true, - Default: nil, + Type: schema.TypeInt, + Optional: true, + Default: nil, + // todo: default change to -1 to allow value 0 in 3.0 + // for issue https://github.com/terraform-providers/terraform-provider-azurerm/issues/6158 ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_modification_greater_than": { - Type: schema.TypeInt, - Optional: true, - Default: nil, + Type: schema.TypeInt, + Optional: true, + Default: nil, + // todo: default change to -1 to allow value 0 in 3.0 + // for issue https://github.com/terraform-providers/terraform-provider-azurerm/issues/6158 ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -159,18 +165,20 @@ func resourceStorageManagementPolicy() *schema.Resource { "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_creation_greater_than": { - Type: schema.TypeInt, - Optional: true, + Type: schema.TypeInt, + Optional: true, + // todo: default change to -1 to allow value 0 in 3.0 + // for issue https://github.com/terraform-providers/terraform-provider-azurerm/issues/6158 ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -185,19 +193,19 @@ func resourceStorageManagementPolicy() *schema.Resource { "change_tier_to_archive_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, "change_tier_to_cool_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, "delete_after_days_since_creation": { Type: schema.TypeInt, Optional: true, - Default: nil, + Default: -1, ValidateFunc: validation.IntBetween(0, 99999), }, }, @@ -403,12 +411,12 @@ func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) st v2 := float64(v.(int)) snapshot.Delete = &storage.DateAfterCreation{DaysAfterCreationGreaterThan: &v2} } - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot.0.change_tier_to_archive_after_days_since_creation", ruleIndex)); ok { + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.snapshot.0.change_tier_to_archive_after_days_since_creation", ruleIndex)); v != -1 { snapshot.TierToArchive = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), } } - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.snapshot.0.change_tier_to_cool_after_days_since_creation", ruleIndex)); ok { + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.snapshot.0.change_tier_to_cool_after_days_since_creation", ruleIndex)); v != -1 { snapshot.TierToCool = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), } @@ -418,17 +426,17 @@ func expandStorageManagementPolicyRule(d *schema.ResourceData, ruleIndex int) st if _, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version", ruleIndex)); ok { version := &storage.ManagementPolicyVersion{} - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version.0.delete_after_days_since_creation", ruleIndex)); ok { + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.version.0.delete_after_days_since_creation", ruleIndex)); v != -1 { version.Delete = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), } } - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version.0.change_tier_to_archive_after_days_since_creation", ruleIndex)); ok { + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.version.0.change_tier_to_archive_after_days_since_creation", ruleIndex)); v != -1 { version.TierToArchive = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), } } - if v, ok := d.GetOk(fmt.Sprintf("rule.%d.actions.0.version.0.change_tier_to_cool_after_days_since_creation", ruleIndex)); ok { + if v := d.Get(fmt.Sprintf("rule.%d.actions.0.version.0.change_tier_to_cool_after_days_since_creation", ruleIndex)); v != -1 { version.TierToCool = &storage.DateAfterCreation{ DaysAfterCreationGreaterThan: utils.Float(float64(v.(int))), } @@ -509,37 +517,39 @@ func flattenStorageManagementPolicyRules(armRules *[]storage.ManagementPolicyRul armActionSnaphost := armAction.Snapshot if armActionSnaphost != nil { - snapshot := make(map[string]interface{}) + deleteAfterCreation, archiveAfterCreation, coolAfterCreation := 0, -1, -1 if armActionSnaphost.Delete != nil && armActionSnaphost.Delete.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionSnaphost.Delete.DaysAfterCreationGreaterThan) - snapshot["delete_after_days_since_creation_greater_than"] = intTemp + deleteAfterCreation = int(*armActionSnaphost.Delete.DaysAfterCreationGreaterThan) } if armActionSnaphost.TierToArchive != nil && armActionSnaphost.TierToArchive.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionSnaphost.TierToArchive.DaysAfterCreationGreaterThan) - snapshot["change_tier_to_archive_after_days_since_creation"] = intTemp + archiveAfterCreation = int(*armActionSnaphost.TierToArchive.DaysAfterCreationGreaterThan) } if armActionSnaphost.TierToCool != nil && armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan) - snapshot["change_tier_to_cool_after_days_since_creation"] = intTemp + coolAfterCreation = int(*armActionSnaphost.TierToCool.DaysAfterCreationGreaterThan) } - action["snapshot"] = [1]interface{}{snapshot} + action["snapshot"] = [1]interface{}{map[string]interface{}{ + "delete_after_days_since_creation_greater_than": deleteAfterCreation, + "change_tier_to_archive_after_days_since_creation": archiveAfterCreation, + "change_tier_to_cool_after_days_since_creation": coolAfterCreation, + }} } if armActionVersion := armAction.Version; armActionVersion != nil { - version := make(map[string]interface{}) + deleteAfterCreation, archiveAfterCreation, coolAfterCreation := -1, -1, -1 if armActionVersion.Delete != nil && armActionVersion.Delete.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionVersion.Delete.DaysAfterCreationGreaterThan) - version["delete_after_days_since_creation"] = intTemp + deleteAfterCreation = int(*armActionVersion.Delete.DaysAfterCreationGreaterThan) } if armActionVersion.TierToArchive != nil && armActionVersion.TierToArchive.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionVersion.TierToArchive.DaysAfterCreationGreaterThan) - version["change_tier_to_archive_after_days_since_creation"] = intTemp + archiveAfterCreation = int(*armActionVersion.TierToArchive.DaysAfterCreationGreaterThan) } if armActionVersion.TierToCool != nil && armActionVersion.TierToCool.DaysAfterCreationGreaterThan != nil { - intTemp := int(*armActionVersion.TierToCool.DaysAfterCreationGreaterThan) - version["change_tier_to_cool_after_days_since_creation"] = intTemp + coolAfterCreation = int(*armActionVersion.TierToCool.DaysAfterCreationGreaterThan) } - action["version"] = [1]interface{}{version} + action["version"] = [1]interface{}{map[string]interface{}{ + "delete_after_days_since_creation": deleteAfterCreation, + "change_tier_to_archive_after_days_since_creation": archiveAfterCreation, + "change_tier_to_cool_after_days_since_creation": coolAfterCreation, + }} } rule["actions"] = [1]interface{}{action} diff --git a/azurerm/internal/services/storage/storage_management_policy_resource_test.go b/azurerm/internal/services/storage/storage_management_policy_resource_test.go index 5f6a9ed67dba..9216751878b3 100644 --- a/azurerm/internal/services/storage/storage_management_policy_resource_test.go +++ b/azurerm/internal/services/storage/storage_management_policy_resource_test.go @@ -308,6 +308,21 @@ func TestAccStorageManagementPolicy_complete(t *testing.T) { }) } +func TestAccStorageManagementPolicy_zero(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + r := StorageManagementPolicyResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.zero(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccStorageManagementPolicy_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") r := StorageManagementPolicyResource{} @@ -868,3 +883,56 @@ resource "azurerm_storage_management_policy" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } + +func (r StorageManagementPolicyResource) zero(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = azurerm_resource_group.test.name + + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "test" { + storage_account_id = azurerm_storage_account.test.id + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + change_tier_to_archive_after_days_since_creation = 0 + change_tier_to_cool_after_days_since_creation = 0 + delete_after_days_since_creation_greater_than = 30 + } + version { + change_tier_to_archive_after_days_since_creation = 0 + change_tier_to_cool_after_days_since_creation = 0 + delete_after_days_since_creation = 0 + } + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} From 51f914a3c929ef4bd31cc0dc8e4aa832ebcbb767 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 26 Apr 2021 19:32:35 -0700 Subject: [PATCH 29/29] Update website/docs/r/storage_management_policy.html.markdown --- website/docs/r/storage_management_policy.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/docs/r/storage_management_policy.html.markdown b/website/docs/r/storage_management_policy.html.markdown index 0db7c99df70f..c242f1ae4518 100644 --- a/website/docs/r/storage_management_policy.html.markdown +++ b/website/docs/r/storage_management_policy.html.markdown @@ -106,7 +106,8 @@ The following arguments are supported: * `prefix_match` - An array of strings for prefixes to be matched. * `blob_types` - An array of predefined values. Valid options are `blockBlob` and `appendBlob`. * `match_blob_index_tag` - A `match_blob_index_tag` block as defined below. The block defines the blob index tag based filtering for blob objects. -~> **NOTE:** This property requires enabling the `blobIndex` feature with [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/) before setting the block `match_blob_index_tag`. + +~> **NOTE:** The `match_blob_index_tag property requires enabling the `blobIndex` feature with [PSH or Cli commands](https://azure.microsoft.com/en-us/blog/manage-and-find-data-with-blob-index-for-azure-storage-now-in-preview/). --- `actions` supports the following: