From 18782a6db6d974bfa250192de1d626eb71371859 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 26 May 2021 14:29:00 +0800 Subject: [PATCH 1/4] update --- .../storage/storage_account_resource.go | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/azurerm/internal/services/storage/storage_account_resource.go b/azurerm/internal/services/storage/storage_account_resource.go index 8a41cab84efe..2882b9192109 100644 --- a/azurerm/internal/services/storage/storage_account_resource.go +++ b/azurerm/internal/services/storage/storage_account_resource.go @@ -934,6 +934,12 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e blobProperties := expandBlobProperties(val.([]interface{})) + if v := d.Get("blob_properties.0.last_access_time_enabled").(bool); v { + blobProperties.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ + Enable: utils.Bool(v), + } + } + if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1268,6 +1274,16 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e blobClient := meta.(*clients.Client).Storage.BlobServicesClient blobProperties := expandBlobProperties(d.Get("blob_properties").([]interface{})) + if d.HasChange("blob_properties.0.last_access_time_enabled") { + lastAccessTimeTracking := false + if v := d.Get("blob_properties.0.last_access_time_enabled").(bool); v { + lastAccessTimeTracking = true + } + blobProperties.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ + Enable: utils.Bool(lastAccessTimeTracking), + } + } + if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1806,10 +1822,6 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { ChangeFeed: &storage.ChangeFeed{ Enabled: utils.Bool(false), }, - LastAccessTimeTrackingPolicy: &storage.LastAccessTimeTrackingPolicy{ - Enable: utils.Bool(false), - }, - DeleteRetentionPolicy: &storage.DeleteRetentionPolicy{ Enabled: utils.Bool(false), }, @@ -1839,9 +1851,6 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { props.DefaultServiceVersion = utils.String(version) } - props.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ - Enable: utils.Bool(v["last_access_time_enabled"].(bool)), - } return &props } From 822d8466fe0330beabe6df953c4a42274a87a510 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 26 May 2021 15:44:17 +0800 Subject: [PATCH 2/4] update --- .../storage/storage_account_resource.go | 31 +++-- .../storage/storage_account_resource_test.go | 107 +++++++++++++++++- website/docs/r/storage_account.html.markdown | 4 + 3 files changed, 130 insertions(+), 12 deletions(-) diff --git a/azurerm/internal/services/storage/storage_account_resource.go b/azurerm/internal/services/storage/storage_account_resource.go index 2882b9192109..0024d18ffe45 100644 --- a/azurerm/internal/services/storage/storage_account_resource.go +++ b/azurerm/internal/services/storage/storage_account_resource.go @@ -940,6 +940,10 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e } } + if v, ok := d.GetOk("blob_properties.0.container_delete_retention_policy"); ok { + blobProperties.ContainerDeleteRetentionPolicy = expandBlobPropertiesDeleteRetentionPolicy(v.([]interface{}), false) + } + if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1284,6 +1288,10 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e } } + if d.HasChange("blob_properties.0.container_delete_retention_policy") { + blobProperties.ContainerDeleteRetentionPolicy = expandBlobPropertiesDeleteRetentionPolicy(d.Get("blob_properties.0.container_delete_retention_policy").([]interface{}), true) + } + if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1835,9 +1843,7 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { v := input[0].(map[string]interface{}) deletePolicyRaw := v["delete_retention_policy"].([]interface{}) - props.BlobServicePropertiesProperties.DeleteRetentionPolicy = expandBlobPropertiesDeleteRetentionPolicy(deletePolicyRaw) - containerDeletePolicyRaw := v["container_delete_retention_policy"].([]interface{}) - props.BlobServicePropertiesProperties.ContainerDeleteRetentionPolicy = expandBlobPropertiesDeleteRetentionPolicy(containerDeletePolicyRaw) + props.BlobServicePropertiesProperties.DeleteRetentionPolicy = expandBlobPropertiesDeleteRetentionPolicy(deletePolicyRaw, true) corsRaw := v["cors_rule"].([]interface{}) props.BlobServicePropertiesProperties.Cors = expandBlobPropertiesCors(corsRaw) @@ -1854,21 +1860,24 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { return &props } -func expandBlobPropertiesDeleteRetentionPolicy(input []interface{}) *storage.DeleteRetentionPolicy { - deleteRetentionPolicy := storage.DeleteRetentionPolicy{ +func expandBlobPropertiesDeleteRetentionPolicy(input []interface{}, isupdate bool) *storage.DeleteRetentionPolicy { + result := storage.DeleteRetentionPolicy{ Enabled: utils.Bool(false), } + if (len(input) == 0 || input[0] == nil) && !isupdate { + return nil + } - if len(input) == 0 { - return &deleteRetentionPolicy + if (len(input) == 0 || input[0] == nil) && isupdate { + return &result } policy := input[0].(map[string]interface{}) - days := policy["days"].(int) - deleteRetentionPolicy.Enabled = utils.Bool(true) - deleteRetentionPolicy.Days = utils.Int32(int32(days)) - return &deleteRetentionPolicy + return &storage.DeleteRetentionPolicy{ + Enabled: utils.Bool(true), + Days: utils.Int32(int32(policy["days"].(int))), + } } func expandBlobPropertiesCors(input []interface{}) *storage.CorsRules { diff --git a/azurerm/internal/services/storage/storage_account_resource_test.go b/azurerm/internal/services/storage/storage_account_resource_test.go index 2a3e3bb4cd40..11fea40492a8 100644 --- a/azurerm/internal/services/storage/storage_account_resource_test.go +++ b/azurerm/internal/services/storage/storage_account_resource_test.go @@ -577,6 +577,28 @@ func TestAccStorageAccount_blobProperties(t *testing.T) { }) } +func TestAccStorageAccount_blobProperties_containerAndLastAccessTimeDisabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + r := StorageAccountResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.blobPropertiesContainerAndLastAccessTimeDisabled(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.blobPropertiesContainerAndLastAccessTimeDisabledUpdated(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccStorageAccount_blobPropertiesEmptyAllowedExposedHeaders(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") r := StorageAccountResource{} @@ -910,7 +932,7 @@ resource "azurerm_storage_account" "test" { account_replication_type = "LRS" tags = { - %s + %s } } `, data.RandomInteger, data.Locations.Primary, data.RandomString, tags) @@ -1857,6 +1879,89 @@ resource "azurerm_storage_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } +func (r StorageAccountResource) blobPropertiesContainerAndLastAccessTimeDisabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestAzureRMSA-%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" + + blob_properties { + cors_rule { + allowed_origins = ["http://www.example.com"] + exposed_headers = ["x-tempo-*"] + allowed_headers = ["x-tempo-*"] + allowed_methods = ["GET", "PUT", "PATCH"] + max_age_in_seconds = "500" + } + + delete_retention_policy { + days = 300 + } + + default_service_version = "2019-07-07" + versioning_enabled = true + change_feed_enabled = true + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func (r StorageAccountResource) blobPropertiesContainerAndLastAccessTimeDisabledUpdated(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestAzureRMSA-%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" + + blob_properties { + cors_rule { + allowed_origins = ["http://www.example.com"] + exposed_headers = ["x-tempo-*", "x-method-*"] + allowed_headers = ["*"] + allowed_methods = ["GET"] + max_age_in_seconds = "2000000000" + } + + cors_rule { + allowed_origins = ["http://www.test.com"] + exposed_headers = ["x-tempo-*"] + allowed_headers = ["*"] + allowed_methods = ["PUT"] + max_age_in_seconds = "1000" + } + + delete_retention_policy { + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + func (r StorageAccountResource) blobPropertiesUpdatedEmptyAllowedExposedHeaders(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index f87fcfd0555e..b5d2fb08d4a2 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -155,6 +155,10 @@ A `blob_properties` block supports the following: * `container_delete_retention_policy` - (Optional) A `container_delete_retention_policy` block as defined below. +~> **Note:** Before setting `container_delete_retention_policy`, the feature `ContainerSoftDelete` needs to be enabled by (steps)[https://docs.microsoft.com/en-us/azure/storage/blobs/soft-delete-container-overview?tabs=powershell#register-for-the-preview +] + + --- A `cors_rule` block supports the following: From 8b99b0f67782477aefffb1e57a587e264d68547e Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 26 May 2021 15:51:26 +0800 Subject: [PATCH 3/4] update --- website/docs/r/storage_account.html.markdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index b5d2fb08d4a2..72fb93d91220 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -155,9 +155,7 @@ A `blob_properties` block supports the following: * `container_delete_retention_policy` - (Optional) A `container_delete_retention_policy` block as defined below. -~> **Note:** Before setting `container_delete_retention_policy`, the feature `ContainerSoftDelete` needs to be enabled by (steps)[https://docs.microsoft.com/en-us/azure/storage/blobs/soft-delete-container-overview?tabs=powershell#register-for-the-preview -] - +~> **Note:** Before setting `container_delete_retention_policy`, the feature `ContainerSoftDelete` needs to be enabled by [steps](https://docs.microsoft.com/en-us/azure/storage/blobs/soft-delete-container-overview?tabs=powershell#register-for-the-preview) --- From 0f67a0b1591b0962926a2fd5ef2b645ad396ac7b Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 26 May 2021 16:14:16 +0800 Subject: [PATCH 4/4] update ci other resource fix --- website/docs/r/kubernetes_cluster.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index fae5cef2d728..d825547f2877 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -456,7 +456,7 @@ An `ingress_application_gateway` block supports the following: * `subnet_id` - (Optional) The ID of the subnet on which to create an Application Gateway, which in turn will be integrated with the ingress controller of this Kubernetes Cluster. See [this](https://docs.microsoft.com/en-us/azure/application-gateway/tutorial-ingress-controller-add-on-new) page for further details. --> **NOTE** If using `enabled` in conjunction with `only_critical_addons_enabled`, the AGIC pod will fail to start. A seperate `azurerm_kubernetes_cluster_node_pool` is required to run the AGIC pod successfully. This is because AGIC is classed as a "non-critical addon". +-> **NOTE** If using `enabled` in conjunction with `only_critical_addons_enabled`, the AGIC pod will fail to start. A separate `azurerm_kubernetes_cluster_node_pool` is required to run the AGIC pod successfully. This is because AGIC is classed as a "non-critical addon". ---