Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Dec 2, 2022
1 parent c5ad6e7 commit 3a5df13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 52 deletions.
53 changes: 4 additions & 49 deletions internal/services/cognitive/cognitive_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DeploymentScaleSettingsModel struct {

type CognitiveDeploymentResource struct{}

var _ sdk.ResourceWithUpdate = CognitiveDeploymentResource{}
var _ sdk.Resource = CognitiveDeploymentResource{}

func (r CognitiveDeploymentResource) ResourceType() string {
return "azurerm_cognitive_deployment"
Expand Down Expand Up @@ -66,12 +66,14 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema {
"model": {
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"format": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"OpenAI",
}, false),
Expand All @@ -87,9 +89,6 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema {
"version": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"1",
}, false),
},
},
},
Expand All @@ -98,6 +97,7 @@ func (r CognitiveDeploymentResource) Arguments() map[string]*pluginsdk.Schema {
"scale_settings": {
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
Expand Down Expand Up @@ -183,51 +183,6 @@ func (r CognitiveDeploymentResource) Create() sdk.ResourceFunc {
}
}

func (r CognitiveDeploymentResource) Update() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Cognitive.DeploymentsClient

id, err := deployments.ParseDeploymentID(metadata.ResourceData.Id())
if err != nil {
return err
}

var model cognitiveDeploymentModel
if err := metadata.Decode(&model); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

resp, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

properties := resp.Model
if properties == nil {
return fmt.Errorf("retrieving %s: properties was nil", id)
}

if metadata.ResourceData.HasChange("format") {
properties.Properties.Model.Format = &model.Model[0].Format
}

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

properties.SystemData = nil

if err := client.CreateOrUpdateThenPoll(ctx, *id, *properties); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}

return nil
},
}
}

func (r CognitiveDeploymentResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/cognitive_deployment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ The following arguments are supported:

A `model` block supports the following:

* `format` - (Required) The format of the Cognitive Services Account Deployment model. Possible value is `OpenAI`.
* `format` - (Required) The format of the Cognitive Services Account Deployment model. Changing this forces a new resource to be created. Possible value is `OpenAI`.

* `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. Possible value is `1`.
* `version` - (Required) The version of Cognitive Services Account Deployment model.

---

A `scale_settings` block supports the following:

* `scale_type` - (Required) Deployment scale type. Possible value is `Standard`.
* `scale_type` - (Required) Deployment scale type. Possible value is `Standard`. Changing this forces a new resource to be created.

## Attributes Reference

Expand Down

0 comments on commit 3a5df13

Please sign in to comment.