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_share_[directory|file] - Deprecate storage_share_id in favor of storage_share_url #28457

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
89 changes: 64 additions & 25 deletions internal/services/storage/storage_share_directory_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/helpers"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate"
Expand All @@ -25,6 +26,45 @@ import (
)

func resourceStorageShareDirectory() *pluginsdk.Resource {
schema := map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.StorageShareDirectoryName,
},

"storage_share_url": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: storageValidate.StorageShareDataPlaneID,
},

"metadata": MetaDataSchema(),
}

if !features.FivePointOhBeta() {
// Keep the storage_share_id for compatibility.
schema["storage_share_id"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: storageValidate.StorageShareDataPlaneID,
ExactlyOneOf: []string{"storage_share_id", "storage_share_url"},
Deprecated: "This property has been deprecated in favour of `storage_share_url` and will be removed in version 5.0 of the Provider.",
}
schema["storage_share_url"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: storageValidate.StorageShareDataPlaneID,
ExactlyOneOf: []string{"storage_share_id", "storage_share_url"},
}
}

resource := &pluginsdk.Resource{
Create: resourceStorageShareDirectoryCreate,
Read: resourceStorageShareDirectoryRead,
Expand All @@ -43,23 +83,7 @@ func resourceStorageShareDirectory() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.StorageShareDirectoryName,
},

"storage_share_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: storageValidate.StorageShareDataPlaneID,
},

"metadata": MetaDataSchema(),
},
Schema: schema,
}

return resource
Expand All @@ -75,13 +99,21 @@ func resourceStorageShareDirectoryCreate(d *pluginsdk.ResourceData, meta interfa
metaDataRaw := d.Get("metadata").(map[string]interface{})
metaData := ExpandMetaData(metaDataRaw)

var storageShareId *shares.ShareId
var err error
if v, ok := d.GetOk("storage_share_id"); ok && v.(string) != "" {
storageShareId, err = shares.ParseShareID(v.(string), storageClient.StorageDomainSuffix)
if err != nil {
return err
var (
storageShareId *shares.ShareId
err error
)
if features.FivePointOhBeta() {
storageShareId, err = shares.ParseShareID(d.Get("storage_share_url").(string), storageClient.StorageDomainSuffix)
} else {
storageShareURL := d.Get("storage_share_url")
if storageShareURL == "" {
storageShareURL = d.Get("storage_share_id")
}
storageShareId, err = shares.ParseShareID(storageShareURL.(string), storageClient.StorageDomainSuffix)
}
if err != nil {
return err
}

if storageShareId == nil {
Expand Down Expand Up @@ -226,7 +258,10 @@ func resourceStorageShareDirectoryRead(d *pluginsdk.ResourceData, meta interface
}

d.Set("name", id.DirectoryPath)
d.Set("storage_share_id", storageShareId.ID())
d.Set("storage_share_url", storageShareId.ID())
if !features.FivePointOhBeta() {
d.Set("storage_share_id", d.Get("storage_share_url"))
}

if err = d.Set("metadata", FlattenMetaData(props.MetaData)); err != nil {
return fmt.Errorf("setting `metadata`: %v", err)
Expand Down Expand Up @@ -270,7 +305,11 @@ func storageShareDirectoryRefreshFunc(ctx context.Context, client *directories.C
return func() (interface{}, string, error) {
res, err := client.Get(ctx, id.ShareName, id.DirectoryPath)
if err != nil {
return nil, strconv.Itoa(res.HttpResponse.StatusCode), fmt.Errorf("retrieving %s: %v", id, err)
state := "unknown"
if res.HttpResponse != nil {
state = strconv.Itoa(res.HttpResponse.StatusCode)
}
return nil, state, fmt.Errorf("retrieving %s: %v", id, err)
}

return res, strconv.Itoa(res.HttpResponse.StatusCode), nil
Expand Down
Loading
Loading