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

[Enhance] -azurerm_machine_learning_datastore_datalake_gen2 - Support crosse sub storage account #28123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/machinelearning/validate"
storageAccountHelper "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/client"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand Down Expand Up @@ -176,9 +177,11 @@ func (r MachineLearningDataStoreDataLakeGen2) Create() sdk.ResourceFunc {
}

props := &datastore.AzureDataLakeGen2Datastore{
SubscriptionId: &containerId.SubscriptionId,
ResourceGroup: &containerId.ResourceGroupName,
AccountName: containerId.StorageAccountName,
Endpoint: pointer.To(metadata.Client.Storage.StorageDomainSuffix),
Filesystem: containerId.ContainerName,
Endpoint: pointer.To(metadata.Client.Storage.StorageDomainSuffix),
Description: utils.String(model.Description),
ServiceDataAccessAuthIdentity: pointer.To(datastore.ServiceDataAccessAuthIdentity(model.ServiceDataIdentity)),
Tags: pointer.To(model.Tags),
Expand Down Expand Up @@ -241,6 +244,8 @@ func (r MachineLearningDataStoreDataLakeGen2) Update() sdk.ResourceFunc {
}

props := &datastore.AzureDataLakeGen2Datastore{
SubscriptionId: &containerId.SubscriptionId,
ResourceGroup: &containerId.ResourceGroupName,
AccountName: containerId.StorageAccountName,
Filesystem: containerId.ContainerName,
Description: utils.String(state.Description),
Expand Down Expand Up @@ -311,8 +316,13 @@ func (r MachineLearningDataStoreDataLakeGen2) Read() sdk.ResourceFunc {
serviceDataIdentity = string(*v)
}
model.ServiceDataIdentity = serviceDataIdentity

storageAccount, err := storageClient.FindAccount(ctx, subscriptionId, data.AccountName)
var storageAccount *storageAccountHelper.AccountDetails
// try to get storage account from the storage subscription if subscription exists otherwise delegate to the default subscription
if data.SubscriptionId != nil && *data.SubscriptionId != "" {
storageAccount, err = storageClient.FindAccount(ctx, *data.SubscriptionId, data.AccountName)
} else {
storageAccount, err = storageClient.FindAccount(ctx, subscriptionId, data.AccountName)
}
if err != nil {
return fmt.Errorf("retrieving Account %q for Data Lake Gen2 File System %q: %s", data.AccountName, data.Filesystem, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package machinelearning_test
import (
"context"
"fmt"
"os"
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
Expand Down Expand Up @@ -49,6 +50,25 @@ func TestAccMachineLearningDataStoreDataLakeGen2_spn(t *testing.T) {
})
}

func TestAccMachineLearningDataStoreDataLakeGen2_crossSubStorageAccount(t *testing.T) {
if os.Getenv("ARM_TEST_ACC_DATASTORE_GEN2_CROSS_SUB_SA_CONTAINER") == "" {
t.Skip("ARM_TEST_ACC_DATASTORE_GEN2_CROSS_SUB_SA_CONTAINER not set")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this and use ARM_SUBSCRIPTION_ID_ALT instead for an alternative subscription id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catriona-m test case updated.


data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_datalake_gen2", "test")
r := MachineLearningDataStoreDataLakeGen2{}

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

func TestAccMachineLearningDataStoreDataLakeGen2_Update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_datalake_gen2", "test")
r := MachineLearningDataStoreDataLakeGen2{}
Expand Down Expand Up @@ -156,6 +176,30 @@ resource "azurerm_machine_learning_datastore_datalake_gen2" "test" {
`, template, data.RandomInteger)
}

func (r MachineLearningDataStoreDataLakeGen2) dataLakeGen2CrossSubStorageAccount(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s

resource "azurerm_storage_container" "test" {
name = "acctestcontainer%[2]d"
storage_account_name = azurerm_storage_account.test.name
container_access_type = "private"
}

resource "azurerm_machine_learning_datastore_datalake_gen2" "test" {
name = "accdatastore%[2]d"
workspace_id = azurerm_machine_learning_workspace.test.id
storage_container_id = azurerm_storage_container.test.resource_manager_id
}

resource "azurerm_machine_learning_datastore_datalake_gen2" "crosssub" {
name = "accdcrosssub%[2]d"
workspace_id = azurerm_machine_learning_workspace.test.id
storage_container_id = "%[3]s"
}`, template, data.RandomInteger, os.Getenv("ARM_TEST_ACC_DATASTORE_GEN2_CROSS_SUB_SA_CONTAINER"))
}

func (r MachineLearningDataStoreDataLakeGen2) requiresImport(data acceptance.TestData) string {
template := r.dataLakeGen2Basic(data)
return fmt.Sprintf(`
Expand Down
Loading