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

Check storage account name in a given subscription during create and update calls for azurerm_machine_learning_datastore_datalake_gen2 resource #27256

Closed
wants to merge 2 commits into from
Closed
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
Expand Up @@ -142,6 +142,7 @@ func (r MachineLearningDataStoreDataLakeGen2) Create() sdk.ResourceFunc {
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.MachineLearning.Datastore
subscriptionId := metadata.Client.Account.SubscriptionId
storageClient := metadata.Client.Storage

var model MachineLearningDataStoreDataLakeGen2Model
if err := metadata.Decode(&model); err != nil {
Expand Down Expand Up @@ -170,6 +171,14 @@ func (r MachineLearningDataStoreDataLakeGen2) Create() sdk.ResourceFunc {
return err
}

storageAccount, err := storageClient.FindAccount(ctx, subscriptionId, containerId.StorageAccountName)
if err != nil {
return fmt.Errorf("retrieving Account %q for Data Lake Gen2 File System %q: %s", containerId.StorageAccountName, containerId.ContainerName, err)
}
if storageAccount == nil {
return fmt.Errorf("unable to locate Storage Account %q", containerId.StorageAccountName)
}

datastoreRaw := datastore.DatastoreResource{
Name: utils.String(model.Name),
Type: pointer.To(string(datastore.DatastoreTypeAzureDataLakeGenTwo)),
Expand Down Expand Up @@ -220,6 +229,8 @@ func (r MachineLearningDataStoreDataLakeGen2) Update() sdk.ResourceFunc {
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.MachineLearning.Datastore
subscriptionId := metadata.Client.Account.SubscriptionId
storageClient := metadata.Client.Storage

id, err := datastore.ParseDataStoreID(metadata.ResourceData.Id())
if err != nil {
Expand All @@ -235,6 +246,14 @@ func (r MachineLearningDataStoreDataLakeGen2) Update() sdk.ResourceFunc {
return err
}

storageAccount, err := storageClient.FindAccount(ctx, subscriptionId, containerId.StorageAccountName)
if err != nil {
return fmt.Errorf("retrieving Account %q for Data Lake Gen2 File System %q: %s", containerId.StorageAccountName, containerId.ContainerName, err)
}
if storageAccount == nil {
return fmt.Errorf("unable to locate Storage Account %q", containerId.StorageAccountName)
}

datastoreRaw := datastore.DatastoreResource{
Name: utils.String(id.DataStoreName),
Type: pointer.To(string(datastore.DatastoreTypeAzureDataLakeGenTwo)),
Expand Down Expand Up @@ -317,7 +336,7 @@ func (r MachineLearningDataStoreDataLakeGen2) Read() sdk.ResourceFunc {
return fmt.Errorf("retrieving Account %q for Data Lake Gen2 File System %q: %s", data.AccountName, data.Filesystem, err)
}
if storageAccount == nil {
return fmt.Errorf("Unable to locate Storage Account %q!", data.AccountName)
return fmt.Errorf("unable to locate Storage Account %q", data.AccountName)
}
containerId := commonids.NewStorageContainerID(storageAccount.StorageAccountId.SubscriptionId, storageAccount.StorageAccountId.ResourceGroupName, data.AccountName, data.Filesystem)
model.StorageContainerID = containerId.ID()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ The following arguments are supported:

* `storage_container_id` - (Required) The ID of the Storage Account Container. Changing this forces a new Machine Learning DataStore to be created.

~> **Note** `storage_container_id` should be in the same subscription as `azurerm_machine_learning_datastore_datalake_gen2` resource.

---
* `tenant_id` - (Optional) The ID of the Tenant which the Service Principal belongs to.

Expand Down
Loading