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_binary: New resource #12369

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 122 additions & 2 deletions azurerm/internal/services/datafactory/data_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,35 @@ func expandDataFactoryDatasetLocation(d *pluginsdk.ResourceData) datafactory.Bas
return expandDataFactoryDatasetAzureBlobFSLocation(d)
}

if _, ok := d.GetOk("sftp_server_location"); ok {
return expandDataFactoryDatasetSFTPServerLocation(d)
}

return nil
}

func expandDataFactoryDatasetSFTPServerLocation(d *pluginsdk.ResourceData) datafactory.BasicDatasetLocation {
sftpServerLocations := d.Get("sftp_server_location").([]interface{})
if len(sftpServerLocations) == 0 || sftpServerLocations[0] == nil {
return nil
}
props := sftpServerLocations[0].(map[string]interface{})
path := props["path"].(string)
filename := props["filename"].(string)

sftpServerLocation := datafactory.SftpLocation{
FolderPath: path,
FileName: filename,
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
}
return sftpServerLocation
}

func expandDataFactoryDatasetHttpServerLocation(d *pluginsdk.ResourceData) datafactory.BasicDatasetLocation {
props := d.Get("http_server_location").([]interface{})[0].(map[string]interface{})
httpServerLocations := d.Get("http_server_location").([]interface{})
if len(httpServerLocations) == 0 || httpServerLocations[0] == nil {
return nil
}
props := httpServerLocations[0].(map[string]interface{})
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
relativeUrl := props["relative_url"].(string)
path := props["path"].(string)
filename := props["filename"].(string)
Expand All @@ -301,7 +325,11 @@ func expandDataFactoryDatasetHttpServerLocation(d *pluginsdk.ResourceData) dataf
}

func expandDataFactoryDatasetAzureBlobStorageLocation(d *pluginsdk.ResourceData) datafactory.BasicDatasetLocation {
props := d.Get("azure_blob_storage_location").([]interface{})[0].(map[string]interface{})
azureBlobStorageLocations := d.Get("azure_blob_storage_location").([]interface{})
if len(azureBlobStorageLocations) == 0 || azureBlobStorageLocations[0] == nil {
return nil
}
props := azureBlobStorageLocations[0].(map[string]interface{})
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
container := props["container"].(string)
path := props["path"].(string)
filename := props["filename"].(string)
Expand Down Expand Up @@ -403,3 +431,95 @@ func flattenDataFactoryDatasetAzureBlobFSLocation(input *datafactory.AzureBlobFS
},
}
}
func flattenDataFactoryDatasetSFTPLocation(input *datafactory.SftpLocation) []interface{} {
if input == nil {
return nil
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
}
result := make(map[string]interface{})

if input.FolderPath != nil {
result["path"] = input.FolderPath
}
if input.FileName != nil {
result["filename"] = input.FileName
}

return []interface{}{result}
}

func flattenDataFactoryDatasetCompression(input datafactory.BasicDatasetCompression) []interface{} {
if input == nil {
return nil
aristosvo marked this conversation as resolved.
Show resolved Hide resolved
}
result := make(map[string]interface{})

if compression, ok := input.AsDatasetBZip2Compression(); ok {
result["type"] = compression.Type
}
if compression, ok := input.AsDatasetDeflateCompression(); ok {
result["type"] = compression.Type
}
if compression, ok := input.AsDatasetGZipCompression(); ok {
result["type"] = compression.Type
result["level"] = compression.Level
}
if compression, ok := input.AsDatasetTarCompression(); ok {
result["type"] = compression.Type
}
if compression, ok := input.AsDatasetTarGZipCompression(); ok {
result["type"] = compression.Type
result["level"] = compression.Level
}
if compression, ok := input.AsDatasetZipDeflateCompression(); ok {
result["type"] = compression.Type
result["level"] = compression.Level
}

return []interface{}{result}
}

func expandDataFactoryDatasetCompression(d *pluginsdk.ResourceData) datafactory.BasicDatasetCompression {
compression := d.Get("compression").([]interface{})
if len(compression) == 0 || compression[0] == nil {
return nil
}
props := compression[0].(map[string]interface{})
level := props["level"].(string)
compressionType := props["type"].(string)

if datafactory.TypeBasicDatasetCompression(compressionType) == datafactory.TypeBasicDatasetCompressionTypeBZip2 {
return datafactory.DatasetBZip2Compression{
Type: datafactory.TypeBasicDatasetCompression(compressionType),
}
}
if datafactory.TypeBasicDatasetCompression(compressionType) == datafactory.TypeBasicDatasetCompressionTypeDeflate {
return datafactory.DatasetDeflateCompression{
Type: datafactory.TypeBasicDatasetCompression(compressionType),
}
}
if datafactory.TypeBasicDatasetCompression(compressionType) == datafactory.TypeBasicDatasetCompressionTypeGZip {
return datafactory.DatasetGZipCompression{
Type: datafactory.TypeBasicDatasetCompression(compressionType),
Level: level,
}
}
if datafactory.TypeBasicDatasetCompression(compressionType) == datafactory.TypeBasicDatasetCompressionTypeTar {
return datafactory.DatasetTarCompression{
Type: datafactory.TypeBasicDatasetCompression(compressionType),
}
}
if datafactory.TypeBasicDatasetCompression(compressionType) == datafactory.TypeBasicDatasetCompressionTypeTarGZip {
return datafactory.DatasetTarGZipCompression{
Type: datafactory.TypeBasicDatasetCompression(compressionType),
Level: level,
}
}
if datafactory.TypeBasicDatasetCompression(compressionType) == datafactory.TypeBasicDatasetCompressionTypeZipDeflate {
return datafactory.DatasetZipDeflateCompression{
Type: datafactory.TypeBasicDatasetCompression(compressionType),
Level: level,
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func resourceDataFactoryDatasetAzureBlob() *pluginsdk.Resource {
ValidateFunc: validate.LinkedServiceDatasetName,
},

// TODO: replace with `data_factory_id` in 3.0
"data_factory_name": {
Type: pluginsdk.TypeString,
Required: true,
Expand Down
Loading