Skip to content

Commit

Permalink
add skip_validation for mahcine learning data store
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Nov 30, 2023
1 parent 2d85390 commit 82ec4db
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") == "" {
Expand Down Expand Up @@ -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(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -124,6 +139,27 @@ resource "azurerm_machine_learning_datastore_fileshare" "test" {
`, template, data.RandomInteger)
}

func (r MachineLearningDataStoreFileShare) fileShareAccountKeySkipValidation(data acceptance.TestData) string {

Check failure on line 142 in internal/services/machinelearning/machine_learning_datastore_fileshare_resource_test.go

View workflow job for this annotation

GitHub Actions / golint

func `MachineLearningDataStoreFileShare.fileShareAccountKeySkipValidation` is unused (unused)
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(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82ec4db

Please sign in to comment.