From 3c4811fa4516c2826a8524a40714791023a70f7d Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 7 Jun 2023 21:33:04 +0000 Subject: [PATCH] feat(vertexai): add parameter `region` to `google_vertex_ai_featurestore_entitytype_feature` (#6992) * feat: add parameter region to google_vertex_ai_featurestore_entitytype_feature * feat: update code to use tpgresource and transport_tpg * fix: update a description of the field * refactor: update regex to validate id of an entity type * fix: remove an no longer used yaml file * fix: fix the files to update the regex Signed-off-by: Modular Magician --- .changelog/6992.txt | 3 ++ ...rtex_ai_featurestore_entitytype_feature.go | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .changelog/6992.txt diff --git a/.changelog/6992.txt b/.changelog/6992.txt new file mode 100644 index 0000000000..9bbed8974c --- /dev/null +++ b/.changelog/6992.txt @@ -0,0 +1,3 @@ +```release-note:bug +vertexai: made google_vertex_ai_featurestore_entitytype_feature always use regional corresponding to parent's region +``` diff --git a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go index e2a21aade7..af25182517 100644 --- a/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go +++ b/google-beta/services/vertexai/resource_vertex_ai_featurestore_entitytype_feature.go @@ -93,6 +93,11 @@ func ResourceVertexAIFeaturestoreEntitytypeFeature() *schema.Resource { Computed: true, Description: `The timestamp when the entity type was most recently updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`, }, + "region": { + Type: schema.TypeString, + Computed: true, + Description: "The region of the feature", + }, }, UseJSONNumber: true, } @@ -126,6 +131,11 @@ func resourceVertexAIFeaturestoreEntitytypeFeatureCreate(d *schema.ResourceData, obj["valueType"] = valueTypeProp } + obj, err = resourceVertexAIFeaturestoreEntitytypeFeatureEncoder(d, meta, obj) + if err != nil { + return err + } + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}{{entitytype}}/features?featureId={{name}}") if err != nil { return err @@ -265,6 +275,11 @@ func resourceVertexAIFeaturestoreEntitytypeFeatureUpdate(d *schema.ResourceData, obj["description"] = descriptionProp } + obj, err = resourceVertexAIFeaturestoreEntitytypeFeatureEncoder(d, meta, obj) + if err != nil { + return err + } + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}{{entitytype}}/features/{{name}}") if err != nil { return err @@ -383,6 +398,13 @@ func resourceVertexAIFeaturestoreEntitytypeFeatureImport(d *schema.ResourceData, } d.SetId(id) + entitytype := d.Get("entitytype").(string) + + re := regexp.MustCompile("^projects/(.+)/locations/(.+)/featurestores/(.+)/entityTypes/(.+)$") + if parts := re.FindStringSubmatch(entitytype); parts != nil { + d.Set("region", parts[2]) + } + return []*schema.ResourceData{d}, nil } @@ -424,3 +446,14 @@ func expandVertexAIFeaturestoreEntitytypeFeatureDescription(v interface{}, d tpg func expandVertexAIFeaturestoreEntitytypeFeatureValueType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } + +func resourceVertexAIFeaturestoreEntitytypeFeatureEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + if v, ok := d.GetOk("entitytype"); ok { + re := regexp.MustCompile("^projects/(.+)/locations/(.+)/featurestores/(.+)/entityTypes/(.+)$") + if parts := re.FindStringSubmatch(v.(string)); parts != nil { + d.Set("region", parts[2]) + } + } + + return obj, nil +}