-
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.
Merge pull request #7107 from yupwei68/wyp-datashare-dataset-blob
- Loading branch information
Showing
13 changed files
with
1,163 additions
and
4 deletions.
There are no files selected for viewing
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
144 changes: 144 additions & 0 deletions
144
azurerm/internal/services/datashare/data_source_data_share_dataset_blob_storage.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,144 @@ | ||
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 dataSourceDataShareDatasetBlobStorage() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmDataShareDatasetBlobStorageRead, | ||
|
||
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, | ||
}, | ||
|
||
"container_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"storage_account": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"subscription_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"file_path": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"folder_path": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"display_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmDataShareDatasetBlobStorageRead(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 Blob Storage 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 reading DataShare Blob Storage 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.BlobDataSet: | ||
if props := resp.BlobProperties; props != nil { | ||
d.Set("container_name", props.ContainerName) | ||
if err := d.Set("storage_account", flattenAzureRmDataShareDataSetBlobStorageAccount(props.StorageAccountName, props.ResourceGroup, props.SubscriptionID)); err != nil { | ||
return fmt.Errorf("setting `storage_account`: %+v", err) | ||
} | ||
d.Set("file_path", props.FilePath) | ||
d.Set("display_name", props.DataSetID) | ||
} | ||
|
||
case datashare.BlobFolderDataSet: | ||
if props := resp.BlobFolderProperties; props != nil { | ||
d.Set("container_name", props.ContainerName) | ||
if err := d.Set("storage_account", flattenAzureRmDataShareDataSetBlobStorageAccount(props.StorageAccountName, props.ResourceGroup, props.SubscriptionID)); err != nil { | ||
return fmt.Errorf("setting `storage_account`: %+v", err) | ||
} | ||
d.Set("folder_path", props.Prefix) | ||
d.Set("display_name", props.DataSetID) | ||
} | ||
|
||
case datashare.BlobContainerDataSet: | ||
if props := resp.BlobContainerProperties; props != nil { | ||
d.Set("container_name", props.ContainerName) | ||
if err := d.Set("storage_account", flattenAzureRmDataShareDataSetBlobStorageAccount(props.StorageAccountName, props.ResourceGroup, props.SubscriptionID)); err != nil { | ||
return fmt.Errorf("setting `storage_account`: %+v", err) | ||
} | ||
d.Set("display_name", props.DataSetID) | ||
} | ||
|
||
default: | ||
return fmt.Errorf("data share dataset %q (Resource Group %q / accountName %q / shareName %q) is not a blob storage 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package helper | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/datashare/mgmt/2019-11-01/datashare" | ||
) | ||
|
||
func GetAzurermDataShareDataSetId(dataset datashare.BasicDataSet) *string { | ||
if dataset == nil { | ||
return nil | ||
} | ||
switch t := dataset.(type) { | ||
case datashare.BlobDataSet: | ||
return t.ID | ||
case datashare.BlobFolderDataSet: | ||
return t.ID | ||
case datashare.BlobContainerDataSet: | ||
return t.ID | ||
case datashare.ADLSGen2FileDataSet: | ||
return t.ID | ||
case datashare.ADLSGen2FolderDataSet: | ||
return t.ID | ||
case datashare.ADLSGen2FileSystemDataSet: | ||
return t.ID | ||
case datashare.ADLSGen1FolderDataSet: | ||
return t.ID | ||
case datashare.ADLSGen1FileDataSet: | ||
return t.ID | ||
case datashare.KustoClusterDataSet: | ||
return t.ID | ||
case datashare.KustoDatabaseDataSet: | ||
return t.ID | ||
case datashare.SQLDWTableDataSet: | ||
return t.ID | ||
case datashare.SQLDBTableDataSet: | ||
return t.ID | ||
default: | ||
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
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
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
Oops, something went wrong.