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 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 @@ -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_SUBSCRIPTION_ID_ALT") == "" {
t.Skip("ARM_SUBSCRIPTION_ID_ALT not set")
}

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,64 @@ 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
}

provider "azurerm-alt" {
subscription_id = "%[3]s"

features {
key_vault {
purge_soft_delete_on_destroy = false
purge_soft_deleted_keys_on_destroy = false
}
}
}

resource "azurerm_resource_group" "testalt" {
provider = azurerm-alt
name = "acctestRG-alt-%[2]d"
location = "%[4]s"
}

resource "azurerm_storage_account" "testalt" {
provider = azurerm-alt
name = "acctestsaalt%[5]d"
location = azurerm_resource_group.testalt.location
resource_group_name = azurerm_resource_group.testalt.name
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_container" "testalt" {
provider = azurerm-alt
name = "acctestcontaineralt%[5]d"
storage_account_name = azurerm_storage_account.testalt.name
container_access_type = "private"
}

resource "azurerm_machine_learning_datastore_datalake_gen2" "crosssub" {
name = "accdcrosssub%[5]d"
workspace_id = azurerm_machine_learning_workspace.test.id
storage_container_id = azurerm_storage_container.testalt.resource_manager_id
}
`, template, data.RandomInteger, os.Getenv("ARM_SUBSCRIPTION_ID_ALT"), data.Locations.Primary, data.RandomIntOfLength(10))
}

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