diff --git a/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource.go b/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource.go index 9e33e6a531d5..bccac3ed54a5 100644 --- a/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource.go +++ b/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource.go @@ -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 { @@ -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)), @@ -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 { @@ -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)), @@ -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() diff --git a/website/docs/r/machine_learning_datastore_datalake_gen2.html.markdown b/website/docs/r/machine_learning_datastore_datalake_gen2.html.markdown index d25543c92725..7b0a7b74b4f2 100644 --- a/website/docs/r/machine_learning_datastore_datalake_gen2.html.markdown +++ b/website/docs/r/machine_learning_datastore_datalake_gen2.html.markdown @@ -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.