Skip to content

Commit

Permalink
feat(vertexai): add vertex_ai_index_endpoint for Vertex AI Matching E…
Browse files Browse the repository at this point in the history
…ngine (#6873) (#1049)

* feat: create vertex_ai_index_endpoint

* fix: remove a white line

* feat: add a comment about deployedIndexes [ci skip]

* feat: add an unit test to check update

* fix: fix the handwritten test name to avoid a conflict

* fix: fix unnecessary code from test

* fix: use immutable instead of input

* refactor: refactor test code with acctest and tpgresource

* test: update network_name to use the unique names

* test: fix an invalid label definition

* feat: increase timeout from 20m to 1h regarding vertex ai index endpoint

* test: increase the timeouts to 120m

* Apply suggestions from code review

* feat: update test and yaml to clarify the fields mutabilities

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jun 7, 2023
1 parent d9ca6e8 commit 1df2ec8
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/hashicorp/terraform-plugin-framework v1.1.1
github.com/hashicorp/terraform-plugin-framework-validators v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
github.com/hashicorp/terraform-provider-google v1.20.1-0.20230607183533-688798ee013e
github.com/hashicorp/terraform-provider-google v1.20.1-0.20230607212826-c110ef9ebb33
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ github.com/hashicorp/terraform-plugin-mux v0.8.0 h1:WCTP66mZ+iIaIrCNJnjPEYnVjawT
github.com/hashicorp/terraform-plugin-mux v0.8.0/go.mod h1:vdW0daEi8Kd4RFJmet5Ot+SIVB/B8SwQVJiYKQwdCy8=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 h1:FtCLTiTcykdsURXPt/ku7fYXm3y19nbzbZcUxHx9RbI=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0/go.mod h1:80wf5oad1tW+oLnbXS4UTYmDCrl7BuN1Q+IA91X1a4Y=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20230607183533-688798ee013e h1:A6w1Yf8WMjrOin2GggsfMVzc1yQDDweLrkS0f7DdXko=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20230607183533-688798ee013e/go.mod h1:ebKbsnBfDqUEv22DQIYGBYKFLSQHHY5vU874kEJ/lj4=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20230607212826-c110ef9ebb33 h1:3eMovsy0a96ULj7ahcCWzHzojvHmtf3a/Lh3qxaPP7Q=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20230607212826-c110ef9ebb33/go.mod h1:ebKbsnBfDqUEv22DQIYGBYKFLSQHHY5vU874kEJ/lj4=
github.com/hashicorp/terraform-registry-address v0.1.0 h1:W6JkV9wbum+m516rCl5/NjKxCyTVaaUBbzYcMzBDO3U=
github.com/hashicorp/terraform-registry-address v0.1.0/go.mod h1:EnyO2jYO6j29DTHbJcm00E5nQTFeTtyZH3H5ycydQ5A=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package vertexai

import (
"reflect"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v2/tfplan2cai/converters/google/resources/tpgresource"
transport_tpg "github.com/GoogleCloudPlatform/terraform-google-conversion/v2/tfplan2cai/converters/google/resources/transport"
)

const VertexAIIndexEndpointAssetType string = "{{region}}-aiplatform.googleapis.com/IndexEndpoint"

func ResourceConverterVertexAIIndexEndpoint() tpgresource.ResourceConverter {
return tpgresource.ResourceConverter{
AssetType: VertexAIIndexEndpointAssetType,
Convert: GetVertexAIIndexEndpointCaiObject,
}
}

func GetVertexAIIndexEndpointCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]tpgresource.Asset, error) {
name, err := tpgresource.AssetName(d, config, "//{{region}}-aiplatform.googleapis.com/projects/{{project}}/locations/{{region}}/indexEndpoints/{{name}}")
if err != nil {
return []tpgresource.Asset{}, err
}
if obj, err := GetVertexAIIndexEndpointApiObject(d, config); err == nil {
return []tpgresource.Asset{{
Name: name,
Type: VertexAIIndexEndpointAssetType,
Resource: &tpgresource.AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/{{region}}-aiplatform/v1/rest",
DiscoveryName: "IndexEndpoint",
Data: obj,
},
}}, nil
} else {
return []tpgresource.Asset{}, err
}
}

func GetVertexAIIndexEndpointApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
displayNameProp, err := expandVertexAIIndexEndpointDisplayName(d.Get("display_name"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) {
obj["displayName"] = displayNameProp
}
descriptionProp, err := expandVertexAIIndexEndpointDescription(d.Get("description"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
labelsProp, err := expandVertexAIIndexEndpointLabels(d.Get("labels"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
networkProp, err := expandVertexAIIndexEndpointNetwork(d.Get("network"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("network"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
obj["network"] = networkProp
}

return obj, nil
}

func expandVertexAIIndexEndpointDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandVertexAIIndexEndpointDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandVertexAIIndexEndpointLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandVertexAIIndexEndpointNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

0 comments on commit 1df2ec8

Please sign in to comment.