Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cognitive_deployment - includes version to Update function #24700

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ func (r CognitiveDeploymentResource) Update() sdk.ResourceFunc {
properties.Properties.RaiPolicyName = pointer.To(model.RaiPolicyName)
}

if metadata.ResourceData.HasChange("model.0.version") {
properties.Properties.Model.Version = pointer.To(model.Model[0].Version)
}

if err := client.CreateOrUpdateThenPoll(ctx, *id, *properties); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ func TestAccCognitiveDeployment_update(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.updateVersion(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("model.0.version").HasValue("1"),
),
},
data.ImportStep(),
})
}

Expand All @@ -119,7 +127,7 @@ func (r CognitiveDeploymentTestResource) Exists(ctx context.Context, clients *cl
return utils.Bool(resp.Model != nil), nil
}

func (r CognitiveDeploymentTestResource) template(data acceptance.TestData, kind string) string {
func (r CognitiveDeploymentTestResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -133,14 +141,14 @@ resource "azurerm_cognitive_account" "test" {
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
kind = "%s"
kind = "OpenAI"
sku_name = "S0"
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, kind)
`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger)
}

func (r CognitiveDeploymentTestResource) basic(data acceptance.TestData) string {
template := r.template(data, "OpenAI")
template := r.template(data)
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -182,7 +190,7 @@ resource "azurerm_cognitive_deployment" "import" {
}

func (r CognitiveDeploymentTestResource) complete(data acceptance.TestData) string {
template := r.template(data, "OpenAI")
template := r.template(data)
return fmt.Sprintf(`
%s

Expand All @@ -205,12 +213,30 @@ resource "azurerm_cognitive_deployment" "test" {
}

func (r CognitiveDeploymentTestResource) update(data acceptance.TestData) string {
template := r.template(data, "OpenAI")
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"
model {
format = "OpenAI"
name = "text-embedding-ada-002"
version = "2"
}
scale {
type = "Standard"
capacity = 2
}
}
`, template, data.RandomInteger)
}



func (r CognitiveDeploymentTestResource) updateVersion(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s

resource "azurerm_cognitive_deployment" "test" {
Expand All @@ -220,7 +246,7 @@ resource "azurerm_cognitive_deployment" "test" {
model {
format = "OpenAI"
name = "text-embedding-ada-002"
version = "2"
version = "1"
}
scale {
type = "Standard"
Expand Down
Loading