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

New resource azurerm_azure_ai_services #26008

Merged
merged 29 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a53fbd2
add support for Cognitive account AI services
xuzhang3 May 16, 2024
70ed5af
rename to azurerm_cognitive_account_ai_services
xuzhang3 May 17, 2024
32fc6e4
merge upstream update
xuzhang3 May 17, 2024
e9fd983
foramt code
xuzhang3 May 17, 2024
20c701f
fix feature unit test
xuzhang3 May 17, 2024
7e3bc7b
1. reuseCognitiveAccount.PurgeSoftDeleteOnDestroy
xuzhang3 May 24, 2024
d624256
update create/update request poller
xuzhang3 May 24, 2024
388a5fe
rename public_network_access_enabled to public_network_access
xuzhang3 May 27, 2024
34db8a6
rename local_auth_enabled to local_authentication_enabled
xuzhang3 Jun 4, 2024
07eddfa
add support for KV-hsm encrption
xuzhang3 Jun 14, 2024
dc433f4
add KV-hsm test case
xuzhang3 Jun 19, 2024
6caac66
update doc
xuzhang3 Jun 20, 2024
c8e01d3
update test case
xuzhang3 Jun 20, 2024
69ddc59
remove unused feature config
xuzhang3 Jun 20, 2024
4ebc86b
remove unused feature config
xuzhang3 Jun 20, 2024
905c056
rename local_auth_enabled to local_authentication_enabled
xuzhang3 Jun 20, 2024
6a9142b
fix test error
xuzhang3 Jun 20, 2024
6d65ff4
update ai service test parameter
xuzhang3 Jul 5, 2024
46689af
skip HSM encryption test
xuzhang3 Jul 10, 2024
4cd821e
remove KV HSM resource from test case
xuzhang3 Jul 11, 2024
e67e110
add encryption when account ready
xuzhang3 Jul 15, 2024
4d74037
rename to azure ai service
xuzhang3 Jul 26, 2024
745f07b
add azure ai service
xuzhang3 Jul 26, 2024
36cd799
update AI service and fix CMK test
xuzhang3 Aug 2, 2024
4d87ee3
rename azure_ai_services to ai_services
xuzhang3 Aug 2, 2024
22bbff7
remove unused code
xuzhang3 Aug 2, 2024
c17aca7
format import
xuzhang3 Aug 2, 2024
9ee7a6d
optimize create/update
xuzhang3 Aug 14, 2024
f93dbc6
rename azure_ai_services to ai_services
xuzhang3 Aug 15, 2024
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
3 changes: 3 additions & 0 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func Default() UserFeatures {
CognitiveAccount: CognitiveAccountFeatures{
PurgeSoftDeleteOnDestroy: true,
},
CognitiveAccountAIServices: CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

we can reuse the CognitiveAccount block/toggle here

KeyVault: KeyVaultFeatures{
PurgeSoftDeleteOnDestroy: true,
PurgeSoftDeletedKeysOnDestroy: true,
Expand Down
37 changes: 21 additions & 16 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
package features

type UserFeatures struct {
ApiManagement ApiManagementFeatures
AppConfiguration AppConfigurationFeatures
ApplicationInsights ApplicationInsightFeatures
CognitiveAccount CognitiveAccountFeatures
VirtualMachine VirtualMachineFeatures
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
KeyVault KeyVaultFeatures
TemplateDeployment TemplateDeploymentFeatures
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
ResourceGroup ResourceGroupFeatures
RecoveryServicesVault RecoveryServicesVault
ManagedDisk ManagedDiskFeatures
Subscription SubscriptionFeatures
PostgresqlFlexibleServer PostgresqlFlexibleServerFeatures
MachineLearning MachineLearningFeatures
RecoveryService RecoveryServiceFeatures
ApiManagement ApiManagementFeatures
AppConfiguration AppConfigurationFeatures
ApplicationInsights ApplicationInsightFeatures
CognitiveAccount CognitiveAccountFeatures
CognitiveAccountAIServices CognitiveAccountAIServicesFeatures
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CognitiveAccountAIServices CognitiveAccountAIServicesFeatures

VirtualMachine VirtualMachineFeatures
VirtualMachineScaleSet VirtualMachineScaleSetFeatures
KeyVault KeyVaultFeatures
TemplateDeployment TemplateDeploymentFeatures
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
ResourceGroup ResourceGroupFeatures
RecoveryServicesVault RecoveryServicesVault
ManagedDisk ManagedDiskFeatures
Subscription SubscriptionFeatures
PostgresqlFlexibleServer PostgresqlFlexibleServerFeatures
MachineLearning MachineLearningFeatures
RecoveryService RecoveryServiceFeatures
}

type CognitiveAccountFeatures struct {
PurgeSoftDeleteOnDestroy bool
}

type CognitiveAccountAIServicesFeatures struct {
PurgeSoftDeleteOnDestroy bool
}

type VirtualMachineFeatures struct {
DeleteOSDiskOnDeletion bool
GracefulShutdown bool
Expand Down
25 changes: 25 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
},
},

"cognitive_account_ai_services": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"purge_soft_delete_on_destroy": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the cognitive_account block for this purpose?

Suggested change
"cognitive_account_ai_services": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"purge_soft_delete_on_destroy": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
},
},


