diff --git a/internal/services/storage/storage_share_resource.go b/internal/services/storage/storage_share_resource.go index deb8a06dbe516..26904d62a38e1 100644 --- a/internal/services/storage/storage_share_resource.go +++ b/internal/services/storage/storage_share_resource.go @@ -160,7 +160,6 @@ func resourceStorageShare() *pluginsdk.Resource { r.Schema["storage_account_name"] = &pluginsdk.Schema{ Type: pluginsdk.TypeString, Optional: true, - Computed: true, ForceNew: true, ExactlyOneOf: []string{ "storage_account_name", @@ -172,7 +171,6 @@ func resourceStorageShare() *pluginsdk.Resource { r.Schema["storage_account_id"] = &pluginsdk.Schema{ Type: pluginsdk.TypeString, Optional: true, - Computed: true, ForceNew: true, ExactlyOneOf: []string{ "storage_account_name", @@ -197,92 +195,84 @@ func resourceStorageShareCreate(d *pluginsdk.ResourceData, meta interface{}) err defer cancel() if !features.FivePointOhBeta() { - storageClient := meta.(*clients.Client).Storage + if accountName := d.Get("storage_account_name").(string); accountName != "" { + storageClient := meta.(*clients.Client).Storage - accountName := d.Get("storage_account_name").(string) - if accountName == "" { - accountId, err := commonids.ParseStorageAccountID(d.Get("storage_account_id").(string)) + shareName := d.Get("name").(string) + quota := d.Get("quota").(int) + metaDataRaw := d.Get("metadata").(map[string]interface{}) + metaData := ExpandMetaData(metaDataRaw) + account, err := storageClient.FindAccount(ctx, subscriptionId, accountName) if err != nil { - return err + return fmt.Errorf("retrieving Account %q for Share %q: %v", accountName, shareName, err) + } + if account == nil { + return fmt.Errorf("locating Storage Account %q", accountName) } - accountName = accountId.StorageAccountName - } - - shareName := d.Get("name").(string) - quota := d.Get("quota").(int) - metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := ExpandMetaData(metaDataRaw) - account, err := storageClient.FindAccount(ctx, subscriptionId, accountName) - if err != nil { - return fmt.Errorf("retrieving Account %q for Share %q: %v", accountName, shareName, err) - } - if account == nil { - return fmt.Errorf("locating Storage Account %q", accountName) - } + // Determine the file endpoint, so we can build a data plane ID + endpoint, err := account.DataPlaneEndpoint(client.EndpointTypeFile) + if err != nil { + return fmt.Errorf("determining File endpoint: %v", err) + } - // Determine the file endpoint, so we can build a data plane ID - endpoint, err := account.DataPlaneEndpoint(client.EndpointTypeFile) - if err != nil { - return fmt.Errorf("determining File endpoint: %v", err) - } + // Parse the file endpoint as a data plane account ID + accountId, err := accounts.ParseAccountID(*endpoint, storageClient.StorageDomainSuffix) + if err != nil { + return fmt.Errorf("parsing Account ID: %v", err) + } - // Parse the file endpoint as a data plane account ID - accountId, err := accounts.ParseAccountID(*endpoint, storageClient.StorageDomainSuffix) - if err != nil { - return fmt.Errorf("parsing Account ID: %v", err) - } + id := shares.NewShareID(*accountId, shareName) - id := shares.NewShareID(*accountId, shareName) + protocol := shares.ShareProtocol(d.Get("enabled_protocol").(string)) + if protocol == shares.NFS { + // Only FileStorage (whose sku tier is Premium only) storage account is able to have NFS file shares. + // See: https://learn.microsoft.com/en-us/azure/storage/files/storage-files-quick-create-use-linux#applies-to + if account.Kind != storageaccounts.KindFileStorage { + return fmt.Errorf("NFS File Share is only supported for Storage Account with kind %q but got `%s`", string(storageaccounts.KindFileStorage), account.Kind) + } + } - protocol := shares.ShareProtocol(d.Get("enabled_protocol").(string)) - if protocol == shares.NFS { - // Only FileStorage (whose sku tier is Premium only) storage account is able to have NFS file shares. - // See: https://learn.microsoft.com/en-us/azure/storage/files/storage-files-quick-create-use-linux#applies-to - if account.Kind != storageaccounts.KindFileStorage { - return fmt.Errorf("NFS File Share is only supported for Storage Account with kind %q but got `%s`", string(storageaccounts.KindFileStorage), account.Kind) + // The files API does not support bearer tokens (@manicminer, 2024-02-15) + fileSharesDataPlaneClient, err := storageClient.FileSharesDataPlaneClient(ctx, *account, storageClient.DataPlaneOperationSupportingOnlySharedKeyAuth()) + if err != nil { + return fmt.Errorf("building File Share Client: %v", err) } - } - // The files API does not support bearer tokens (@manicminer, 2024-02-15) - fileSharesDataPlaneClient, err := storageClient.FileSharesDataPlaneClient(ctx, *account, storageClient.DataPlaneOperationSupportingOnlySharedKeyAuth()) - if err != nil { - return fmt.Errorf("building File Share Client: %v", err) - } + exists, err := fileSharesDataPlaneClient.Exists(ctx, shareName) + if err != nil { + return fmt.Errorf("checking for existing %s: %v", id, err) + } + if exists != nil && *exists { + return tf.ImportAsExistsError("azurerm_storage_share", id.ID()) + } - exists, err := fileSharesDataPlaneClient.Exists(ctx, shareName) - if err != nil { - return fmt.Errorf("checking for existing %s: %v", id, err) - } - if exists != nil && *exists { - return tf.ImportAsExistsError("azurerm_storage_share", id.ID()) - } + log.Printf("[INFO] Creating Share %q in Storage Account %q", shareName, accountName) + input := shares.CreateInput{ + QuotaInGB: quota, + MetaData: metaData, + EnabledProtocol: protocol, + } - log.Printf("[INFO] Creating Share %q in Storage Account %q", shareName, accountName) - input := shares.CreateInput{ - QuotaInGB: quota, - MetaData: metaData, - EnabledProtocol: protocol, - } + if accessTier := d.Get("access_tier").(string); accessTier != "" { + tier := shares.AccessTier(accessTier) + input.AccessTier = &tier + } - if accessTier := d.Get("access_tier").(string); accessTier != "" { - tier := shares.AccessTier(accessTier) - input.AccessTier = &tier - } + if err = fileSharesDataPlaneClient.Create(ctx, shareName, input); err != nil { + return fmt.Errorf("creating %s: %v", id, err) + } - if err = fileSharesDataPlaneClient.Create(ctx, shareName, input); err != nil { - return fmt.Errorf("creating %s: %v", id, err) - } + d.SetId(id.ID()) - d.SetId(id.ID()) + aclsRaw := d.Get("acl").(*pluginsdk.Set).List() + acls := expandStorageShareACLsDeprecated(aclsRaw) + if err = fileSharesDataPlaneClient.UpdateACLs(ctx, shareName, shares.SetAclInput{SignedIdentifiers: acls}); err != nil { + return fmt.Errorf("setting ACLs for %s: %v", id, err) + } - aclsRaw := d.Get("acl").(*pluginsdk.Set).List() - acls := expandStorageShareACLsDeprecated(aclsRaw) - if err = fileSharesDataPlaneClient.UpdateACLs(ctx, shareName, shares.SetAclInput{SignedIdentifiers: acls}); err != nil { - return fmt.Errorf("setting ACLs for %s: %v", id, err) + return resourceStorageShareRead(d, meta) } - - return resourceStorageShareRead(d, meta) } accountId, err := commonids.ParseStorageAccountID(d.Get("storage_account_id").(string)) @@ -333,7 +323,7 @@ func resourceStorageShareRead(d *pluginsdk.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - if !features.FivePointOhBeta() { + if !features.FivePointOhBeta() && !strings.HasPrefix(d.Id(), "/subscriptions/") { storageClient := meta.(*clients.Client).Storage id, err := shares.ParseShareID(d.Id(), storageClient.StorageDomainSuffix) if err != nil { @@ -368,8 +358,6 @@ func resourceStorageShareRead(d *pluginsdk.ResourceData, meta interface{}) error d.Set("name", id.ShareName) - // Setting both - d.Set("storage_account_id", account.StorageAccountId.ID()) d.Set("storage_account_name", id.AccountId.AccountName) d.Set("quota", props.QuotaGB) @@ -434,6 +422,10 @@ func resourceStorageShareRead(d *pluginsdk.ResourceData, meta interface{}) error } } + if !features.FivePointOhBeta() { + d.Set("resource_manager_id", id.ID()) + } + // TODO - The following section for `url` will need to be updated to go-azure-sdk when the Giovanni Deprecation process has been completed account, err := meta.(*clients.Client).Storage.FindAccount(ctx, subscriptionId, id.StorageAccountName) if err != nil { @@ -467,7 +459,7 @@ func resourceStorageShareUpdate(d *pluginsdk.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - if !features.FivePointOhBeta() { + if !features.FivePointOhBeta() && !strings.HasPrefix(d.Id(), "/subscriptions/") { id, err := shares.ParseShareID(d.Id(), storageClient.StorageDomainSuffix) if err != nil { return err @@ -590,7 +582,7 @@ func resourceStorageShareDelete(d *pluginsdk.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - if !features.FivePointOhBeta() { + if !features.FivePointOhBeta() && !strings.HasPrefix(d.Id(), "/subscriptions/") { storageClient := meta.(*clients.Client).Storage id, err := shares.ParseShareID(d.Id(), storageClient.StorageDomainSuffix) if err != nil {