From fb41a01f54a0fcb6fdff9aab4250da46a02eb2cf Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 16 Jan 2024 22:36:44 +0000 Subject: [PATCH] feat(vertexai): Support google_vertex_ai_feature_group_feature (#9692) * feat(vertexai): Support google_vertex_ai_feature_group_feature * feat(vertexai): Support google_vertex_ai_feature_group_feature (take 2) * feat(vertexai): update code based on feedback * test: allow 2024 for copyrights * feat(vertexai): update code to use standard url [upstream:b45adda3a0beab8f795530e2cce46a25d156f0b8] Signed-off-by: Modular Magician --- .changelog/9692.txt | 3 + google/provider/provider_mmv1_resources.go | 5 +- ...esource_vertex_ai_feature_group_feature.go | 522 ++++++++++++++++++ ...ai_feature_group_feature_generated_test.go | 249 +++++++++ ...vertex_ai_feature_group_feature_sweeper.go | 139 +++++ ...ce_vertex_ai_feature_group_feature_test.go | 186 +++++++ ...tex_ai_feature_group_feature.html.markdown | 200 +++++++ 7 files changed, 1302 insertions(+), 2 deletions(-) create mode 100644 .changelog/9692.txt create mode 100644 google/services/vertexai/resource_vertex_ai_feature_group_feature.go create mode 100644 google/services/vertexai/resource_vertex_ai_feature_group_feature_generated_test.go create mode 100644 google/services/vertexai/resource_vertex_ai_feature_group_feature_sweeper.go create mode 100644 google/services/vertexai/resource_vertex_ai_feature_group_feature_test.go create mode 100644 website/docs/r/vertex_ai_feature_group_feature.html.markdown diff --git a/.changelog/9692.txt b/.changelog/9692.txt new file mode 100644 index 00000000000..a5ae0b3c2a9 --- /dev/null +++ b/.changelog/9692.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_vertex_ai_feature_group_feature` +``` diff --git a/google/provider/provider_mmv1_resources.go b/google/provider/provider_mmv1_resources.go index b5e17d078c8..b6e7f689b07 100644 --- a/google/provider/provider_mmv1_resources.go +++ b/google/provider/provider_mmv1_resources.go @@ -379,9 +379,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{ } // Resources -// Generated resources: 367 +// Generated resources: 368 // Generated IAM resources: 222 -// Total generated resources: 589 +// Total generated resources: 590 var generatedResources = map[string]*schema.Resource{ "google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(), "google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(), @@ -932,6 +932,7 @@ var generatedResources = map[string]*schema.Resource{ "google_vertex_ai_dataset": vertexai.ResourceVertexAIDataset(), "google_vertex_ai_endpoint": vertexai.ResourceVertexAIEndpoint(), "google_vertex_ai_feature_group": vertexai.ResourceVertexAIFeatureGroup(), + "google_vertex_ai_feature_group_feature": vertexai.ResourceVertexAIFeatureGroupFeature(), "google_vertex_ai_feature_online_store": vertexai.ResourceVertexAIFeatureOnlineStore(), "google_vertex_ai_feature_online_store_featureview": vertexai.ResourceVertexAIFeatureOnlineStoreFeatureview(), "google_vertex_ai_featurestore": vertexai.ResourceVertexAIFeaturestore(), diff --git a/google/services/vertexai/resource_vertex_ai_feature_group_feature.go b/google/services/vertexai/resource_vertex_ai_feature_group_feature.go new file mode 100644 index 00000000000..7612bd3a9a6 --- /dev/null +++ b/google/services/vertexai/resource_vertex_ai_feature_group_feature.go @@ -0,0 +1,522 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** 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 ( + "fmt" + "log" + "reflect" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/hashicorp/terraform-provider-google/google/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" +) + +func ResourceVertexAIFeatureGroupFeature() *schema.Resource { + return &schema.Resource{ + Create: resourceVertexAIFeatureGroupFeatureCreate, + Read: resourceVertexAIFeatureGroupFeatureRead, + Update: resourceVertexAIFeatureGroupFeatureUpdate, + Delete: resourceVertexAIFeatureGroupFeatureDelete, + + Importer: &schema.ResourceImporter{ + State: resourceVertexAIFeatureGroupFeatureImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(20 * time.Minute), + Update: schema.DefaultTimeout(20 * time.Minute), + Delete: schema.DefaultTimeout(20 * time.Minute), + }, + + CustomizeDiff: customdiff.All( + tpgresource.SetLabelsDiff, + tpgresource.DefaultProviderProject, + ), + + Schema: map[string]*schema.Schema{ + "feature_group": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The name of the Feature Group.`, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The resource name of the Feature Group Feature.`, + }, + "region": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The region for the resource. It should be the same as the feature group's region.`, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: `The description of the FeatureGroup.`, + }, + "labels": { + Type: schema.TypeMap, + Optional: true, + Description: `The labels with user-defined metadata to organize your FeatureGroup. + +**Note**: This field is non-authoritative, and will only manage the labels present in your configuration. +Please refer to the field 'effective_labels' for all of the labels present on the resource.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "version_column_name": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: `The name of the BigQuery Table/View column hosting data for this version. If no value is provided, will use featureId.`, + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: `The timestamp of when the FeatureGroup was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`, + }, + "effective_labels": { + Type: schema.TypeMap, + Computed: true, + Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "terraform_labels": { + Type: schema.TypeMap, + Computed: true, + Description: `The combination of labels configured directly on the resource + and default labels configured on the provider.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: `The timestamp of when the FeatureGroup was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + UseJSONNumber: true, + } +} + +func resourceVertexAIFeatureGroupFeatureCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + descriptionProp, err := expandVertexAIFeatureGroupFeatureDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + versionColumnNameProp, err := expandVertexAIFeatureGroupFeatureVersionColumnName(d.Get("version_column_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("version_column_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(versionColumnNameProp)) && (ok || !reflect.DeepEqual(v, versionColumnNameProp)) { + obj["versionColumnName"] = versionColumnNameProp + } + labelsProp, err := expandVertexAIFeatureGroupFeatureEffectiveLabels(d.Get("effective_labels"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features?featureId={{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new FeatureGroupFeature: %#v", obj) + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for FeatureGroupFeature: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return fmt.Errorf("Error creating FeatureGroupFeature: %s", err) + } + + // Store the ID now + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + // Use the resource in the operation response to populate + // identity fields and d.Id() before read + var opRes map[string]interface{} + err = VertexAIOperationWaitTimeWithResponse( + config, res, &opRes, project, "Creating FeatureGroupFeature", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + + return fmt.Errorf("Error waiting to create FeatureGroupFeature: %s", err) + } + + // This may have caused the ID to update - update it if so. + id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating FeatureGroupFeature %q: %#v", d.Id(), res) + + return resourceVertexAIFeatureGroupFeatureRead(d, meta) +} + +func resourceVertexAIFeatureGroupFeatureRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for FeatureGroupFeature: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("VertexAIFeatureGroupFeature %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + + if err := d.Set("create_time", flattenVertexAIFeatureGroupFeatureCreateTime(res["createTime"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + if err := d.Set("update_time", flattenVertexAIFeatureGroupFeatureUpdateTime(res["updateTime"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + if err := d.Set("labels", flattenVertexAIFeatureGroupFeatureLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + if err := d.Set("description", flattenVertexAIFeatureGroupFeatureDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + if err := d.Set("version_column_name", flattenVertexAIFeatureGroupFeatureVersionColumnName(res["versionColumnName"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + if err := d.Set("terraform_labels", flattenVertexAIFeatureGroupFeatureTerraformLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + if err := d.Set("effective_labels", flattenVertexAIFeatureGroupFeatureEffectiveLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroupFeature: %s", err) + } + + return nil +} + +func resourceVertexAIFeatureGroupFeatureUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for FeatureGroupFeature: %s", err) + } + billingProject = project + + obj := make(map[string]interface{}) + descriptionProp, err := expandVertexAIFeatureGroupFeatureDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + versionColumnNameProp, err := expandVertexAIFeatureGroupFeatureVersionColumnName(d.Get("version_column_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("version_column_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, versionColumnNameProp)) { + obj["versionColumnName"] = versionColumnNameProp + } + labelsProp, err := expandVertexAIFeatureGroupFeatureEffectiveLabels(d.Get("effective_labels"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating FeatureGroupFeature %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + + if d.HasChange("version_column_name") { + updateMask = append(updateMask, "versionColumnName") + } + + if d.HasChange("effective_labels") { + updateMask = append(updateMask, "labels") + } + // updateMask is a URL parameter but not present in the schema, so ReplaceVars + // won't set it + url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + // if updateMask is empty we are not updating anything so skip the post + if len(updateMask) > 0 { + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + + if err != nil { + return fmt.Errorf("Error updating FeatureGroupFeature %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating FeatureGroupFeature %q: %#v", d.Id(), res) + } + + err = VertexAIOperationWaitTime( + config, res, project, "Updating FeatureGroupFeature", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } + } + + return resourceVertexAIFeatureGroupFeatureRead(d, meta) +} + +func resourceVertexAIFeatureGroupFeatureDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for FeatureGroupFeature: %s", err) + } + billingProject = project + + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting FeatureGroupFeature %q", d.Id()) + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "DELETE", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutDelete), + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, "FeatureGroupFeature") + } + + err = VertexAIOperationWaitTime( + config, res, project, "Deleting FeatureGroupFeature", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting FeatureGroupFeature %q: %#v", d.Id(), res) + return nil +} + +func resourceVertexAIFeatureGroupFeatureImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*transport_tpg.Config) + if err := tpgresource.ParseImportId([]string{ + "^projects/(?P[^/]+)/locations/(?P[^/]+)/featureGroups/(?P[^/]+)/features/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)$", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/featureGroups/{{feature_group}}/features/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenVertexAIFeatureGroupFeatureCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupFeatureUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupFeatureLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + + transformed := make(map[string]interface{}) + if l, ok := d.GetOkExists("labels"); ok { + for k := range l.(map[string]interface{}) { + transformed[k] = v.(map[string]interface{})[k] + } + } + + return transformed +} + +func flattenVertexAIFeatureGroupFeatureDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupFeatureVersionColumnName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupFeatureTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + + transformed := make(map[string]interface{}) + if l, ok := d.GetOkExists("terraform_labels"); ok { + for k := range l.(map[string]interface{}) { + transformed[k] = v.(map[string]interface{})[k] + } + } + + return transformed +} + +func flattenVertexAIFeatureGroupFeatureEffectiveLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func expandVertexAIFeatureGroupFeatureDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandVertexAIFeatureGroupFeatureVersionColumnName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandVertexAIFeatureGroupFeatureEffectiveLabels(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 +} diff --git a/google/services/vertexai/resource_vertex_ai_feature_group_feature_generated_test.go b/google/services/vertexai/resource_vertex_ai_feature_group_feature_generated_test.go new file mode 100644 index 00000000000..3d6e42ca4e7 --- /dev/null +++ b/google/services/vertexai/resource_vertex_ai_feature_group_feature_generated_test.go @@ -0,0 +1,249 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** 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_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" +) + +func TestAccVertexAIFeatureGroupFeature_vertexAiFeatureGroupFeatureExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckVertexAIFeatureGroupFeatureDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAIFeatureGroupFeature_vertexAiFeatureGroupFeatureExample(context), + }, + { + ResourceName: "google_vertex_ai_feature_group_feature.feature_group_feature", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"name", "feature_group", "region", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccVertexAIFeatureGroupFeature_vertexAiFeatureGroupFeatureExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_vertex_ai_feature_group_feature" "feature_group_feature" { + name = "tf_test_example_feature%{random_suffix}" + region = "us-central1" + feature_group = google_vertex_ai_feature_group.sample_feature_group.name + description = "A sample feature" + labels = { + label-one = "value-one" + } +} + + +resource "google_vertex_ai_feature_group" "sample_feature_group" { + name = "tf_test_example_feature_group%{random_suffix}" + description = "A sample feature group" + region = "us-central1" + labels = { + label-one = "value-one" + } + big_query { + big_query_source { + # The source table must have a column named 'feature_timestamp' of type TIMESTAMP. + input_uri = "bq://${google_bigquery_table.sample_table.project}.${google_bigquery_table.sample_table.dataset_id}.${google_bigquery_table.sample_table.table_id}" + } + entity_id_columns = ["feature_id"] + } +} + +resource "google_bigquery_dataset" "sample_dataset" { + dataset_id = "tf_test_job_load%{random_suffix}_dataset" + friendly_name = "test" + description = "This is a test description" + location = "US" +} + +resource "google_bigquery_table" "sample_table" { + deletion_protection = false + dataset_id = google_bigquery_dataset.sample_dataset.dataset_id + table_id = "tf_test_job_load%{random_suffix}_table" + + schema = < 0 { + log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) + } + + return nil +} diff --git a/google/services/vertexai/resource_vertex_ai_feature_group_feature_test.go b/google/services/vertexai/resource_vertex_ai_feature_group_feature_test.go new file mode 100644 index 00000000000..83643482f91 --- /dev/null +++ b/google/services/vertexai/resource_vertex_ai_feature_group_feature_test.go @@ -0,0 +1,186 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package vertexai_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccVertexAIFeatureGroupFeature_updated(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckVertexAIFeatureGroupFeatureDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAIFeatureGroupFeature_basic(context), + }, + { + ResourceName: "google_vertex_ai_feature_group_feature.feature_group_feature", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"feature_group", "labels", "terraform_labels"}, + }, + { + Config: testAccVertexAIFeatureGroupFeature_updated(context), + }, + { + ResourceName: "google_vertex_ai_feature_group_feature.feature_group_feature", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"feature_group", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccVertexAIFeatureGroupFeature_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_vertex_ai_feature_group_feature" "feature_group_feature" { + name = "tf_test_example_feature%{random_suffix}" + region = "us-central1" + feature_group = google_vertex_ai_feature_group.sample_feature_group.name + description = "A sample feature" + labels = { + label-one = "value-one" + } + version_column_name = "tf_test_example_feature_v1_%{random_suffix}" +} + + +resource "google_vertex_ai_feature_group" "sample_feature_group" { + name = "tf_test_example_feature_group%{random_suffix}" + description = "A sample feature group" + region = "us-central1" + labels = { + label-one = "value-one" + } + big_query { + big_query_source { + # The source table must have a column named 'feature_timestamp' of type TIMESTAMP. + input_uri = "bq://${google_bigquery_table.sample_table.project}.${google_bigquery_table.sample_table.dataset_id}.${google_bigquery_table.sample_table.table_id}" + } + entity_id_columns = ["feature_id"] + } +} + +resource "google_bigquery_dataset" "sample_dataset" { + dataset_id = "tf_test_job_load%{random_suffix}_dataset" + friendly_name = "test" + description = "This is a test description" + location = "US" +} + +resource "google_bigquery_table" "sample_table" { + deletion_protection = false + dataset_id = google_bigquery_dataset.sample_dataset.dataset_id + table_id = "tf_test_job_load%{random_suffix}_table" + + schema = < + + Open in Cloud Shell + + +## Example Usage - Vertex Ai Feature Group Feature + + +```hcl +resource "google_vertex_ai_feature_group_feature" "feature_group_feature" { + name = "example_feature" + region = "us-central1" + feature_group = google_vertex_ai_feature_group.sample_feature_group.name + description = "A sample feature" + labels = { + label-one = "value-one" + } +} + + +resource "google_vertex_ai_feature_group" "sample_feature_group" { + name = "example_feature_group" + description = "A sample feature group" + region = "us-central1" + labels = { + label-one = "value-one" + } + big_query { + big_query_source { + # The source table must have a column named 'feature_timestamp' of type TIMESTAMP. + input_uri = "bq://${google_bigquery_table.sample_table.project}.${google_bigquery_table.sample_table.dataset_id}.${google_bigquery_table.sample_table.table_id}" + } + entity_id_columns = ["feature_id"] + } +} + +resource "google_bigquery_dataset" "sample_dataset" { + dataset_id = "job_load_dataset" + friendly_name = "test" + description = "This is a test description" + location = "US" +} + +resource "google_bigquery_table" "sample_table" { + deletion_protection = false + dataset_id = google_bigquery_dataset.sample_dataset.dataset_id + table_id = "job_load_table" + + schema = <