Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_data_lake_gen2_filesystem_resource: do not set/retrieve ACLs when HNS is not Enabled #10470

Merged
merged 3 commits into from
Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -216,6 +222,12 @@ 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.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")
}

propertiesRaw := d.Get("properties").(map[string]interface{})
properties := ExpandMetaData(propertiesRaw)

Expand Down Expand Up @@ -292,24 +304,22 @@ 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
var ace []interface{}
// acl is only enabled when `IsHnsEnabled` is true otherwise the rest api will report error
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)
if err == nil {
acl, err := accesscontrol.ParseACL(pathResponse.ACL)
if err != nil {
return fmt.Errorf("Error parsing response ACL %q: %s", pathResponse.ACL, err)
}
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))
d.Set("ace", ace)

return nil
}
Expand Down