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_data_factory_dataset_parquet - Support azure_blob_fs_location #23261

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 16 additions & 26 deletions internal/services/datafactory/data_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,14 @@ func expandDataFactoryDatasetAzureBlobFSLocation(d *pluginsdk.ResourceData) data

props := azureBlobFsLocations[0].(map[string]interface{})

blobStorageLocation := datafactory.AzureBlobFSLocation{
FileSystem: props["file_system"].(string),
blobFSLocation := datafactory.AzureBlobFSLocation{
Type: datafactory.TypeBasicDatasetLocationTypeAzureBlobFSLocation,
}
if path := props["path"].(string); len(path) > 0 {
blobStorageLocation.FolderPath = path
}
if filename := props["filename"].(string); len(filename) > 0 {
blobStorageLocation.FileName = filename
FileSystem: expandDataFactoryExpressionResultType(props["file_system"].(string), props["dynamic_file_system_enabled"].(bool)),
FolderPath: expandDataFactoryExpressionResultType(props["path"].(string), props["dynamic_path_enabled"].(bool)),
FileName: expandDataFactoryExpressionResultType(props["filename"].(string), props["dynamic_filename_enabled"].(bool)),
}

return blobStorageLocation
return blobFSLocation
}

func flattenDataFactoryDatasetHTTPServerLocation(input *datafactory.HTTPServerLocation) []interface{} {
Expand Down Expand Up @@ -490,31 +486,25 @@ func flattenDataFactoryDatasetAzureBlobFSLocation(input *datafactory.AzureBlobFS
if input == nil {
return []interface{}{}
}
result := make(map[string]interface{})

fileSystem, path, fileName := "", "", ""
if input.FileSystem != nil {
if v, ok := input.FileSystem.(string); ok {
fileSystem = v
}
fileSystem, dynamicFileSystemEnabled := flattenDataFactoryExpressionResultType(input.FileSystem)
result["file_system"] = fileSystem
result["dynamic_file_system_enabled"] = dynamicFileSystemEnabled
}
if input.FolderPath != nil {
if v, ok := input.FolderPath.(string); ok {
path = v
}
path, dynamicPathEnabled := flattenDataFactoryExpressionResultType(input.FolderPath)
result["path"] = path
result["dynamic_path_enabled"] = dynamicPathEnabled
}
if input.FileName != nil {
if v, ok := input.FileName.(string); ok {
fileName = v
}
filename, dynamicFilenameEnabled := flattenDataFactoryExpressionResultType(input.FileName)
result["filename"] = filename
result["dynamic_filename_enabled"] = dynamicFilenameEnabled
}

return []interface{}{
map[string]interface{}{
"file_system": fileSystem,
"path": path,
"filename": fileName,
},
}
return []interface{}{result}
}

func flattenDataFactoryDatasetSFTPLocation(input *datafactory.SftpLocation) []interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,54 @@ func resourceDataFactoryDatasetParquet() *pluginsdk.Resource {
},
},

// Parquet Specific Field, one option for 'location'
"azure_blob_fs_location": {
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
ExactlyOneOf: []string{"azure_blob_fs_location", "azure_blob_storage_location", "http_server_location"},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"file_system": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"dynamic_file_system_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"path": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"dynamic_path_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"filename": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"dynamic_filename_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
},
},

