From 7121ef55cec3e41583f9b4f5a9f72e2521934209 Mon Sep 17 00:00:00 2001 From: "Yun Liu (from Dev Box)" Date: Fri, 15 Dec 2023 16:16:06 +0800 Subject: [PATCH 1/6] add `source` property and update doc --- .../cognitive_deployment_resource.go | 20 ++++++++++++++++++- .../docs/r/cognitive_deployment.html.markdown | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/services/cognitive/cognitive_deployment_resource.go b/internal/services/cognitive/cognitive_deployment_resource.go index 333129977a58..3f796e2e0c7e 100644 --- a/internal/services/cognitive/cognitive_deployment_resource.go +++ b/internal/services/cognitive/cognitive_deployment_resource.go @@ -12,6 +12,7 @@ import ( "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/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" @@ -32,6 +33,7 @@ type cognitiveDeploymentModel struct { type DeploymentModelModel struct { Format string `tfschema:"format"` Name string `tfschema:"name"` + Source string `tfschema:"source"` Version string `tfschema:"version"` } @@ -98,9 +100,15 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.StringIsNotEmpty, }, + "source": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: azure.ValidateResourceID, + }, + "version": { Type: pluginsdk.TypeString, - Required: true, + Optional: true, }, }, }, @@ -411,6 +419,10 @@ func expandDeploymentModelModel(inputList []DeploymentModelModel) *deployments.D output.Name = &input.Name } + if input.Source != "" { + output.Source = &input.Source + } + if input.Version != "" { output.Version = &input.Version } @@ -461,6 +473,12 @@ func flattenDeploymentModelModel(input *deployments.DeploymentModel) []Deploymen } output.Name = name + source := "" + if input.Source != nil { + source = *input.Source + } + output.Source = source + version := "" if input.Version != nil { version = *input.Version diff --git a/website/docs/r/cognitive_deployment.html.markdown b/website/docs/r/cognitive_deployment.html.markdown index 77313ea69c41..ba8c8c7af6f4 100644 --- a/website/docs/r/cognitive_deployment.html.markdown +++ b/website/docs/r/cognitive_deployment.html.markdown @@ -66,7 +66,9 @@ A `model` block supports the following: * `name` - (Required) The name of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. -* `version` - (Required) The version of Cognitive Services Account Deployment model. +* `source` - (Optional) Deployment model source ARM resource ID. + +* `version` - (Optional) The version of Cognitive Services Account Deployment model. If `version` is not specified, a default version will be assigned. The default version is different for different models and might change when there is new version available for a model. --- From 4d974bc8e77bd5ca97205029f8853021b3ef4945 Mon Sep 17 00:00:00 2001 From: "Yun Liu (from Dev Box)" Date: Mon, 18 Dec 2023 14:50:08 +0800 Subject: [PATCH 2/6] test optional `version` property --- .../services/cognitive/cognitive_deployment_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/cognitive/cognitive_deployment_resource_test.go b/internal/services/cognitive/cognitive_deployment_resource_test.go index 9f64971317ad..5f2467369f1e 100644 --- a/internal/services/cognitive/cognitive_deployment_resource_test.go +++ b/internal/services/cognitive/cognitive_deployment_resource_test.go @@ -152,7 +152,6 @@ resource "azurerm_cognitive_deployment" "test" { model { format = "OpenAI" name = "text-embedding-ada-002" - version = "2" } scale { type = "Standard" From 47463045b175b298e821cff7e28259e127800b70 Mon Sep 17 00:00:00 2001 From: "Yun Liu (from Dev Box)" Date: Mon, 18 Dec 2023 15:22:45 +0800 Subject: [PATCH 3/6] test optional `version` property --- .../cognitive/cognitive_deployment_resource_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/services/cognitive/cognitive_deployment_resource_test.go b/internal/services/cognitive/cognitive_deployment_resource_test.go index 5f2467369f1e..faf8792d39f7 100644 --- a/internal/services/cognitive/cognitive_deployment_resource_test.go +++ b/internal/services/cognitive/cognitive_deployment_resource_test.go @@ -142,20 +142,21 @@ resource "azurerm_cognitive_account" "test" { func (r CognitiveDeploymentTestResource) basic(data acceptance.TestData) string { template := r.template(data, "OpenAI") 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" + format = "OpenAI" + name = "text-embedding-ada-002" } scale { type = "Standard" } + lifecycle { + ignore_changes = [model.0.version] + } } `, template, data.RandomInteger) } From 23c6eba3e1f42e6ecbaf73ae380015fd0ec0ef6d Mon Sep 17 00:00:00 2001 From: "Yun Liu (from Dev Box)" Date: Tue, 9 Jan 2024 15:00:30 +0800 Subject: [PATCH 4/6] Remove `source` from the update list. --- .../cognitive/cognitive_deployment_resource.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/internal/services/cognitive/cognitive_deployment_resource.go b/internal/services/cognitive/cognitive_deployment_resource.go index 3f796e2e0c7e..dbf2b325099b 100644 --- a/internal/services/cognitive/cognitive_deployment_resource.go +++ b/internal/services/cognitive/cognitive_deployment_resource.go @@ -12,7 +12,6 @@ import ( "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/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" @@ -33,7 +32,6 @@ type cognitiveDeploymentModel struct { type DeploymentModelModel struct { Format string `tfschema:"format"` Name string `tfschema:"name"` - Source string `tfschema:"source"` Version string `tfschema:"version"` } @@ -100,12 +98,6 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: validation.StringIsNotEmpty, }, - "source": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceID, - }, - "version": { Type: pluginsdk.TypeString, Optional: true, @@ -419,10 +411,6 @@ func expandDeploymentModelModel(inputList []DeploymentModelModel) *deployments.D output.Name = &input.Name } - if input.Source != "" { - output.Source = &input.Source - } - if input.Version != "" { output.Version = &input.Version } @@ -473,12 +461,6 @@ func flattenDeploymentModelModel(input *deployments.DeploymentModel) []Deploymen } output.Name = name - source := "" - if input.Source != nil { - source = *input.Source - } - output.Source = source - version := "" if input.Version != nil { version = *input.Version From 5e9d0232de77bb01821a5ad3cd18f951370bf244 Mon Sep 17 00:00:00 2001 From: "Yun Liu (from Dev Box)" Date: Tue, 9 Jan 2024 15:02:55 +0800 Subject: [PATCH 5/6] Remove `source` from doc. --- website/docs/r/cognitive_deployment.html.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/docs/r/cognitive_deployment.html.markdown b/website/docs/r/cognitive_deployment.html.markdown index ba8c8c7af6f4..5dcd875a4db9 100644 --- a/website/docs/r/cognitive_deployment.html.markdown +++ b/website/docs/r/cognitive_deployment.html.markdown @@ -66,8 +66,6 @@ A `model` block supports the following: * `name` - (Required) The name of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. -* `source` - (Optional) Deployment model source ARM resource ID. - * `version` - (Optional) The version of Cognitive Services Account Deployment model. If `version` is not specified, a default version will be assigned. The default version is different for different models and might change when there is new version available for a model. --- From 5660e5dbf1fb6eca97c451ed215858f569c1876c Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 23 Jan 2024 10:20:07 +0800 Subject: [PATCH 6/6] Update website/docs/r/cognitive_deployment.html.markdown Co-authored-by: stephybun --- website/docs/r/cognitive_deployment.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/cognitive_deployment.html.markdown b/website/docs/r/cognitive_deployment.html.markdown index 5dcd875a4db9..e4b88ff7cffe 100644 --- a/website/docs/r/cognitive_deployment.html.markdown +++ b/website/docs/r/cognitive_deployment.html.markdown @@ -66,7 +66,7 @@ A `model` block supports the following: * `name` - (Required) The name of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. -* `version` - (Optional) The version of Cognitive Services Account Deployment model. If `version` is not specified, a default version will be assigned. The default version is different for different models and might change when there is new version available for a model. +* `version` - (Optional) The version of Cognitive Services Account Deployment model. If `version` is not specified, the default version of the model at the time will be assigned. ---