From 73f1be70e8a441b14b9773a670bf0ead9e7eac3b Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Thu, 30 Nov 2023 18:13:05 +0800 Subject: [PATCH] add skip_validation for mahcine learning data store --- ...learning_datastore_blobstorage_resource.go | 22 ++++++++++-- ...ing_datastore_blobstorage_resource_test.go | 36 +++++++++++++++++++ ...arning_datastore_datalake_gen2_resource.go | 22 ++++++++++-- ...g_datastore_datalake_gen2_resource_test.go | 35 ++++++++++++++++++ ...e_learning_datastore_fileshare_resource.go | 22 ++++++++++-- ...rning_datastore_fileshare_resource_test.go | 36 +++++++++++++++++++ ...arning_datastore_blobstorage.html.markdown | 2 ++ ...ning_datastore_datalake_gen2.html.markdown | 2 ++ ...learning_datastore_fileshare.html.markdown | 2 ++ 9 files changed, 170 insertions(+), 9 deletions(-) diff --git a/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource.go b/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource.go index e64c2729071f..dd82b49e99ef 100644 --- a/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource.go +++ b/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource.go @@ -8,6 +8,7 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" @@ -33,6 +34,7 @@ type MachineLearningDataStoreBlobStorageModel struct { ServiceDataAuthIdentity string `tfschema:"service_data_auth_identity"` AccountKey string `tfschema:"account_key"` SharedAccessSignature string `tfschema:"shared_access_signature"` + SkipValidation bool `tfschema:"skip_validation"` Tags map[string]string `tfschema:"tags"` } @@ -117,6 +119,11 @@ func (r MachineLearningDataStoreBlobStorage) Arguments() map[string]*pluginsdk.S AtLeastOneOf: []string{"account_key", "shared_access_signature"}, }, + "skip_validation": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + "tags": commonschema.TagsForceNew(), } } @@ -198,7 +205,11 @@ func (r MachineLearningDataStoreBlobStorage) Create() sdk.ResourceFunc { } datastoreRaw.Properties = props - _, err = client.CreateOrUpdate(ctx, id, datastoreRaw, datastore.DefaultCreateOrUpdateOperationOptions()) + opts := datastore.DefaultCreateOrUpdateOperationOptions() + if model.SkipValidation { + opts.SkipValidation = pointer.To(true) + } + _, err = client.CreateOrUpdate(ctx, id, datastoreRaw, opts) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) } @@ -267,7 +278,11 @@ func (r MachineLearningDataStoreBlobStorage) Update() sdk.ResourceFunc { } datastoreRaw.Properties = props - _, err = client.CreateOrUpdate(ctx, *id, datastoreRaw, datastore.DefaultCreateOrUpdateOperationOptions()) + opts := datastore.DefaultCreateOrUpdateOperationOptions() + if state.SkipValidation { + opts.SkipValidation = pointer.To(true) + } + _, err = client.CreateOrUpdate(ctx, *id, datastoreRaw, opts) if err != nil { return fmt.Errorf("updating %s: %+v", id, err) } @@ -316,12 +331,13 @@ func (r MachineLearningDataStoreBlobStorage) Read() sdk.ResourceFunc { return fmt.Errorf("retrieving Account %q for Container %q: %s", *data.AccountName, *data.ContainerName, 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(subscriptionId, storageAccount.ResourceGroup, *data.AccountName, *data.ContainerName) model.StorageContainerID = containerId.ID() model.IsDefault = *data.IsDefault + model.SkipValidation = metadata.ResourceData.Get("skip_validation").(bool) if v, ok := metadata.ResourceData.GetOk("account_key"); ok { if v.(string) != "" { diff --git a/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource_test.go b/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource_test.go index acf6cea4990c..5cab4bde7407 100644 --- a/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource_test.go +++ b/internal/services/machinelearning/machine_learning_datastore_blobstorage_resource_test.go @@ -34,6 +34,21 @@ func TestAccMachineLearningDataStoreBlobStorage_accountKey(t *testing.T) { }) } +func TestAccMachineLearningDataStoreBlobStorage_accountKeySkipValidation(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_blobstorage", "test") + r := MachineLearningDataStoreBlobStorage{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.blobStorageAccountKeySkipValidation(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("account_key", "skip_validation"), + }) +} + func TestAccMachineLearningDataStoreBlobStorage_sasToken(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_blobstorage", "test") r := MachineLearningDataStoreBlobStorage{} @@ -124,6 +139,27 @@ resource "azurerm_machine_learning_datastore_blobstorage" "test" { `, template, data.RandomInteger) } +func (r MachineLearningDataStoreBlobStorage) blobStorageAccountKeySkipValidation(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_blobstorage" "test" { + name = "accdatastore%[2]d" + workspace_id = azurerm_machine_learning_workspace.test.id + storage_container_id = azurerm_storage_container.test.resource_manager_id + account_key = azurerm_storage_account.test.primary_access_key + skip_validation = true +} +`, template, data.RandomInteger) +} + func (r MachineLearningDataStoreBlobStorage) blobStorageSas(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` 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 eceb7ed3a240..60abb075656c 100644 --- a/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource.go +++ b/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" @@ -36,6 +37,7 @@ type MachineLearningDataStoreDataLakeGen2Model struct { Description string `tfschema:"description"` IsDefault bool `tfschema:"is_default"` ServiceDataIdentity string `tfschema:"service_data_identity"` + SkipValidation bool `tfschema:"skip_validation"` Tags map[string]string `tfschema:"tags"` } @@ -125,6 +127,11 @@ func (r MachineLearningDataStoreDataLakeGen2) Arguments() map[string]*pluginsdk. Default: string(datastore.ServiceDataAccessAuthIdentityNone), }, + "skip_validation": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + "authority_url": { Type: pluginsdk.TypeString, Optional: true, @@ -203,7 +210,11 @@ func (r MachineLearningDataStoreDataLakeGen2) Create() sdk.ResourceFunc { props.Credentials = creds datastoreRaw.Properties = props - _, err = client.CreateOrUpdate(ctx, id, datastoreRaw, datastore.DefaultCreateOrUpdateOperationOptions()) + opts := datastore.DefaultCreateOrUpdateOperationOptions() + if model.SkipValidation { + opts.SkipValidation = pointer.To(true) + } + _, err = client.CreateOrUpdate(ctx, id, datastoreRaw, opts) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) } @@ -267,7 +278,11 @@ func (r MachineLearningDataStoreDataLakeGen2) Update() sdk.ResourceFunc { props.Credentials = creds datastoreRaw.Properties = props - _, err = client.CreateOrUpdate(ctx, *id, datastoreRaw, datastore.DefaultCreateOrUpdateOperationOptions()) + opts := datastore.DefaultCreateOrUpdateOperationOptions() + if state.SkipValidation { + opts.SkipValidation = pointer.To(true) + } + _, err = client.CreateOrUpdate(ctx, *id, datastoreRaw, opts) if err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) } @@ -316,12 +331,13 @@ 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(subscriptionId, storageAccount.ResourceGroup, data.AccountName, data.Filesystem) model.StorageContainerID = containerId.ID() model.IsDefault = *data.IsDefault + model.SkipValidation = metadata.ResourceData.Get("skip_validation").(bool) if creds, ok := data.Credentials.(datastore.ServicePrincipalDatastoreCredentials); ok { if !strings.EqualFold(creds.TenantId, "00000000-0000-0000-0000-000000000000") && !strings.EqualFold(creds.ClientId, "00000000-0000-0000-0000-000000000000") { diff --git a/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource_test.go b/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource_test.go index 364c0bc896e1..ab476eb8a8c4 100644 --- a/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource_test.go +++ b/internal/services/machinelearning/machine_learning_datastore_datalake_gen2_resource_test.go @@ -35,6 +35,21 @@ func TestAccMachineLearningDataStoreDataLakeGen2_basic(t *testing.T) { }) } +func TestAccMachineLearningDataStoreDataLakeGen2_skipValidation(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_datalake_gen2", "test") + r := MachineLearningDataStoreDataLakeGen2{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.dataLakeGen2SkipValidation(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("skip_validation"), + }) +} + func TestAccMachineLearningDataStoreDataLakeGen2_spn(t *testing.T) { if os.Getenv("ARM_TENANT_ID") == "" || os.Getenv("ARM_CLIENT_ID") == "" || os.Getenv("ARM_CLIENT_SECRET") == "" { @@ -134,6 +149,26 @@ resource "azurerm_machine_learning_datastore_datalake_gen2" "test" { `, template, data.RandomInteger) } +func (r MachineLearningDataStoreDataLakeGen2) dataLakeGen2SkipValidation(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 + skip_validation = true +} +`, template, data.RandomInteger) +} + func (r MachineLearningDataStoreDataLakeGen2) dataLakeGen2Spn(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` diff --git a/internal/services/machinelearning/machine_learning_datastore_fileshare_resource.go b/internal/services/machinelearning/machine_learning_datastore_fileshare_resource.go index f646f0b65b12..5139d5e44a16 100644 --- a/internal/services/machinelearning/machine_learning_datastore_fileshare_resource.go +++ b/internal/services/machinelearning/machine_learning_datastore_fileshare_resource.go @@ -8,6 +8,7 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-sdk/resource-manager/machinelearningservices/2023-04-01/datastore" @@ -33,6 +34,7 @@ type MachineLearningDataStoreFileShareModel struct { ServiceDataIdentity string `tfschema:"service_data_identity"` AccountKey string `tfschema:"account_key"` SharedAccessSignature string `tfschema:"shared_access_signature"` + SkipValidation bool `tfschema:"skip_validation"` Tags map[string]string `tfschema:"tags"` } @@ -107,6 +109,11 @@ func (r MachineLearningDataStoreFileShare) Arguments() map[string]*pluginsdk.Sch AtLeastOneOf: []string{"account_key", "shared_access_signature"}, }, + "skip_validation": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + "tags": commonschema.TagsForceNew(), } } @@ -190,7 +197,11 @@ func (r MachineLearningDataStoreFileShare) Create() sdk.ResourceFunc { } datastoreRaw.Properties = props - _, err = client.CreateOrUpdate(ctx, id, datastoreRaw, datastore.DefaultCreateOrUpdateOperationOptions()) + opts := datastore.DefaultCreateOrUpdateOperationOptions() + if model.SkipValidation { + opts.SkipValidation = pointer.To(true) + } + _, err = client.CreateOrUpdate(ctx, id, datastoreRaw, opts) if err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) } @@ -258,7 +269,11 @@ func (r MachineLearningDataStoreFileShare) Update() sdk.ResourceFunc { } datastoreRaw.Properties = props - _, err = client.CreateOrUpdate(ctx, *id, datastoreRaw, datastore.DefaultCreateOrUpdateOperationOptions()) + opts := datastore.DefaultCreateOrUpdateOperationOptions() + if state.SkipValidation { + opts.SkipValidation = pointer.To(true) + } + _, err = client.CreateOrUpdate(ctx, *id, datastoreRaw, opts) if err != nil { return fmt.Errorf("updating %s: %+v", id, err) } @@ -307,12 +322,13 @@ func (r MachineLearningDataStoreFileShare) Read() sdk.ResourceFunc { return fmt.Errorf("retrieving Account %q for Share %q: %s", data.AccountName, data.FileShareName, 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) } fileShareId := storageparse.NewStorageShareResourceManagerID(subscriptionId, storageAccount.ResourceGroup, data.AccountName, "default", data.FileShareName) model.StorageFileShareID = fileShareId.ID() model.IsDefault = *data.IsDefault + model.SkipValidation = metadata.ResourceData.Get("skip_validation").(bool) if v, ok := metadata.ResourceData.GetOk("account_key"); ok { if v.(string) != "" { diff --git a/internal/services/machinelearning/machine_learning_datastore_fileshare_resource_test.go b/internal/services/machinelearning/machine_learning_datastore_fileshare_resource_test.go index 03cc518f5f6a..1f1932cd11b1 100644 --- a/internal/services/machinelearning/machine_learning_datastore_fileshare_resource_test.go +++ b/internal/services/machinelearning/machine_learning_datastore_fileshare_resource_test.go @@ -34,6 +34,21 @@ func TestAccMachineLearningDataStoreFileShare_accountKey(t *testing.T) { }) } +func TestAccMachineLearningDataStoreFileShare_accountKeySkipValidation(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_fileshare", "test") + r := MachineLearningDataStoreFileShare{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.fileShareAccountKey(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("account_key"), + }) +} + func TestAccMachineLearningDataStoreFileShare_sasToken(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_machine_learning_datastore_fileshare", "test") r := MachineLearningDataStoreFileShare{} @@ -124,6 +139,27 @@ resource "azurerm_machine_learning_datastore_fileshare" "test" { `, template, data.RandomInteger) } +func (r MachineLearningDataStoreFileShare) fileShareAccountKeySkipValidation(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_storage_share" "test" { + name = "accfs%[2]d" + storage_account_name = azurerm_storage_account.test.name + quota = 1 +} + +resource "azurerm_machine_learning_datastore_fileshare" "test" { + name = "accdatastore%[2]d" + workspace_id = azurerm_machine_learning_workspace.test.id + storage_fileshare_id = azurerm_storage_share.test.resource_manager_id + account_key = azurerm_storage_account.test.primary_access_key + skip_validation = true +} +`, template, data.RandomInteger) +} + func (r MachineLearningDataStoreFileShare) fileShareSas(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` diff --git a/website/docs/r/machine_learning_datastore_blobstorage.html.markdown b/website/docs/r/machine_learning_datastore_blobstorage.html.markdown index ea0686105dff..b3b33f7f6e8a 100644 --- a/website/docs/r/machine_learning_datastore_blobstorage.html.markdown +++ b/website/docs/r/machine_learning_datastore_blobstorage.html.markdown @@ -99,6 +99,8 @@ The following arguments are supported: * `service_data_auth_identity` - (Optional) Specifies which identity to use when retrieving data from the specified source. Defaults to `None`. Possible values are `None`, `WorkspaceSystemAssignedIdentity` and `WorkspaceUserAssignedIdentity`. +* `skip_validation` - (Optional) Whether to skip the access check during the creation. + * `tags` - (Optional) A mapping of tags which should be assigned to the Machine Learning DataStore. Changing this forces a new Machine Learning DataStore to be created. ## Attributes Reference 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 fefe5cd304df..64ee5252f486 100644 --- a/website/docs/r/machine_learning_datastore_datalake_gen2.html.markdown +++ b/website/docs/r/machine_learning_datastore_datalake_gen2.html.markdown @@ -95,6 +95,8 @@ The following arguments are supported: * `service_data_identity` - (Optional) Specifies which identity to use when retrieving data from the specified source. Defaults to `None`. Possible values are `None`, `WorkspaceSystemAssignedIdentity` and `WorkspaceUserAssignedIdentity`. +* `skip_validation` - (Optional) Whether to skip the access check during the creation. + * `tags` - (Optional) A mapping of tags which should be assigned to the Machine Learning DataStore. Changing this forces a new Machine Learning DataStore to be created. ## Attributes Reference diff --git a/website/docs/r/machine_learning_datastore_fileshare.html.markdown b/website/docs/r/machine_learning_datastore_fileshare.html.markdown index 71af64a88671..0106135e286a 100644 --- a/website/docs/r/machine_learning_datastore_fileshare.html.markdown +++ b/website/docs/r/machine_learning_datastore_fileshare.html.markdown @@ -93,6 +93,8 @@ The following arguments are supported: * `service_data_identity` - (Optional) Specifies which identity to use when retrieving data from the specified source. Defaults to `None`. Possible values are `None`, `WorkspaceSystemAssignedIdentity` and `WorkspaceUserAssignedIdentity`. +* `skip_validation` - (Optional) Whether to skip the access check during the creation. + * `tags` - (Optional) A mapping of tags which should be assigned to the Machine Learning DataStore. Changing this forces a new Machine Learning DataStore to be created. ## Attributes Reference