-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source
azurerm_data_share_dataset_data_lake_gen1
(#7840)
Partially fix #6480 Sub PR of : #7064 === RUN TestAccDataSourceAzureRMDataShareDatasetDataLakeGen1_basic === PAUSE TestAccDataSourceAzureRMDataShareDatasetDataLakeGen1_basic === CONT TestAccDataSourceAzureRMDataShareDatasetDataLakeGen1_basic --- PASS: TestAccDataSourceAzureRMDataShareDatasetDataLakeGen1_basic (369.62s)
- Loading branch information
Showing
5 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
azurerm/internal/services/datashare/data_source_data_share_dataset_data_lake_gen1.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...m/internal/services/datashare/tests/data_source_data_share_dataset_data_lake_gen1_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
website/docs/d/data_share_dataset_data_lake_gen1.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |