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 data source azurerm_data_share_dataset_data_lake_gen1 #7840

Merged
merged 1 commit into from
Jul 24, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 4 additions & 3 deletions azurerm/internal/services/datashare/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@
<a href="/docs/providers/azurerm/d/data_share_dataset_blob_storage.html">azurerm_data_share_dataset_blob_storage</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/data_share_dataset_data_lake_gen1.html">azurerm_data_share_dataset_data_lake_gen1</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/dedicated_host.html">azurerm_dedicated_host</a>
</li>
Expand Down
56 changes: 56 additions & 0 deletions website/docs/d/data_share_dataset_data_lake_gen1.html.markdown
Original file line number Diff line number Diff line change
@@ -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.