// Parquet Specific Field, one option for 'location'
"azure_blob_storage_location": {
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: []string{"http_server_location"},
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
ExactlyOneOf: []string{"azure_blob_fs_location", "azure_blob_storage_location", "http_server_location"},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"container": {
Expand Down Expand Up @@ -156,10 +198,10 @@ func resourceDataFactoryDatasetParquet() *pluginsdk.Resource {

// Parquet Specific Field, one option for 'location'
"http_server_location": {
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: []string{"azure_blob_storage_location"},
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
ExactlyOneOf: []string{"azure_blob_fs_location", "azure_blob_storage_location", "http_server_location"},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"relative_url": {
Expand Down Expand Up @@ -270,7 +312,7 @@ func resourceDataFactoryDatasetParquetCreateUpdate(d *pluginsdk.ResourceData, me

location := expandDataFactoryDatasetLocation(d)
if location == nil {
return fmt.Errorf("One of `http_server_location`, `azure_blob_storage_location` must be specified to create a DataFactory Parquet Dataset")
return fmt.Errorf("One of `http_server_location`, `azure_blob_fs_location`, `azure_blob_storage_location` must be specified to create a DataFactory Parquet Dataset")
}

parquetDatasetProperties := datafactory.ParquetDatasetTypeProperties{
Expand Down Expand Up @@ -394,6 +436,11 @@ func resourceDataFactoryDatasetParquetRead(d *pluginsdk.ResourceData, meta inter
return fmt.Errorf("setting `azure_blob_storage_location` for Data Factory Parquet Dataset %s", err)
}
}
if azureBlobFSLocation, ok := properties.Location.AsAzureBlobFSLocation(); ok {
if err := d.Set("azure_blob_fs_location", flattenDataFactoryDatasetAzureBlobFSLocation(azureBlobFSLocation)); err != nil {
return fmt.Errorf("setting `azure_blob_fs_location` for Data Factory Parquet Dataset %s", err)
}
}

compressionCodec, ok := properties.CompressionCodec.(string)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,50 @@ func TestAccDataFactoryDatasetParquet_blobDynamicContainer(t *testing.T) {
})
}

func TestAccDataFactoryDatasetParquet_blobFS(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_parquet", "test")
r := DatasetParquetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.blobFS(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccDataFactoryDatasetParquet_blobFSDynamicPath(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_parquet", "test")
r := DatasetParquetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.blobFS(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.blobFSDynamicPath(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.blobFS(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t DatasetParquetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.DataSetID(state.ID)
if err != nil {
Expand Down Expand Up @@ -395,3 +439,110 @@ resource "azurerm_data_factory_dataset_parquet" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (DatasetParquetResource) blobFS(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-df-%d"
location = "%s"
}

resource "azurerm_storage_account" "test" {
name = "acctestdf%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
account_tier = "Standard"
account_replication_type = "GRS"
is_hns_enabled = true
}

resource "azurerm_storage_container" "test" {
name = "content"
storage_account_name = azurerm_storage_account.test.name
container_access_type = "private"
}

resource "azurerm_data_factory" "test" {
name = "acctestdf%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}


resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" {
name = "acctestlsdls%d"
data_factory_id = azurerm_data_factory.test.id
url = azurerm_storage_account.test.primary_dfs_endpoint
storage_account_key = azurerm_storage_account.test.primary_access_key
}

resource "azurerm_data_factory_dataset_parquet" "test" {
name = "acctestds%d"
data_factory_id = azurerm_data_factory.test.id
linked_service_name = azurerm_data_factory_linked_service_data_lake_storage_gen2.test.name

azure_blob_fs_location {
file_system = azurerm_storage_container.test.name
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (DatasetParquetResource) blobFSDynamicPath(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-df-%d"
location = "%s"
}

resource "azurerm_storage_account" "test" {
name = "acctestdf%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
account_tier = "Standard"
account_replication_type = "GRS"
is_hns_enabled = true
}

resource "azurerm_storage_container" "test" {
name = "content"
storage_account_name = azurerm_storage_account.test.name
container_access_type = "private"
}

resource "azurerm_data_factory" "test" {
name = "acctestdf%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}


resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" {
name = "acctestlsdls%d"
data_factory_id = azurerm_data_factory.test.id
url = azurerm_storage_account.test.primary_dfs_endpoint
storage_account_key = azurerm_storage_account.test.primary_access_key
}

resource "azurerm_data_factory_dataset_parquet" "test" {
name = "acctestds%d"
data_factory_id = azurerm_data_factory.test.id
linked_service_name = azurerm_data_factory_linked_service_data_lake_storage_gen2.test.name

azure_blob_fs_location {
file_system = azurerm_storage_container.test.name
dynamic_file_system_enabled = true
path = "@concat('foo/bar/',formatDateTime(convertTimeZone(utcnow(),'UTC','W. Europe Standard Time'),'yyyy-MM-dd'))"
dynamic_path_enabled = true
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
26 changes: 22 additions & 4 deletions website/docs/r/data_factory_dataset_parquet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ The following supported locations for a Parquet Dataset:

* `http_server_location` - (Optional) A `http_server_location` block as defined below.

* `azure_blob_fs_location` - (Optional) A `azure_blob_fs_location` block as defined below.

* `azure_blob_storage_location` - (Optional) A `azure_blob_storage_location` block as defined below.

The following supported arguments are specific to Parquet Dataset:
Expand Down Expand Up @@ -103,19 +105,35 @@ A `http_server_location` block supports the following:
* `path` - (Optional) The folder path to the file on the web server.
---

A `azure_blob_fs_location` block supports the following:

* `file_system` - (Required) The container on the Azure Data Lake Storage Account hosting the file.

* `dynamic_file_system_enabled` - (Optional) Is the `file_system` using dynamic expression, function or system variables? Defaults to `false`.

* `path` - (Optional) The folder path to the file on the Azure Data Lake Storage Account.

* `dynamic_path_enabled` - (Optional) Is the `path` using dynamic expression, function or system variables? Defaults to `false`.

* `filename` - (Optional) The filename of the file on the Azure Data Lake Storage Account.

* `dynamic_filename_enabled` - (Optional) Is the `filename` using dynamic expression, function or system variables? Defaults to `false`.

---

A `azure_blob_storage_location` block supports the following:

* `container` - (Required) The container on the Azure Blob Storage Account hosting the file.

* `filename` - (Optional) The filename of the file on the web server.

* `dynamic_container_enabled` - (Optional) Is the `container` using dynamic expression, function or system variables? Defaults to `false`.

* `path` - (Optional) The folder path to the file on the Azure Blob Storage Account.

* `dynamic_path_enabled` - (Optional) Is the `path` using dynamic expression, function or system variables? Defaults to `false`.

* `dynamic_filename_enabled` - (Optional) Is the `filename` using dynamic expression, function or system variables? Defaults to `false`.
* `filename` - (Optional) The filename of the file on the Azure Blob Storage Account.

* `path` - (Optional) The folder path to the file on the web server.
* `dynamic_filename_enabled` - (Optional) Is the `filename` using dynamic expression, function or system variables? Defaults to `false`.

## Attributes Reference

Expand Down