Skip to content

Commit

Permalink
azurerm_cognitive_deployment - Make version_upgrade_option updata…
Browse files Browse the repository at this point in the history
…ble (#24922)
  • Loading branch information
lonegunmanb authored Feb 20, 2024
1 parent eaf257d commit aff4210
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/services/cognitive/cognitive_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down
47 changes: 47 additions & 0 deletions internal/services/cognitive/cognitive_deployment_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion website/docs/r/cognitive_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

---

Expand Down

0 comments on commit aff4210

Please sign in to comment.