"key_vault": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -448,6 +463,16 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["cognitive_account_ai_services"]; ok {
items := raw.([]interface{})
if len(items) > 0 && items[0] != nil {
cognitiveAIServicesRaw := items[0].(map[string]interface{})
if v, ok := cognitiveAIServicesRaw["purge_soft_delete_on_destroy"]; ok {
featuresMap.CognitiveAccountAIServices.PurgeSoftDeleteOnDestroy = v.(bool)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the cognitive_account block for this purpose?

Suggested change
if raw, ok := val["cognitive_account_ai_services"]; ok {
items := raw.([]interface{})
if len(items) > 0 && items[0] != nil {
cognitiveAIServicesRaw := items[0].(map[string]interface{})
if v, ok := cognitiveAIServicesRaw["purge_soft_delete_on_destroy"]; ok {
featuresMap.CognitiveAccountAIServices.PurgeSoftDeleteOnDestroy = v.(bool)
}
}
}


if raw, ok := val["key_vault"]; ok {
items := raw.([]interface{})
if len(items) > 0 && items[0] != nil {
Expand Down
84 changes: 84 additions & 0 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestExpandFeatures(t *testing.T) {
CognitiveAccount: features.CognitiveAccountFeatures{
PurgeSoftDeleteOnDestroy: true,
},
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the CognitiveAccount block for this purpose?

Suggested change
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},

KeyVault: features.KeyVaultFeatures{
PurgeSoftDeletedCertsOnDestroy: true,
PurgeSoftDeletedKeysOnDestroy: true,
Expand Down Expand Up @@ -115,6 +118,11 @@ func TestExpandFeatures(t *testing.T) {
"purge_soft_delete_on_destroy": true,
},
},
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": true,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the cognitive_account block for this purpose?

Suggested change
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": true,
},
},

"key_vault": []interface{}{
map[string]interface{}{
"purge_soft_deleted_certificates_on_destroy": true,
Expand Down Expand Up @@ -208,6 +216,9 @@ func TestExpandFeatures(t *testing.T) {
CognitiveAccount: features.CognitiveAccountFeatures{
PurgeSoftDeleteOnDestroy: true,
},
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},

KeyVault: features.KeyVaultFeatures{
PurgeSoftDeletedCertsOnDestroy: true,
PurgeSoftDeletedKeysOnDestroy: true,
Expand Down Expand Up @@ -288,6 +299,11 @@ func TestExpandFeatures(t *testing.T) {
"purge_soft_delete_on_destroy": false,
},
},
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the cognitive_account block for this purpose?

Suggested change
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
},
},

"key_vault": []interface{}{
map[string]interface{}{
"purge_soft_deleted_certificates_on_destroy": false,
Expand Down Expand Up @@ -381,6 +397,9 @@ func TestExpandFeatures(t *testing.T) {
CognitiveAccount: features.CognitiveAccountFeatures{
PurgeSoftDeleteOnDestroy: false,
},
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: false,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the cognitive_account block for this purpose?

Suggested change
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: false,
},

KeyVault: features.KeyVaultFeatures{
PurgeSoftDeletedCertsOnDestroy: false,
PurgeSoftDeletedKeysOnDestroy: false,
Expand Down Expand Up @@ -716,6 +735,71 @@ func TestExpandFeaturesCognitiveServices(t *testing.T) {
}
}

func TestExpandFeaturesCognitiveAIServicesAccount(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"cognitive_account_ai_services": []interface{}{},
},
},
Expected: features.UserFeatures{
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
},
},
{
Name: "Purge on Destroy Enabled",
Input: []interface{}{
map[string]interface{}{
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": true,
},
},
},
},
Expected: features.UserFeatures{
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
},
},
{
Name: "Purge on Destroy Disabled",
Input: []interface{}{
map[string]interface{}{
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
},
},
},
},
Expected: features.UserFeatures{
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: false,
},
},
},
}

for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.CognitiveAccountAIServices, testCase.Expected.CognitiveAccountAIServices) {
t.Fatalf("Expected %+v but got %+v", result.CognitiveAccountAIServices, testCase.Expected.CognitiveAccountAIServices)
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the cognitive_account block for this purpose?

Suggested change
func TestExpandFeaturesCognitiveAIServicesAccount(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"cognitive_account_ai_services": []interface{}{},
},
},
Expected: features.UserFeatures{
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
},
},
{
Name: "Purge on Destroy Enabled",
Input: []interface{}{
map[string]interface{}{
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": true,
},
},
},
},
Expected: features.UserFeatures{
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: true,
},
},
},
{
Name: "Purge on Destroy Disabled",
Input: []interface{}{
map[string]interface{}{
"cognitive_account_ai_services": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
},
},
},
},
Expected: features.UserFeatures{
CognitiveAccountAIServices: features.CognitiveAccountAIServicesFeatures{
PurgeSoftDeleteOnDestroy: false,
},
},
},
}
for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.CognitiveAccountAIServices, testCase.Expected.CognitiveAccountAIServices) {
t.Fatalf("Expected %+v but got %+v", result.CognitiveAccountAIServices, testCase.Expected.CognitiveAccountAIServices)
}
}
}

func TestExpandFeaturesKeyVault(t *testing.T) {
testData := []struct {
Name string
Expand Down
Loading
Loading