From 60a3592fd116f49de32f32aae8e7431c9d2680f0 Mon Sep 17 00:00:00 2001 From: njucz Date: Thu, 4 Feb 2021 16:02:14 +0800 Subject: [PATCH 1/3] fix tc --- ...rage_data_lake_gen2_filesystem_resource.go | 31 +++++++++---------- ...data_lake_gen2_filesystem_resource_test.go | 23 +++++++++++--- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go index b14d4e2459e3..bbc79f709d0a 100644 --- a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go +++ b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go @@ -216,6 +216,10 @@ func resourceStorageDataLakeGen2FileSystemUpdate(d *schema.ResourceData, meta in return fmt.Errorf("Error checking for existence of Storage Account %q (Resource Group %q): %+v", storageID.Name, storageID.ResourceGroup, err) } + if acl != nil && (storageAccount.IsHnsEnabled == nil || *storageAccount.IsHnsEnabled == false) { + return fmt.Errorf("ACL is enabled only when the Hierarchical Namespace (HNS) feature is turned ON") + } + propertiesRaw := d.Get("properties").(map[string]interface{}) properties := ExpandMetaData(propertiesRaw) @@ -292,24 +296,19 @@ func resourceStorageDataLakeGen2FileSystemRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error setting `properties`: %+v", err) } - // The above `getStatus` API request doesn't return the ACLs - // Have to make a `getAccessControl` request, but that doesn't return all fields either! - pathResponse, err := pathClient.GetProperties(ctx, id.AccountName, id.DirectoryName, "/", paths.GetPropertiesActionGetAccessControl) - if err != nil { - if utils.ResponseWasNotFound(pathResponse.Response) { - log.Printf("[INFO] Root path does not exist in File System %q in Storage Account %q - removing from state...", id.DirectoryName, id.AccountName) - d.SetId("") - return nil + // acl is only enabled when `IsHnsEnabled` is true otherwise the rest api will report error + if storageAccount.IsHnsEnabled != nil && *storageAccount.IsHnsEnabled { + // The above `getStatus` API request doesn't return the ACLs + // Have to make a `getAccessControl` request, but that doesn't return all fields either! + pathResponse, err := pathClient.GetProperties(ctx, id.AccountName, id.DirectoryName, "/", paths.GetPropertiesActionGetAccessControl) + if err == nil { + acl, err := accesscontrol.ParseACL(pathResponse.ACL) + if err != nil { + return fmt.Errorf("Error parsing response ACL %q: %s", pathResponse.ACL, err) + } + d.Set("ace", FlattenDataLakeGen2AceList(acl)) } - - return fmt.Errorf("Error retrieving ACLs for Root path in File System %q in Storage Account %q: %+v", id.DirectoryName, id.AccountName, err) - } - - acl, err := accesscontrol.ParseACL(pathResponse.ACL) - if err != nil { - return fmt.Errorf("Error parsing response ACL %q: %s", pathResponse.ACL, err) } - d.Set("ace", FlattenDataLakeGen2AceList(acl)) return nil } diff --git a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go index 1e224dd445d9..f2afb93ecd2f 100644 --- a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go +++ b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go @@ -57,7 +57,7 @@ func TestAccStorageDataLakeGen2FileSystem_withDefaultACL(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.RequiresImportErrorStep(r.requiresImport), + data.ImportStep(), }) } @@ -144,15 +144,30 @@ func (r StorageDataLakeGen2FileSystemResource) Destroy(ctx context.Context, clie } func (r StorageDataLakeGen2FileSystemResource) basic(data acceptance.TestData) string { - template := r.template(data) return fmt.Sprintf(` -%s +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "acctestacc%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_kind = "BlobStorage" + account_tier = "Standard" + account_replication_type = "LRS" +} resource "azurerm_storage_data_lake_gen2_filesystem" "test" { name = "acctest-%d" storage_account_id = azurerm_storage_account.test.id } -`, template, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } func (r StorageDataLakeGen2FileSystemResource) requiresImport(data acceptance.TestData) string { From 697e5346b534670503b317c3c42236c6eb3f94a9 Mon Sep 17 00:00:00 2001 From: njucz Date: Thu, 4 Feb 2021 16:51:23 +0800 Subject: [PATCH 2/3] update --- .../storage/storage_data_lake_gen2_filesystem_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go index bbc79f709d0a..78ffb18bf6f0 100644 --- a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go +++ b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go @@ -216,7 +216,7 @@ func resourceStorageDataLakeGen2FileSystemUpdate(d *schema.ResourceData, meta in return fmt.Errorf("Error checking for existence of Storage Account %q (Resource Group %q): %+v", storageID.Name, storageID.ResourceGroup, err) } - if acl != nil && (storageAccount.IsHnsEnabled == nil || *storageAccount.IsHnsEnabled == false) { + if acl != nil && (storageAccount.IsHnsEnabled == nil || !*storageAccount.IsHnsEnabled) { return fmt.Errorf("ACL is enabled only when the Hierarchical Namespace (HNS) feature is turned ON") } From c053a7a1913211fe38237a7eab4262111431d23a Mon Sep 17 00:00:00 2001 From: njucz <740360112@qq.com> Date: Thu, 4 Feb 2021 21:47:50 +0800 Subject: [PATCH 3/3] update --- ...rage_data_lake_gen2_filesystem_resource.go | 17 +++++++++++--- ...data_lake_gen2_filesystem_resource_test.go | 23 ++++--------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go index 78ffb18bf6f0..0c5eea8e568c 100644 --- a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go +++ b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource.go @@ -139,6 +139,12 @@ func resourceStorageDataLakeGen2FileSystemCreate(d *schema.ResourceData, meta in return fmt.Errorf("Error checking for existence of Storage Account %q (Resource Group %q): %+v", storageID.Name, storageID.ResourceGroup, err) } + if acl != nil && (storageAccount.AccountProperties == nil || + storageAccount.AccountProperties.IsHnsEnabled == nil || + !*storageAccount.AccountProperties.IsHnsEnabled) { + return fmt.Errorf("ACL is enabled only when the Hierarchical Namespace (HNS) feature is turned ON") + } + fileSystemName := d.Get("name").(string) propertiesRaw := d.Get("properties").(map[string]interface{}) properties := ExpandMetaData(propertiesRaw) @@ -216,7 +222,9 @@ func resourceStorageDataLakeGen2FileSystemUpdate(d *schema.ResourceData, meta in return fmt.Errorf("Error checking for existence of Storage Account %q (Resource Group %q): %+v", storageID.Name, storageID.ResourceGroup, err) } - if acl != nil && (storageAccount.IsHnsEnabled == nil || !*storageAccount.IsHnsEnabled) { + if acl != nil && (storageAccount.AccountProperties == nil || + storageAccount.AccountProperties.IsHnsEnabled == nil || + !*storageAccount.AccountProperties.IsHnsEnabled) { return fmt.Errorf("ACL is enabled only when the Hierarchical Namespace (HNS) feature is turned ON") } @@ -296,8 +304,10 @@ func resourceStorageDataLakeGen2FileSystemRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error setting `properties`: %+v", err) } + var ace []interface{} // acl is only enabled when `IsHnsEnabled` is true otherwise the rest api will report error - if storageAccount.IsHnsEnabled != nil && *storageAccount.IsHnsEnabled { + if storageAccount.AccountProperties != nil && storageAccount.AccountProperties.IsHnsEnabled != nil && + *storageAccount.AccountProperties.IsHnsEnabled { // The above `getStatus` API request doesn't return the ACLs // Have to make a `getAccessControl` request, but that doesn't return all fields either! pathResponse, err := pathClient.GetProperties(ctx, id.AccountName, id.DirectoryName, "/", paths.GetPropertiesActionGetAccessControl) @@ -306,9 +316,10 @@ func resourceStorageDataLakeGen2FileSystemRead(d *schema.ResourceData, meta inte if err != nil { return fmt.Errorf("Error parsing response ACL %q: %s", pathResponse.ACL, err) } - d.Set("ace", FlattenDataLakeGen2AceList(acl)) + ace = FlattenDataLakeGen2AceList(acl) } } + d.Set("ace", ace) return nil } diff --git a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go index f2afb93ecd2f..1e224dd445d9 100644 --- a/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go +++ b/azurerm/internal/services/storage/storage_data_lake_gen2_filesystem_resource_test.go @@ -57,7 +57,7 @@ func TestAccStorageDataLakeGen2FileSystem_withDefaultACL(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.ImportStep(), + data.RequiresImportErrorStep(r.requiresImport), }) } @@ -144,30 +144,15 @@ func (r StorageDataLakeGen2FileSystemResource) Destroy(ctx context.Context, clie } func (r StorageDataLakeGen2FileSystemResource) basic(data acceptance.TestData) string { + template := r.template(data) return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestacc%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_kind = "BlobStorage" - account_tier = "Standard" - account_replication_type = "LRS" -} +%s resource "azurerm_storage_data_lake_gen2_filesystem" "test" { name = "acctest-%d" storage_account_id = azurerm_storage_account.test.id } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) +`, template, data.RandomInteger) } func (r StorageDataLakeGen2FileSystemResource) requiresImport(data acceptance.TestData) string {