From aff42109e87954b4da1706570b45fec0927820e8 Mon Sep 17 00:00:00 2001 From: lonegunmanb Date: Tue, 20 Feb 2024 08:23:35 +0800 Subject: [PATCH] `azurerm_cognitive_deployment` - Make `version_upgrade_option` updatable (#24922) --- .../cognitive_deployment_resource.go | 3 +- .../cognitive_deployment_resource_test.go | 47 +++++++++++++++++++ .../docs/r/cognitive_deployment.html.markdown | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/internal/services/cognitive/cognitive_deployment_resource.go b/internal/services/cognitive/cognitive_deployment_resource.go index 90726d166c22..5ec55c12b886 100644 --- a/internal/services/cognitive/cognitive_deployment_resource.go +++ b/internal/services/cognitive/cognitive_deployment_resource.go @@ -115,7 +115,6 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema { "version_upgrade_option": { Type: pluginsdk.TypeString, Optional: true, - ForceNew: true, Default: string(deployments.DeploymentModelVersionUpgradeOptionOnceNewDefaultVersionAvailable), ValidateFunc: validation.StringInSlice([]string{ string(deployments.DeploymentModelVersionUpgradeOptionOnceCurrentVersionExpired), @@ -315,6 +314,8 @@ func (r CognitiveDeploymentResource) Update() sdk.ResourceFunc { properties.Properties.Model.Version = pointer.To(model.Model[0].Version) } + properties.Properties.VersionUpgradeOption = pointer.To(deployments.DeploymentModelVersionUpgradeOption(model.VersionUpgradeOption)) + if err := client.CreateOrUpdateThenPoll(ctx, *id, *properties); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } diff --git a/internal/services/cognitive/cognitive_deployment_resource_test.go b/internal/services/cognitive/cognitive_deployment_resource_test.go index ce9c746768ad..86336e92c14e 100644 --- a/internal/services/cognitive/cognitive_deployment_resource_test.go +++ b/internal/services/cognitive/cognitive_deployment_resource_test.go @@ -107,6 +107,30 @@ func TestAccCognitiveDeployment_update(t *testing.T) { ), }, data.ImportStep(), + { + Config: r.versionUpgradeOption(data, "OnceNewDefaultVersionAvailable"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("version_upgrade_option").HasValue("OnceNewDefaultVersionAvailable"), + ), + }, + data.ImportStep(), + { + Config: r.versionUpgradeOption(data, "OnceCurrentVersionExpired"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("version_upgrade_option").HasValue("OnceCurrentVersionExpired"), + ), + }, + data.ImportStep(), + { + Config: r.updateVersion(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("version_upgrade_option").HasValue("OnceNewDefaultVersionAvailable"), + ), + }, + data.ImportStep(), }) } @@ -255,3 +279,26 @@ resource "azurerm_cognitive_deployment" "test" { } `, template, data.RandomInteger) } + +func (r CognitiveDeploymentTestResource) versionUpgradeOption(data acceptance.TestData, versionUpgradeOption string) string { + template := r.template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_cognitive_deployment" "test" { + name = "acctest-cd-%d" + cognitive_account_id = azurerm_cognitive_account.test.id + rai_policy_name = "Microsoft.Default" + version_upgrade_option = "%s" + model { + format = "OpenAI" + name = "text-embedding-ada-002" + version = "1" + } + scale { + type = "Standard" + capacity = 2 + } +} +`, template, data.RandomInteger, versionUpgradeOption) +} diff --git a/website/docs/r/cognitive_deployment.html.markdown b/website/docs/r/cognitive_deployment.html.markdown index e4b88ff7cffe..59ccf7673635 100644 --- a/website/docs/r/cognitive_deployment.html.markdown +++ b/website/docs/r/cognitive_deployment.html.markdown @@ -56,7 +56,7 @@ The following arguments are supported: * `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`. Changing this forces a new resource to be created. +* `version_upgrade_option` - (Optional) Deployment model version upgrade option. Possible values are `OnceNewDefaultVersionAvailable`, `OnceCurrentVersionExpired`, and `NoAutoUpgrade`. Defaults to `OnceNewDefaultVersionAvailable`. ---