diff --git a/.changelog/9520.txt b/.changelog/9520.txt new file mode 100644 index 0000000000..5dc22ad286 --- /dev/null +++ b/.changelog/9520.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_vertexai_feature_group` +``` diff --git a/google-beta/provider/provider_mmv1_resources.go b/google-beta/provider/provider_mmv1_resources.go index 27951a0cbf..75ff3ee593 100644 --- a/google-beta/provider/provider_mmv1_resources.go +++ b/google-beta/provider/provider_mmv1_resources.go @@ -417,9 +417,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{ } // Resources -// Generated resources: 410 +// Generated resources: 411 // Generated IAM resources: 252 -// Total generated resources: 662 +// Total generated resources: 663 var generatedResources = map[string]*schema.Resource{ "google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(), "google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(), @@ -1047,6 +1047,7 @@ var generatedResources = map[string]*schema.Resource{ "google_vertex_ai_endpoint_iam_binding": tpgiamresource.ResourceIamBinding(vertexai.VertexAIEndpointIamSchema, vertexai.VertexAIEndpointIamUpdaterProducer, vertexai.VertexAIEndpointIdParseFunc), "google_vertex_ai_endpoint_iam_member": tpgiamresource.ResourceIamMember(vertexai.VertexAIEndpointIamSchema, vertexai.VertexAIEndpointIamUpdaterProducer, vertexai.VertexAIEndpointIdParseFunc), "google_vertex_ai_endpoint_iam_policy": tpgiamresource.ResourceIamPolicy(vertexai.VertexAIEndpointIamSchema, vertexai.VertexAIEndpointIamUpdaterProducer, vertexai.VertexAIEndpointIdParseFunc), + "google_vertex_ai_feature_group": vertexai.ResourceVertexAIFeatureGroup(), "google_vertex_ai_feature_online_store": vertexai.ResourceVertexAIFeatureOnlineStore(), "google_vertex_ai_featurestore": vertexai.ResourceVertexAIFeaturestore(), "google_vertex_ai_featurestore_iam_binding": tpgiamresource.ResourceIamBinding(vertexai.VertexAIFeaturestoreIamSchema, vertexai.VertexAIFeaturestoreIamUpdaterProducer, vertexai.VertexAIFeaturestoreIdParseFunc), diff --git a/google-beta/services/vertexai/resource_vertex_ai_feature_group.go b/google-beta/services/vertexai/resource_vertex_ai_feature_group.go new file mode 100644 index 0000000000..fc0c0b4cd9 --- /dev/null +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group.go @@ -0,0 +1,663 @@ +// 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-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func ResourceVertexAIFeatureGroup() *schema.Resource { + return &schema.Resource{ + Create: resourceVertexAIFeatureGroupCreate, + Read: resourceVertexAIFeatureGroupRead, + Update: resourceVertexAIFeatureGroupUpdate, + Delete: resourceVertexAIFeatureGroupDelete, + + Importer: &schema.ResourceImporter{ + State: resourceVertexAIFeatureGroupImport, + }, + + 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{ + "big_query": { + Type: schema.TypeList, + Optional: true, + Description: `Indicates that features for this group come from BigQuery Table/View. By default treats the source as a sparse time series source, which is required to have an entityId and a feature_timestamp column in the source.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "big_query_source": { + Type: schema.TypeList, + Required: true, + ForceNew: true, + Description: `The BigQuery source URI that points to either a BigQuery Table or View.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "input_uri": { + Type: schema.TypeString, + Required: true, + Description: `BigQuery URI to a table, up to 2000 characters long. For example: 'bq://projectId.bqDatasetId.bqTableId.'`, + }, + }, + }, + }, + "entity_id_columns": { + Type: schema.TypeList, + Optional: true, + Description: `Columns to construct entityId / row keys. Currently only supports 1 entity_id_column. If not provided defaults to entityId.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + "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}, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: `The resource name of the Feature Group.`, + }, + "region": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `The region of feature group. eg us-central1`, + }, + "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}, + }, + "etag": { + Type: schema.TypeString, + Computed: true, + Description: `Used to perform consistent read-modify-write updates.`, + }, + "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 resourceVertexAIFeatureGroupCreate(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{}) + nameProp, err := expandVertexAIFeatureGroupName(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 + } + descriptionProp, err := expandVertexAIFeatureGroupDescription(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 + } + bigQueryProp, err := expandVertexAIFeatureGroupBigQuery(d.Get("big_query"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("big_query"); !tpgresource.IsEmptyValue(reflect.ValueOf(bigQueryProp)) && (ok || !reflect.DeepEqual(v, bigQueryProp)) { + obj["bigQuery"] = bigQueryProp + } + labelsProp, err := expandVertexAIFeatureGroupEffectiveLabels(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?featureGroupId={{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new FeatureGroup: %#v", obj) + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for FeatureGroup: %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 FeatureGroup: %s", err) + } + + // Store the ID now + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/featureGroups/{{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 FeatureGroup", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + + return fmt.Errorf("Error waiting to create FeatureGroup: %s", err) + } + + if err := d.Set("name", flattenVertexAIFeatureGroupName(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}}/featureGroups/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating FeatureGroup %q: %#v", d.Id(), res) + + return resourceVertexAIFeatureGroupRead(d, meta) +} + +func resourceVertexAIFeatureGroupRead(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/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for FeatureGroup: %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("VertexAIFeatureGroup %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + + if err := d.Set("name", flattenVertexAIFeatureGroupName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("create_time", flattenVertexAIFeatureGroupCreateTime(res["createTime"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("update_time", flattenVertexAIFeatureGroupUpdateTime(res["updateTime"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("labels", flattenVertexAIFeatureGroupLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("description", flattenVertexAIFeatureGroupDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("big_query", flattenVertexAIFeatureGroupBigQuery(res["bigQuery"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("terraform_labels", flattenVertexAIFeatureGroupTerraformLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + if err := d.Set("effective_labels", flattenVertexAIFeatureGroupEffectiveLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading FeatureGroup: %s", err) + } + + return nil +} + +func resourceVertexAIFeatureGroupUpdate(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 FeatureGroup: %s", err) + } + billingProject = project + + obj := make(map[string]interface{}) + nameProp, err := expandVertexAIFeatureGroupName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + descriptionProp, err := expandVertexAIFeatureGroupDescription(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 + } + bigQueryProp, err := expandVertexAIFeatureGroupBigQuery(d.Get("big_query"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("big_query"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, bigQueryProp)) { + obj["bigQuery"] = bigQueryProp + } + labelsProp, err := expandVertexAIFeatureGroupEffectiveLabels(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/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating FeatureGroup %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("name") { + updateMask = append(updateMask, "name") + } + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + + if d.HasChange("big_query") { + updateMask = append(updateMask, "bigQuery") + } + + 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 FeatureGroup %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating FeatureGroup %q: %#v", d.Id(), res) + } + + err = VertexAIOperationWaitTime( + config, res, project, "Updating FeatureGroup", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } + } + + return resourceVertexAIFeatureGroupRead(d, meta) +} + +func resourceVertexAIFeatureGroupDelete(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 FeatureGroup: %s", err) + } + billingProject = project + + url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/featureGroups/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting FeatureGroup %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, "FeatureGroup") + } + + err = VertexAIOperationWaitTime( + config, res, project, "Deleting FeatureGroup", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting FeatureGroup %q: %#v", d.Id(), res) + return nil +} + +func resourceVertexAIFeatureGroupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*transport_tpg.Config) + if err := tpgresource.ParseImportId([]string{ + "^projects/(?P[^/]+)/locations/(?P[^/]+)/featureGroups/(?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/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenVertexAIFeatureGroupName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + return tpgresource.NameFromSelfLinkStateFunc(v) +} + +func flattenVertexAIFeatureGroupCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupLabels(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 flattenVertexAIFeatureGroupDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return d.Get("description") +} + +func flattenVertexAIFeatureGroupBigQuery(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["big_query_source"] = + flattenVertexAIFeatureGroupBigQueryBigQuerySource(original["bigQuerySource"], d, config) + transformed["entity_id_columns"] = + flattenVertexAIFeatureGroupBigQueryEntityIdColumns(original["entityIdColumns"], d, config) + return []interface{}{transformed} +} +func flattenVertexAIFeatureGroupBigQueryBigQuerySource(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["input_uri"] = + flattenVertexAIFeatureGroupBigQueryBigQuerySourceInputUri(original["inputUri"], d, config) + return []interface{}{transformed} +} +func flattenVertexAIFeatureGroupBigQueryBigQuerySourceInputUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupBigQueryEntityIdColumns(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenVertexAIFeatureGroupTerraformLabels(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 flattenVertexAIFeatureGroupEffectiveLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func expandVertexAIFeatureGroupName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandVertexAIFeatureGroupDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandVertexAIFeatureGroupBigQuery(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedBigQuerySource, err := expandVertexAIFeatureGroupBigQueryBigQuerySource(original["big_query_source"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBigQuerySource); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["bigQuerySource"] = transformedBigQuerySource + } + + transformedEntityIdColumns, err := expandVertexAIFeatureGroupBigQueryEntityIdColumns(original["entity_id_columns"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEntityIdColumns); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["entityIdColumns"] = transformedEntityIdColumns + } + + return transformed, nil +} + +func expandVertexAIFeatureGroupBigQueryBigQuerySource(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedInputUri, err := expandVertexAIFeatureGroupBigQueryBigQuerySourceInputUri(original["input_uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedInputUri); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["inputUri"] = transformedInputUri + } + + return transformed, nil +} + +func expandVertexAIFeatureGroupBigQueryBigQuerySourceInputUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandVertexAIFeatureGroupBigQueryEntityIdColumns(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandVertexAIFeatureGroupEffectiveLabels(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-beta/services/vertexai/resource_vertex_ai_feature_group_generated_test.go b/google-beta/services/vertexai/resource_vertex_ai_feature_group_generated_test.go new file mode 100644 index 0000000000..dfe6c5a958 --- /dev/null +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group_generated_test.go @@ -0,0 +1,143 @@ +// 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-beta/google-beta/acctest" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func TestAccVertexAIFeatureGroup_vertexAiFeatureGroupExample(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: testAccCheckVertexAIFeatureGroupDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAIFeatureGroup_vertexAiFeatureGroupExample(context), + }, + { + ResourceName: "google_vertex_ai_feature_group.feature_group", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "region", "description", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccVertexAIFeatureGroup_vertexAiFeatureGroupExample(context map[string]interface{}) string { + return acctest.Nprintf(` + resource "google_vertex_ai_feature_group" "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-beta/services/vertexai/resource_vertex_ai_feature_group_test.go b/google-beta/services/vertexai/resource_vertex_ai_feature_group_test.go new file mode 100644 index 0000000000..697832d0a9 --- /dev/null +++ b/google-beta/services/vertexai/resource_vertex_ai_feature_group_test.go @@ -0,0 +1,140 @@ +// 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-beta/google-beta/acctest" +) + +func TestAccVertexAIFeatureGroup_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: testAccCheckVertexAIFeatureGroupDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAIFeatureGroup_basic(context), + }, + { + ResourceName: "google_vertex_ai_feature_group.feature_group", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "region", "description", "labels", "terraform_labels"}, + }, + { + Config: testAccVertexAIFeatureGroup_updated(context), + }, + { + ResourceName: "google_vertex_ai_feature_group.feature_group", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"etag", "region", "description", "labels", "terraform_labels"}, + }, + }, + }) +} + +func testAccVertexAIFeatureGroup_basic(context map[string]interface{}) string { + return acctest.Nprintf(` + resource "google_vertex_ai_feature_group" "feature_group" { + name = "tf_test_feature_group%{random_suffix}" + description = "A sample feature group" + region = "us-central1" + labels = { + label-one = "value-one" + } + big_query { + big_query_source { + 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 + + +```hcl + resource "google_vertex_ai_feature_group" "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 = <The `big_query` block supports: + +* `big_query_source` - + (Required) + The BigQuery source URI that points to either a BigQuery Table or View. + Structure is [documented below](#nested_big_query_source). + +* `entity_id_columns` - + (Optional) + Columns to construct entityId / row keys. Currently only supports 1 entity_id_column. If not provided defaults to entityId. + + +The `big_query_source` block supports: + +* `input_uri` - + (Required) + BigQuery URI to a table, up to 2000 characters long. For example: `bq://projectId.bqDatasetId.bqTableId.` + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{region}}/featureGroups/{{name}}` + +* `create_time` - + The timestamp of when the FeatureGroup was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. + +* `update_time` - + The timestamp of when the FeatureGroup was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. + +* `etag` - + Used to perform consistent read-modify-write updates. + +* `terraform_labels` - + The combination of labels configured directly on the resource + and default labels configured on the provider. + +* `effective_labels` - + All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. + + +## Timeouts + +This resource provides the following +[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: + +- `create` - Default is 20 minutes. +- `update` - Default is 20 minutes. +- `delete` - Default is 20 minutes. + +## Import + + +FeatureGroup can be imported using any of these accepted formats: + +* `projects/{{project}}/locations/{{region}}/featureGroups/{{name}}` +* `{{project}}/{{region}}/{{name}}` +* `{{region}}/{{name}}` +* `{{name}}` + + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import FeatureGroup using one of the formats above. For example: + +```tf +import { + id = "projects/{{project}}/locations/{{region}}/featureGroups/{{name}}" + to = google_vertex_ai_feature_group.default +} +``` + +When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), FeatureGroup can be imported using one of the formats above. For example: + +``` +$ terraform import google_vertex_ai_feature_group.default projects/{{project}}/locations/{{region}}/featureGroups/{{name}} +$ terraform import google_vertex_ai_feature_group.default {{project}}/{{region}}/{{name}} +$ terraform import google_vertex_ai_feature_group.default {{region}}/{{name}} +$ terraform import google_vertex_ai_feature_group.default {{name}} +``` + +## User Project Overrides + +This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).