From c7481abf29b4bc3a63cb974843e3aa0ae4ccb9a5 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Mon, 2 Dec 2024 17:24:50 +0800 Subject: [PATCH] `azurerm_cognitive_deployment` - support for the property `dynamic_throttling_enabled` (#28100) * Support `dynamic_throttling_enabled` property in `azurerm_cognitive_deployment` * Fix linter issue --- .../cognitive_deployment_resource.go | 35 ++++++++++++------- .../cognitive_deployment_resource_test.go | 26 ++++---------- .../docs/r/cognitive_deployment.html.markdown | 2 ++ 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/internal/services/cognitive/cognitive_deployment_resource.go b/internal/services/cognitive/cognitive_deployment_resource.go index 40ecfcc8b9dc..ebd62e4c21e5 100644 --- a/internal/services/cognitive/cognitive_deployment_resource.go +++ b/internal/services/cognitive/cognitive_deployment_resource.go @@ -20,12 +20,13 @@ import ( ) type cognitiveDeploymentModel struct { - Name string `tfschema:"name"` - CognitiveAccountId string `tfschema:"cognitive_account_id"` - Model []DeploymentModelModel `tfschema:"model"` - RaiPolicyName string `tfschema:"rai_policy_name"` - Sku []DeploymentSkuModel `tfschema:"sku"` - VersionUpgradeOption string `tfschema:"version_upgrade_option"` + Name string `tfschema:"name"` + CognitiveAccountId string `tfschema:"cognitive_account_id"` + DynamicThrottlingEnabled bool `tfschema:"dynamic_throttling_enabled"` + Model []DeploymentModelModel `tfschema:"model"` + RaiPolicyName string `tfschema:"rai_policy_name"` + Sku []DeploymentSkuModel `tfschema:"sku"` + VersionUpgradeOption string `tfschema:"version_upgrade_option"` } type DeploymentModelModel struct { @@ -74,6 +75,11 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: cognitiveservicesaccounts.ValidateAccountID, }, + "dynamic_throttling_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + "model": { Type: pluginsdk.TypeList, Required: true, @@ -220,6 +226,10 @@ func (r CognitiveDeploymentResource) Create() sdk.ResourceFunc { properties.Properties.RaiPolicyName = &model.RaiPolicyName } + if model.DynamicThrottlingEnabled { + properties.Properties.DynamicThrottlingEnabled = &model.DynamicThrottlingEnabled + } + if model.VersionUpgradeOption != "" { option := deployments.DeploymentModelVersionUpgradeOption(model.VersionUpgradeOption) properties.Properties.VersionUpgradeOption = &option @@ -266,6 +276,10 @@ func (r CognitiveDeploymentResource) Update() sdk.ResourceFunc { properties := resp.Model + if metadata.ResourceData.HasChange("dynamic_throttling_enabled") { + properties.Properties.DynamicThrottlingEnabled = pointer.To(model.DynamicThrottlingEnabled) + } + if metadata.ResourceData.HasChange("sku.0.capacity") { properties.Sku.Capacity = pointer.To(model.Sku[0].Capacity) } @@ -323,12 +337,9 @@ func (r CognitiveDeploymentResource) Read() sdk.ResourceFunc { if properties := model.Properties; properties != nil { state.Model = flattenDeploymentModelModel(properties.Model) - if v := properties.RaiPolicyName; v != nil { - state.RaiPolicyName = *v - } - if v := properties.VersionUpgradeOption; v != nil { - state.VersionUpgradeOption = string(*v) - } + state.DynamicThrottlingEnabled = pointer.From(properties.DynamicThrottlingEnabled) + state.RaiPolicyName = pointer.From(properties.RaiPolicyName) + state.VersionUpgradeOption = string(pointer.From(properties.VersionUpgradeOption)) } if sku := flattenDeploymentSkuModel(model.Sku); sku != nil { state.Sku = sku diff --git a/internal/services/cognitive/cognitive_deployment_resource_test.go b/internal/services/cognitive/cognitive_deployment_resource_test.go index 1cb9cffd5746..c980c756794b 100644 --- a/internal/services/cognitive/cognitive_deployment_resource_test.go +++ b/internal/services/cognitive/cognitive_deployment_resource_test.go @@ -19,19 +19,6 @@ import ( type CognitiveDeploymentTestResource struct{} -func TestAccCognitiveDeploymentSequential(t *testing.T) { - // Only two OpenAI resources could be created per region, so run the tests sequentially. - // Refer to : https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quotas-limits - acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ - "deployment": { - "basic": TestAccCognitiveDeployment_basic, - "requiresImport": testAccCognitiveDeployment_requiresImport, - "complete": testAccCognitiveDeployment_complete, - "update": TestAccCognitiveDeployment_update, - }, - }) -} - func TestAccCognitiveDeployment_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cognitive_deployment", "test") r := CognitiveDeploymentTestResource{} @@ -47,7 +34,7 @@ func TestAccCognitiveDeployment_basic(t *testing.T) { }) } -func testAccCognitiveDeployment_requiresImport(t *testing.T) { +func TestAccCognitiveDeployment_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cognitive_deployment", "test") r := CognitiveDeploymentTestResource{} @@ -62,7 +49,7 @@ func testAccCognitiveDeployment_requiresImport(t *testing.T) { }) } -func testAccCognitiveDeployment_complete(t *testing.T) { +func TestAccCognitiveDeployment_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cognitive_deployment", "test") r := CognitiveDeploymentTestResource{} data.ResourceSequentialTest(t, r, []acceptance.TestStep{ @@ -70,6 +57,7 @@ func testAccCognitiveDeployment_complete(t *testing.T) { Config: r.complete(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("dynamic_throttling_enabled").HasValue("true"), ), }, data.ImportStep(), @@ -211,9 +199,9 @@ func (r CognitiveDeploymentTestResource) complete(data acceptance.TestData) stri %s resource "azurerm_cognitive_deployment" "test" { - name = "acctest-cd-%d" - cognitive_account_id = azurerm_cognitive_account.test.id - + name = "acctest-cd-%d" + cognitive_account_id = azurerm_cognitive_account.test.id + dynamic_throttling_enabled = true model { format = "OpenAI" name = "text-embedding-ada-002" @@ -222,7 +210,7 @@ resource "azurerm_cognitive_deployment" "test" { sku { name = "Standard" } - rai_policy_name = "RAI policy" + rai_policy_name = "Microsoft.DefaultV2" version_upgrade_option = "OnceNewDefaultVersionAvailable" } `, template, data.RandomInteger) diff --git a/website/docs/r/cognitive_deployment.html.markdown b/website/docs/r/cognitive_deployment.html.markdown index a60624b3eea3..51b9aba4512e 100644 --- a/website/docs/r/cognitive_deployment.html.markdown +++ b/website/docs/r/cognitive_deployment.html.markdown @@ -54,6 +54,8 @@ The following arguments are supported: * `sku` - (Required) A `sku` block as defined below. +* `dynamic_throttling_enabled` - (Optional) Whether dynamic throttling is enabled. + * `rai_policy_name` - (Optional) The name of RAI policy. * `version_upgrade_option` - (Optional) Deployment model version upgrade option. Possible values are `OnceNewDefaultVersionAvailable`, `OnceCurrentVersionExpired`, and `NoAutoUpgrade`. Defaults to `OnceNewDefaultVersionAvailable`.