Skip to content

Commit

Permalink
add support for VersionUpgradeOption so the users can set the model's…
Browse files Browse the repository at this point in the history
… version they like
  • Loading branch information
lonegunmanb committed Jul 19, 2023
1 parent 706bc6b commit 7eb2aa8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
31 changes: 26 additions & 5 deletions internal/services/cognitive/cognitive_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
)

type cognitiveDeploymentModel struct {
Name string `tfschema:"name"`
CognitiveAccountId string `tfschema:"cognitive_account_id"`
Model []DeploymentModelModel `tfschema:"model"`
RaiPolicyName string `tfschema:"rai_policy_name"`
ScaleSettings []DeploymentScaleSettingsModel `tfschema:"scale"`
Name string `tfschema:"name"`
CognitiveAccountId string `tfschema:"cognitive_account_id"`
Model []DeploymentModelModel `tfschema:"model"`
RaiPolicyName string `tfschema:"rai_policy_name"`
ScaleSettings []DeploymentScaleSettingsModel `tfschema:"scale"`
VersionUpgradeOption string `tfschema:"version_upgrade_option"`
}

type DeploymentModelModel struct {
Expand Down Expand Up @@ -109,6 +110,18 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema {
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"version_upgrade_option": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: string(deployments.DeploymentModelVersionUpgradeOptionOnceNewDefaultVersionAvailable),
ValidateFunc: validation.StringInSlice([]string{
string(deployments.DeploymentModelVersionUpgradeOptionOnceCurrentVersionExpired),
string(deployments.DeploymentModelVersionUpgradeOptionOnceNewDefaultVersionAvailable),
string(deployments.DeploymentModelVersionUpgradeOptionNoAutoUpgrade),
}, false),
},
}
if !features.FourPointOh() {
arguments["scale"] = &pluginsdk.Schema{
Expand Down Expand Up @@ -244,6 +257,11 @@ func (r CognitiveDeploymentResource) Create() sdk.ResourceFunc {
properties.Properties.RaiPolicyName = &model.RaiPolicyName
}

if model.VersionUpgradeOption != "" {
option := deployments.DeploymentModelVersionUpgradeOption(model.VersionUpgradeOption)
properties.Properties.VersionUpgradeOption = &option
}

properties.Sku = expandDeploymentSkuModel(model.ScaleSettings)

if err := client.CreateOrUpdateThenPoll(ctx, id, *properties); err != nil {
Expand Down Expand Up @@ -293,6 +311,9 @@ func (r CognitiveDeploymentResource) Read() sdk.ResourceFunc {
if v := properties.RaiPolicyName; v != nil {
state.RaiPolicyName = *v
}
if v := properties.VersionUpgradeOption; v != nil {
state.VersionUpgradeOption = string(*v)
}
state.ScaleSettings = flattenDeploymentScaleSettingsModel(properties.ScaleSettings)
}
if scale := flattenDeploymentSkuModel(model.Sku); scale != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ resource "azurerm_cognitive_deployment" "test" {
model {
format = "OpenAI"
name = "text-embedding-ada-002"
version = "1"
version = "2"
}
scale {
type = "Standard"
Expand All @@ -145,7 +145,7 @@ resource "azurerm_cognitive_deployment" "import" {
model {
format = "OpenAI"
name = "text-embedding-ada-002"
version = "1"
version = "2"
}
scale {
type = "Standard"
Expand All @@ -171,7 +171,8 @@ resource "azurerm_cognitive_deployment" "test" {
scale {
type = "Standard"
}
rai_policy_name = "RAI policy"
rai_policy_name = "RAI policy"
version_upgrade_option = "OnceNewDefaultVersionAvailable"
}
`, template, data.RandomInteger)
}
2 changes: 2 additions & 0 deletions website/docs/r/cognitive_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ The following arguments are supported:

* `rai_policy_name` - (Optional) The name of RAI policy. 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`. Changing this forces a new resource to be created.

---

A `model` block supports the following:
Expand Down

0 comments on commit 7eb2aa8

Please sign in to comment.