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

New resource/datasource azurerm_data_share_dataset #7064

Closed
wants to merge 7 commits into from
Closed
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
5 changes: 5 additions & 0 deletions azurerm/internal/services/datashare/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type Client struct {
AccountClient *datashare.AccountsClient
DataSetClient *datashare.DataSetsClient
SharesClient *datashare.SharesClient
SynchronizationClient *datashare.SynchronizationSettingsClient
}
Expand All @@ -15,6 +16,9 @@ func NewClient(o *common.ClientOptions) *Client {
accountClient := datashare.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&accountClient.Client, o.ResourceManagerAuthorizer)

dataSetClient := datashare.NewDataSetsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&dataSetClient.Client, o.ResourceManagerAuthorizer)

sharesClient := datashare.NewSharesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&sharesClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -23,6 +27,7 @@ func NewClient(o *common.ClientOptions) *Client {

return &Client{
AccountClient: &accountClient,
DataSetClient: &dataSetClient,
SharesClient: &sharesClient,
SynchronizationClient: &synchronizationSettingsClient,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package datashare

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/helper"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
)

func dataSourceDataShareDatasetBlobStorage() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDataShareDatasetBlobStorageRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.DatashareDataSetName(),
},

"share_id": {
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.DataShareID,
},

"container_name": {
Type: schema.TypeString,
Computed: true,
},

"storage_account_name": {
Type: schema.TypeString,
Computed: true,
},

"storage_account_resource_group_name": {
Type: schema.TypeString,
Computed: true,
},

"storage_account_subscription_id": {
Type: schema.TypeString,
Computed: true,
},

"file_path": {
Type: schema.TypeString,
Computed: true,
},

"folder_path": {
Type: schema.TypeString,
Computed: true,
},

"display_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceArmDataShareDatasetBlobStorageRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataShare.DataSetClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
shareID := d.Get("share_id").(string)
shareId, err := parse.DataShareID(shareID)
if err != nil {
return err
}

respModel, err := client.Get(ctx, shareId.ResourceGroup, shareId.AccountName, shareId.Name, name)
if err != nil {
return fmt.Errorf("retrieving DataShare Blob Storage DataSet %q (Resource Group %q / accountName %q / shareName %q): %+v", name, shareId.ResourceGroup, shareId.AccountName, shareId.Name, err)
}

respId := helper.GetAzurermDataShareDataSetId(respModel.Value)
if respId == nil || *respId == "" {
return fmt.Errorf("empty or nil ID returned for reading DataShare Blob Storage DataSet %q (Resource Group %q / accountName %q / shareName %q)", name, shareId.ResourceGroup, shareId.AccountName, shareId.Name)
}

d.SetId(*respId)
d.Set("name", name)
d.Set("share_id", shareID)

switch resp := respModel.Value.(type) {
case datashare.BlobDataSet:
if props := resp.BlobProperties; props != nil {
d.Set("container_name", props.ContainerName)
d.Set("storage_account_name", props.StorageAccountName)
d.Set("storage_account_resource_group_name", props.ResourceGroup)
d.Set("storage_account_subscription_id", props.SubscriptionID)
d.Set("file_path", props.FilePath)
d.Set("display_name", props.DataSetID)
}

case datashare.BlobFolderDataSet:
if props := resp.BlobFolderProperties; props != nil {
d.Set("container_name", props.ContainerName)
d.Set("storage_account_name", props.StorageAccountName)
d.Set("storage_account_resource_group_name", props.ResourceGroup)
d.Set("storage_account_subscription_id", props.SubscriptionID)
d.Set("folder_path", props.Prefix)
d.Set("display_name", props.DataSetID)
}

case datashare.BlobContainerDataSet:
if props := resp.BlobContainerProperties; props != nil {
d.Set("container_name", props.ContainerName)
d.Set("storage_account_name", props.StorageAccountName)
d.Set("storage_account_resource_group_name", props.ResourceGroup)
d.Set("storage_account_subscription_id", props.SubscriptionID)
d.Set("display_name", props.DataSetID)
}

default:
return fmt.Errorf("data share dataset %q (Resource Group %q / accountName %q / shareName %q) is not a blob storage dataset", name, shareId.ResourceGroup, shareId.AccountName, shareId.Name)
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package datashare

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/helper"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datashare/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
)

func dataSourceDataShareDatasetDataLakeGen1() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDataShareDatasetDataLakeGen1Read,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.DatashareDataSetName(),
},

"share_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.DataShareID,
},

"data_lake_store_name": {
Type: schema.TypeString,
Computed: true,
},

"data_lake_store_resource_group_name": {
Type: schema.TypeString,
Computed: true,
},

"data_lake_store_subscription_id": {
Type: schema.TypeString,
Computed: true,
},

"folder_path": {
Type: schema.TypeString,
Computed: true,
},

"file_name": {
Type: schema.TypeString,
Computed: true,
},

"display_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceArmDataShareDatasetDataLakeGen1Read(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataShare.DataSetClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
shareID := d.Get("share_id").(string)
shareId, err := parse.DataShareID(shareID)
if err != nil {
return err
}

respModel, err := client.Get(ctx, shareId.ResourceGroup, shareId.AccountName, shareId.Name, name)
if err != nil {
return fmt.Errorf("retrieving DataShare Data Lake Gen1 DataSet %q (Resource Group %q / accountName %q / shareName %q): %+v", name, shareId.ResourceGroup, shareId.AccountName, shareId.Name, err)
}

respId := helper.GetAzurermDataShareDataSetId(respModel.Value)
if respId == nil || *respId == "" {
return fmt.Errorf("empty or nil ID returned for DataShare Data Lake Gen1 DataSet %q (Resource Group %q / accountName %q / shareName %q)", name, shareId.ResourceGroup, shareId.AccountName, shareId.Name)
}

d.SetId(*respId)
d.Set("name", name)
d.Set("share_id", shareID)

switch resp := respModel.Value.(type) {
case datashare.ADLSGen1FileDataSet:
if props := resp.ADLSGen1FileProperties; props != nil {
d.Set("data_lake_store_name", props.AccountName)
d.Set("data_lake_store_resource_group_name", props.ResourceGroup)
d.Set("data_lake_store_subscription_id", props.SubscriptionID)
d.Set("folder_path", props.FolderPath)
d.Set("file_name", props.FileName)
d.Set("display_name", props.DataSetID)
}

case datashare.ADLSGen1FolderDataSet:
if props := resp.ADLSGen1FolderProperties; props != nil {
d.Set("data_lake_store_name", props.AccountName)
d.Set("data_lake_store_resource_group_name", props.ResourceGroup)
d.Set("data_lake_store_subscription_id", props.SubscriptionID)
d.Set("folder_path", props.FolderPath)
d.Set("display_name", props.DataSetID)
}

default:
return fmt.Errorf("data share dataset %q (Resource Group %q / accountName %q / shareName %q) is not a datalake store gen1 dataset", name, shareId.ResourceGroup, shareId.AccountName, shareId.Name)
}

return nil
}
Loading