Skip to content

Commit

Permalink
add vertexai/featureonlinestore resource (#9632) (#16857)
Browse files Browse the repository at this point in the history
* rebase featureonlinestore based on merged changes

* rebase based on merged featureonlinestore pr

* fix pr suggestions featureonlinestore

* fix documentation and pr comments featureonlinestore
[upstream:f6b6532046e9886815386703ebdbfc9cfbcada93]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 21, 2023
1 parent 211e756 commit d73f132
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 202 deletions.
9 changes: 9 additions & 0 deletions .changelog/9632.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:enhancement
vertexai: added `force_destroy` field to `google_vertex_ai_feature_online_store` resource
```
```release-note:enhancement
vertexai: added `optimized`, `dedicated_serving_endpoint` and `embedding_management` fields to `google_vertex_ai_feature_online_store` resource (beta)
```
```release-note:bug
vertexai: changed `region` field from required to optional in `google_vertex_ai_feature_online_store` resource
```
64 changes: 33 additions & 31 deletions google/services/vertexai/resource_vertex_ai_feature_online_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ func ResourceVertexAIFeatureOnlineStore() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The resource name of the Feature Online Store.`,
},
"region": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The region of feature online store. eg us-central1`,
Description: `The resource name of the Feature Online Store. This value may be up to 60 characters, and valid characters are [a-z0-9_]. The first character cannot be a number.`,
},
"bigtable": {
Type: schema.TypeList,
Expand Down Expand Up @@ -101,6 +95,7 @@ func ResourceVertexAIFeatureOnlineStore() *schema.Resource {
},
},
},
ExactlyOneOf: []string{"bigtable"},
},
"labels": {
Type: schema.TypeMap,
Expand All @@ -111,6 +106,13 @@ func ResourceVertexAIFeatureOnlineStore() *schema.Resource {
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"region": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The region of feature online store. eg us-central1`,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -144,6 +146,12 @@ Please refer to the field 'effective_labels' for all of the labels present on th
Computed: true,
Description: `The timestamp of when the feature online store was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`,
},
"force_destroy": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: `If set to true, any FeatureViews and Features for this FeatureOnlineStore will also be deleted.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -163,12 +171,6 @@ func resourceVertexAIFeatureOnlineStoreCreate(d *schema.ResourceData, meta inter
}

obj := make(map[string]interface{})
nameProp, err := expandVertexAIFeatureOnlineStoreName(d.Get("name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
bigtableProp, err := expandVertexAIFeatureOnlineStoreBigtable(d.Get("bigtable"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -234,10 +236,6 @@ func resourceVertexAIFeatureOnlineStoreCreate(d *schema.ResourceData, meta inter
return fmt.Errorf("Error waiting to create FeatureOnlineStore: %s", err)
}

if err := d.Set("name", flattenVertexAIFeatureOnlineStoreName(opRes["name"], d, config)); err != nil {
return err
}

// This may have caused the ID to update - update it if so.
id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/featureOnlineStores/{{name}}")
if err != nil {
Expand Down Expand Up @@ -286,13 +284,16 @@ func resourceVertexAIFeatureOnlineStoreRead(d *schema.ResourceData, meta interfa
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("VertexAIFeatureOnlineStore %q", d.Id()))
}

// Explicitly set virtual fields to default values if unset
if _, ok := d.GetOkExists("force_destroy"); !ok {
if err := d.Set("force_destroy", false); err != nil {
return fmt.Errorf("Error setting force_destroy: %s", err)
}
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading FeatureOnlineStore: %s", err)
}

if err := d.Set("name", flattenVertexAIFeatureOnlineStoreName(res["name"], d, config)); err != nil {
return fmt.Errorf("Error reading FeatureOnlineStore: %s", err)
}
if err := d.Set("create_time", flattenVertexAIFeatureOnlineStoreCreateTime(res["createTime"], d, config)); err != nil {
return fmt.Errorf("Error reading FeatureOnlineStore: %s", err)
}
Expand Down Expand Up @@ -425,6 +426,13 @@ func resourceVertexAIFeatureOnlineStoreDelete(d *schema.ResourceData, meta inter
}

var obj map[string]interface{}

if v, ok := d.GetOk("force_destroy"); ok {
url, err = transport_tpg.AddQueryParams(url, map[string]string{"force": fmt.Sprintf("%v", v)})
if err != nil {
return err
}
}
log.Printf("[DEBUG] Deleting FeatureOnlineStore %q", d.Id())

// err == nil indicates that the billing_project value was found
Expand Down Expand Up @@ -475,14 +483,12 @@ func resourceVertexAIFeatureOnlineStoreImport(d *schema.ResourceData, meta inter
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
}

func flattenVertexAIFeatureOnlineStoreName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
// Explicitly set virtual fields to default values on import
if err := d.Set("force_destroy", false); err != nil {
return nil, fmt.Errorf("Error setting force_destroy: %s", err)
}
return tpgresource.NameFromSelfLinkStateFunc(v)

return []*schema.ResourceData{d}, nil
}

func flattenVertexAIFeatureOnlineStoreCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down Expand Up @@ -612,10 +618,6 @@ func flattenVertexAIFeatureOnlineStoreEffectiveLabels(v interface{}, d *schema.R
return v
}

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

func expandVertexAIFeatureOnlineStoreBigtable(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,27 @@ func TestAccVertexAIFeatureOnlineStore_vertexAiFeatureOnlineStoreExample(t *test
ResourceName: "google_vertex_ai_feature_online_store.feature_online_store",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "region", "labels", "terraform_labels"},
ImportStateVerifyIgnore: []string{"name", "etag", "region", "force_destroy", "labels", "terraform_labels"},
},
},
})
}

func testAccVertexAIFeatureOnlineStore_vertexAiFeatureOnlineStoreExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource google_vertex_ai_feature_online_store "feature_online_store" {
name = "tf_test_example_feature_online_store%{random_suffix}"
region = "us-central1"
labels = {
label-one = "value-one"
}
bigtable {
auto_scaling {
min_node_count = 1
max_node_count = 2
cpu_utilization_target = 60
}
resource "google_vertex_ai_feature_online_store" "feature_online_store" {
name = "tf_test_example_feature_online_store%{random_suffix}"
labels = {
foo = "bar"
}
region = "us-central1"
bigtable {
auto_scaling {
min_node_count = 1
max_node_count = 3
cpu_utilization_target = 50
}
}
}
`, context)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccVertexAIFeatureOnlineStore_updated(t *testing.T) {
ResourceName: "google_vertex_ai_feature_online_store.feature_online_store",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "region", "labels", "terraform_labels"},
ImportStateVerifyIgnore: []string{"name", "etag", "region", "force_destroy", "labels", "terraform_labels"},
},
{
Config: testAccVertexAIFeatureOnlineStore_updated(context),
Expand All @@ -38,7 +38,7 @@ func TestAccVertexAIFeatureOnlineStore_updated(t *testing.T) {
ResourceName: "google_vertex_ai_feature_online_store.feature_online_store",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "region", "labels", "terraform_labels"},
ImportStateVerifyIgnore: []string{"name", "etag", "region", "force_destroy", "labels", "terraform_labels"},
},
},
})
Expand All @@ -60,6 +60,7 @@ resource google_vertex_ai_feature_online_store "feature_online_store" {
cpu_utilization_target = 60
}
}
force_destroy = true
}
`, context)
}
Expand All @@ -80,6 +81,7 @@ resource google_vertex_ai_feature_online_store "feature_online_store" {
max_node_count = 3
}
}
force_destroy = true
}
`, context)
}
Loading

0 comments on commit d73f132

Please sign in to comment.