Skip to content

Commit

Permalink
feat: add cognitve deployment dynamic_throttling
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Lettron <[email protected]>
  • Loading branch information
guilhem committed Jun 6, 2024
1 parent 6c924c5 commit dfbef1e
Show file tree
Hide file tree
Showing 107 changed files with 3,772 additions and 44 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.4.0
github.com/hashicorp/go-azure-helpers v0.69.0
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748
github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240606.1065251
github.com/hashicorp/go-azure-sdk/sdk v0.20240606.1065251
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-azure-helpers v0.69.0 h1:JwUWXyDgyr6OafU4CgSvrbEP1wcMjfz4gxRQciDQkBQ=
github.com/hashicorp/go-azure-helpers v0.69.0/go.mod h1:BmbF4JDYXK5sEmFeU5hcn8Br21uElcqLfdQxjatwQKw=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748 h1:sJEw1sYmLpBFUY+4UpE88GimbuAcvmo4ZvTPYenEdp4=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240604.1114748/go.mod h1:1kTyma4K4ZtSWbtCNQfv8H2NZMsIyF+6S8GRbchmUCI=
github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748 h1:DJi4uLd/aUmAcXbTuQXeI6HukIG2ydrnq9aDM2o6D5A=
github.com/hashicorp/go-azure-sdk/sdk v0.20240604.1114748/go.mod h1:Ts5vRL3KPw8iLit+4WSi1hOWlRCx++wJrCkMGj69xBY=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240606.1065251 h1:fzRfTUZydIsTkL0mk2d287khuESflUcYTH6pmMqwHfg=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240606.1065251/go.mod h1:jAijsWRuf9OFNxFaszSMeiWCg9GwV+y6Fge5VIR+4wA=
github.com/hashicorp/go-azure-sdk/sdk v0.20240606.1065251 h1:VWLqZM09/qybAlkuyba3AlQcTmzMJogG2DrK70woa/g=
github.com/hashicorp/go-azure-sdk/sdk v0.20240606.1065251/go.mod h1:Ts5vRL3KPw8iLit+4WSi1hOWlRCx++wJrCkMGj69xBY=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
4 changes: 2 additions & 2 deletions internal/services/cognitive/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package client
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/deployments"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/deployments"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/cognitive/cognitive_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
search "github.com/hashicorp/go-azure-sdk/resource-manager/search/2022-09-01/services"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
30 changes: 22 additions & 8 deletions internal/services/cognitive/cognitive_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/deployments"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/deployments"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
Expand All @@ -21,12 +21,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"`
ScaleSettings []DeploymentScaleSettingsModel `tfschema:"scale"`
VersionUpgradeOption string `tfschema:"version_upgrade_option"`
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"`
DynamicThrottlingEnabled bool `tfschema:"dynamic_throttling_enabled"`
}

type DeploymentModelModel struct {
Expand Down Expand Up @@ -122,6 +123,12 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema {
string(deployments.DeploymentModelVersionUpgradeOptionNoAutoUpgrade),
}, false),
},

"dynamic_throttling_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
}
if !features.FourPointOh() {
arguments["scale"] = &pluginsdk.Schema{
Expand Down Expand Up @@ -261,6 +268,8 @@ func (r CognitiveDeploymentResource) Create() sdk.ResourceFunc {
properties.Properties.VersionUpgradeOption = &option
}

properties.Properties.DynamicThrottlingEnabled = pointer.To(model.DynamicThrottlingEnabled)

properties.Sku = expandDeploymentSkuModel(model.ScaleSettings)

if err := client.CreateOrUpdateThenPoll(ctx, id, *properties); err != nil {
Expand Down Expand Up @@ -314,6 +323,8 @@ func (r CognitiveDeploymentResource) Update() sdk.ResourceFunc {
properties.Properties.Model.Version = pointer.To(model.Model[0].Version)
}

properties.Properties.DynamicThrottlingEnabled = pointer.FromBool(model.DynamicThrottlingEnabled)

properties.Properties.VersionUpgradeOption = pointer.To(deployments.DeploymentModelVersionUpgradeOption(model.VersionUpgradeOption))

if err := client.CreateOrUpdateThenPoll(ctx, *id, *properties); err != nil {
Expand Down Expand Up @@ -366,6 +377,9 @@ func (r CognitiveDeploymentResource) Read() sdk.ResourceFunc {
if v := properties.VersionUpgradeOption; v != nil {
state.VersionUpgradeOption = string(*v)
}

state.DynamicThrottlingEnabled = pointer.From(properties.DynamicThrottlingEnabled)

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 @@ -9,7 +9,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/deployments"
"github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/deployments"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -131,6 +131,14 @@ func TestAccCognitiveDeployment_update(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.dynamicThrottling(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("dynamic_throttling_enabled").Exists(),
),
},
data.ImportStep(),
})
}

Expand Down Expand Up @@ -302,3 +310,26 @@ resource "azurerm_cognitive_deployment" "test" {
}
`, template, data.RandomInteger, versionUpgradeOption)
}

func (r CognitiveDeploymentTestResource) dynamicThrottling(data acceptance.TestData) 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
model {
format = "OpenAI"
name = "text-embedding-ada-002"
}
dynamic_throttling_enabled = true
scale {
type = "Standard"
}
lifecycle {
ignore_changes = [model.0.version]
}
}
`, template, data.RandomInteger)
}

This file was deleted.

Loading

0 comments on commit dfbef1e

Please sign in to comment.