diff --git a/azurerm/internal/services/datashare/data_source_data_share_dataset_data_lake_gen1.go b/azurerm/internal/services/datashare/data_source_data_share_dataset_data_lake_gen1.go new file mode 100644 index 000000000000..5e957ce0bb8f --- /dev/null +++ b/azurerm/internal/services/datashare/data_source_data_share_dataset_data_lake_gen1.go @@ -0,0 +1,111 @@ +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(), + }, + + "data_share_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.DataShareID, + }, + + "data_lake_store_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("data_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("data_share_id", shareID) + + switch resp := respModel.Value.(type) { + case datashare.ADLSGen1FileDataSet: + if props := resp.ADLSGen1FileProperties; props != nil { + if props.SubscriptionID != nil && props.ResourceGroup != nil && props.AccountName != nil { + d.Set("data_lake_store_id", fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataLakeStore/accounts/%s", *props.SubscriptionID, *props.ResourceGroup, *props.AccountName)) + } + 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 { + if props.SubscriptionID != nil && props.ResourceGroup != nil && props.AccountName != nil { + d.Set("data_lake_store_id", fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataLakeStore/accounts/%s", *props.SubscriptionID, *props.ResourceGroup, *props.AccountName)) + } + 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 +} diff --git a/azurerm/internal/services/datashare/registration.go b/azurerm/internal/services/datashare/registration.go index 23a8546de59d..8c181d951f77 100644 --- a/azurerm/internal/services/datashare/registration.go +++ b/azurerm/internal/services/datashare/registration.go @@ -19,9 +19,10 @@ func (r Registration) WebsiteCategories() []string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_data_share_account": dataSourceDataShareAccount(), - "azurerm_data_share": dataSourceDataShare(), - "azurerm_data_share_dataset_blob_storage": dataSourceDataShareDatasetBlobStorage(), + "azurerm_data_share_account": dataSourceDataShareAccount(), + "azurerm_data_share": dataSourceDataShare(), + "azurerm_data_share_dataset_blob_storage": dataSourceDataShareDatasetBlobStorage(), + "azurerm_data_share_dataset_data_lake_gen1": dataSourceDataShareDatasetDataLakeGen1(), } } diff --git a/azurerm/internal/services/datashare/tests/data_source_data_share_dataset_data_lake_gen1_test.go b/azurerm/internal/services/datashare/tests/data_source_data_share_dataset_data_lake_gen1_test.go new file mode 100644 index 000000000000..ff2489c2c0e3 --- /dev/null +++ b/azurerm/internal/services/datashare/tests/data_source_data_share_dataset_data_lake_gen1_test.go @@ -0,0 +1,42 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMDataShareDatasetDataLakeGen1_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_data_share_dataset_data_lake_gen1", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataShareDataSetDestroy("azurerm_data_share_dataset_data_lake_gen1"), + Steps: []resource.TestStep{ + { + Config: testAccDataSourceDataShareDatasetDataLakeGen1_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataShareDataSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "data_lake_store_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "file_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), + ), + }, + }, + }) +} + +func testAccDataSourceDataShareDatasetDataLakeGen1_basic(data acceptance.TestData) string { + config := testAccAzureRMDataShareDataSetDataLakeGen1File_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_data_share_dataset_data_lake_gen1" "test" { + name = azurerm_data_share_dataset_data_lake_gen1.test.name + data_share_id = azurerm_data_share_dataset_data_lake_gen1.test.data_share_id +} +`, config) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 3819ee37bd01..77db6ec2fba9 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -209,6 +209,10 @@ azurerm_data_share_dataset_blob_storage +
  • + azurerm_data_share_dataset_data_lake_gen1 +
  • +
  • azurerm_dedicated_host
  • diff --git a/website/docs/d/data_share_dataset_data_lake_gen1.html.markdown b/website/docs/d/data_share_dataset_data_lake_gen1.html.markdown new file mode 100644 index 000000000000..a087d1f75180 --- /dev/null +++ b/website/docs/d/data_share_dataset_data_lake_gen1.html.markdown @@ -0,0 +1,56 @@ +--- +subcategory: "Data Share" +layout: "azurerm" +page_title: "Azure Resource Manager: Data Source: azurerm_data_share_dataset_data_lake_gen1" +description: |- + Gets information about an existing DataShareDataLakeGen1Dataset. +--- + +# Data Source: azurerm_data_share_dataset_data_lake_gen1 + +Use this data source to access information about an existing DataShareDataLakeGen1Dataset. + +## Example Usage + +```hcl +provider "azurerm" { + features {} +} + +data "azurerm_data_share_dataset_data_lake_gen1" "example" { + name = "example-dsdsdlg1" + data_share_id = "example-share-id" +} + +output "id" { + value = data.azurerm_data_share_dataset_data_lake_gen1.example.id +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Data Share Data Lake Gen1 Dataset. + +* `data_share_id` - (Required) The resource ID of the Data Share where this Data Share Data Lake Gen1 Dataset should be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The resource ID of the Data Share Data Lake Gen1 Dataset. + +* `data_lake_store_id` - The resource ID of the Data Lake Store to be shared with the receiver. + +* `display_name` - The displayed name of the Data Share Dataset. + +* `file_name` - The file name of the data lake store to be shared with the receiver. + +* `folder_path` - The folder path of the data lake store to be shared with the receiver. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `read` - (Defaults to 5 minutes) Used when retrieving the DataShareDataLakeGen1Dataset.