diff --git a/.changelog/11018.txt b/.changelog/11018.txt new file mode 100644 index 0000000000..87f7a8bf13 --- /dev/null +++ b/.changelog/11018.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_discovery_engine_schema` +``` \ No newline at end of file diff --git a/google-beta/provider/provider_mmv1_resources.go b/google-beta/provider/provider_mmv1_resources.go index 03bec0391f..27e48342ca 100644 --- a/google-beta/provider/provider_mmv1_resources.go +++ b/google-beta/provider/provider_mmv1_resources.go @@ -474,9 +474,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{ } // Resources -// Generated resources: 507 +// Generated resources: 508 // Generated IAM resources: 285 -// Total generated resources: 792 +// Total generated resources: 793 var generatedResources = map[string]*schema.Resource{ "google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(), "google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(), @@ -875,6 +875,7 @@ var generatedResources = map[string]*schema.Resource{ "google_dialogflow_cx_webhook": dialogflowcx.ResourceDialogflowCXWebhook(), "google_discovery_engine_chat_engine": discoveryengine.ResourceDiscoveryEngineChatEngine(), "google_discovery_engine_data_store": discoveryengine.ResourceDiscoveryEngineDataStore(), + "google_discovery_engine_schema": discoveryengine.ResourceDiscoveryEngineSchema(), "google_discovery_engine_search_engine": discoveryengine.ResourceDiscoveryEngineSearchEngine(), "google_dns_managed_zone": dns.ResourceDNSManagedZone(), "google_dns_managed_zone_iam_binding": tpgiamresource.ResourceIamBinding(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc), diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_schema.go b/google-beta/services/discoveryengine/resource_discovery_engine_schema.go new file mode 100644 index 0000000000..41cc062707 --- /dev/null +++ b/google-beta/services/discoveryengine/resource_discovery_engine_schema.go @@ -0,0 +1,319 @@ +// 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 discoveryengine + +import ( + "fmt" + "log" + "net/http" + "reflect" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func ResourceDiscoveryEngineSchema() *schema.Resource { + return &schema.Resource{ + Create: resourceDiscoveryEngineSchemaCreate, + Read: resourceDiscoveryEngineSchemaRead, + Delete: resourceDiscoveryEngineSchemaDelete, + + Importer: &schema.ResourceImporter{ + State: resourceDiscoveryEngineSchemaImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(60 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), + }, + + CustomizeDiff: customdiff.All( + tpgresource.DefaultProviderProject, + ), + + Schema: map[string]*schema.Schema{ + "data_store_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The unique id of the data store.`, + }, + "location": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The geographic location where the data store should reside. The value can +only be one of "global", "us" and "eu".`, + }, + "schema_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The unique id of the schema.`, + }, + "json_schema": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsJSON, + StateFunc: func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }, + Description: `The JSON representation of the schema.`, + ExactlyOneOf: []string{"json_schema"}, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `The unique full resource name of the schema. Values are of the format +'projects/{project}/locations/{location}/collections/{collection_id}/dataStores/{data_store_id}/schemas/{schema_id}'. +This field must be a UTF-8 encoded string with a length limit of 1024 +characters.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + UseJSONNumber: true, + } +} + +func resourceDiscoveryEngineSchemaCreate(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{}) + jsonSchemaProp, err := expandDiscoveryEngineSchemaJsonSchema(d.Get("json_schema"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("json_schema"); !tpgresource.IsEmptyValue(reflect.ValueOf(jsonSchemaProp)) && (ok || !reflect.DeepEqual(v, jsonSchemaProp)) { + obj["jsonSchema"] = jsonSchemaProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{DiscoveryEngineBasePath}}projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas?schemaId={{schema_id}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Schema: %#v", obj) + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Schema: %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 + } + + headers := make(http.Header) + 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), + Headers: headers, + }) + if err != nil { + return fmt.Errorf("Error creating Schema: %s", err) + } + + // Store the ID now + id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + err = DiscoveryEngineOperationWaitTime( + config, res, project, "Creating Schema", userAgent, + d.Timeout(schema.TimeoutCreate)) + + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create Schema: %s", err) + } + + log.Printf("[DEBUG] Finished creating Schema %q: %#v", d.Id(), res) + + return resourceDiscoveryEngineSchemaRead(d, meta) +} + +func resourceDiscoveryEngineSchemaRead(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, "{{DiscoveryEngineBasePath}}projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}") + if err != nil { + return err + } + + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Schema: %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 + } + + headers := make(http.Header) + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Headers: headers, + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("DiscoveryEngineSchema %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Schema: %s", err) + } + + if err := d.Set("name", flattenDiscoveryEngineSchemaName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Schema: %s", err) + } + if err := d.Set("json_schema", flattenDiscoveryEngineSchemaJsonSchema(res["jsonSchema"], d, config)); err != nil { + return fmt.Errorf("Error reading Schema: %s", err) + } + + return nil +} + +func resourceDiscoveryEngineSchemaDelete(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 Schema: %s", err) + } + billingProject = project + + url, err := tpgresource.ReplaceVars(d, config, "{{DiscoveryEngineBasePath}}projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}") + if err != nil { + return err + } + + var obj map[string]interface{} + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + headers := make(http.Header) + + log.Printf("[DEBUG] Deleting Schema %q", d.Id()) + 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), + Headers: headers, + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, "Schema") + } + + err = DiscoveryEngineOperationWaitTime( + config, res, project, "Deleting Schema", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting Schema %q: %#v", d.Id(), res) + return nil +} + +func resourceDiscoveryEngineSchemaImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*transport_tpg.Config) + if err := tpgresource.ParseImportId([]string{ + "^projects/(?P[^/]+)/locations/(?P[^/]+)/collections/default_collection/dataStores/(?P[^/]+)/schemas/(?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/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenDiscoveryEngineSchemaName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenDiscoveryEngineSchemaJsonSchema(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + s, err := structure.NormalizeJsonString(v) + if err != nil { + log.Printf("[ERROR] failed to normalize JSON string: %v", err) + } + return s +} + +func expandDiscoveryEngineSchemaJsonSchema(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_test.go b/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_test.go new file mode 100644 index 0000000000..f0b7af6ea6 --- /dev/null +++ b/google-beta/services/discoveryengine/resource_discovery_engine_schema_generated_test.go @@ -0,0 +1,117 @@ +// 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 discoveryengine_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/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 TestAccDiscoveryEngineSchema_discoveryengineSchemaBasicExample(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: testAccCheckDiscoveryEngineSchemaDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDiscoveryEngineSchema_discoveryengineSchemaBasicExample(context), + }, + { + ResourceName: "google_discovery_engine_schema.basic", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"data_store_id", "location", "schema_id"}, + }, + }, + }) +} + +func testAccDiscoveryEngineSchema_discoveryengineSchemaBasicExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_discovery_engine_schema" "basic" { + location = google_discovery_engine_data_store.basic.location + data_store_id = google_discovery_engine_data_store.basic.data_store_id + schema_id = "tf-test-schema-id%{random_suffix}" + json_schema = "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"datetime_detection\":true,\"type\":\"object\",\"geolocation_detection\":true}" +} + +resource "google_discovery_engine_data_store" "basic" { + location = "global" + data_store_id = "tf-test-data-store-id%{random_suffix}" + display_name = "tf-test-structured-datastore" + industry_vertical = "GENERIC" + content_config = "NO_CONTENT" + solution_types = ["SOLUTION_TYPE_SEARCH"] + create_advanced_site_search = false + skip_default_schema_creation = true +} +`, context) +} + +func testAccCheckDiscoveryEngineSchemaDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_discovery_engine_schema" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := acctest.GoogleProviderConfig(t) + + url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{DiscoveryEngineBasePath}}projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}") + if err != nil { + return err + } + + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: config.UserAgent, + }) + if err == nil { + return fmt.Errorf("DiscoveryEngineSchema still exists at %s", url) + } + } + + return nil + } +} diff --git a/google-beta/services/discoveryengine/resource_discovery_engine_schema_sweeper.go b/google-beta/services/discoveryengine/resource_discovery_engine_schema_sweeper.go new file mode 100644 index 0000000000..a839e3e3b7 --- /dev/null +++ b/google-beta/services/discoveryengine/resource_discovery_engine_schema_sweeper.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 discoveryengine + +import ( + "context" + "log" + "strings" + "testing" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/sweeper" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +func init() { + sweeper.AddTestSweepers("DiscoveryEngineSchema", testSweepDiscoveryEngineSchema) +} + +// At the time of writing, the CI only passes us-central1 as the region +func testSweepDiscoveryEngineSchema(region string) error { + resourceName := "DiscoveryEngineSchema" + log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) + + config, err := sweeper.SharedConfigForRegion(region) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) + return err + } + + err = config.LoadAndValidate(context.Background()) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) + return err + } + + t := &testing.T{} + billingId := envvar.GetTestBillingAccountFromEnv(t) + + // Setup variables to replace in list template + d := &tpgresource.ResourceDataMock{ + FieldsInSchema: map[string]interface{}{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + "billing_account": billingId, + }, + } + + listTemplate := strings.Split("https://{{location}}-discoveryengine.googleapis.com/v1/projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas", "?")[0] + listUrl, err := tpgresource.ReplaceVars(d, config, listTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) + return nil + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: config.Project, + RawURL: listUrl, + UserAgent: config.UserAgent, + }) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) + return nil + } + + resourceList, ok := res["schemas"] + if !ok { + log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") + return nil + } + + rl := resourceList.([]interface{}) + + log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) + // Keep count of items that aren't sweepable for logging. + nonPrefixCount := 0 + for _, ri := range rl { + obj := ri.(map[string]interface{}) + var name string + // Id detected in the delete URL, attempt to use id. + if obj["id"] != nil { + name = tpgresource.GetResourceNameFromSelfLink(obj["id"].(string)) + } else if obj["name"] != nil { + name = tpgresource.GetResourceNameFromSelfLink(obj["name"].(string)) + } else { + log.Printf("[INFO][SWEEPER_LOG] %s resource name and id were nil", resourceName) + return nil + } + // Skip resources that shouldn't be sweeped + if !sweeper.IsSweepableTestResource(name) { + nonPrefixCount++ + continue + } + + deleteTemplate := "https://{{location}}-discoveryengine.googleapis.com/v1/projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}" + deleteUrl, err := tpgresource.ReplaceVars(d, config, deleteTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) + return nil + } + deleteUrl = deleteUrl + name + + // Don't wait on operations as we may have a lot to delete + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "DELETE", + Project: config.Project, + RawURL: deleteUrl, + UserAgent: config.UserAgent, + }) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) + } else { + log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) + } + } + + if nonPrefixCount > 0 { + log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) + } + + return nil +} diff --git a/website/docs/r/discovery_engine_schema.html.markdown b/website/docs/r/discovery_engine_schema.html.markdown new file mode 100644 index 0000000000..8a5ef116f7 --- /dev/null +++ b/website/docs/r/discovery_engine_schema.html.markdown @@ -0,0 +1,139 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- +subcategory: "Discovery Engine" +description: |- + Schema defines the structure and layout of a type of document data. +--- + +# google_discovery_engine_schema + +Schema defines the structure and layout of a type of document data. + + +To get more information about Schema, see: + +* [API documentation](https://cloud.google.com/generative-ai-app-builder/docs/reference/rest/v1/projects.locations.collections.dataStores.schemas) +* How-to Guides + * [Provide a schema for your data store](https://cloud.google.com/generative-ai-app-builder/docs/provide-schema) + + +## Example Usage - Discoveryengine Schema Basic + + +```hcl +resource "google_discovery_engine_schema" "basic" { + location = google_discovery_engine_data_store.basic.location + data_store_id = google_discovery_engine_data_store.basic.data_store_id + schema_id = "schema-id" + json_schema = "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"datetime_detection\":true,\"type\":\"object\",\"geolocation_detection\":true}" +} + +resource "google_discovery_engine_data_store" "basic" { + location = "global" + data_store_id = "data-store-id" + display_name = "tf-test-structured-datastore" + industry_vertical = "GENERIC" + content_config = "NO_CONTENT" + solution_types = ["SOLUTION_TYPE_SEARCH"] + create_advanced_site_search = false + skip_default_schema_creation = true +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `location` - + (Required) + The geographic location where the data store should reside. The value can + only be one of "global", "us" and "eu". + +* `data_store_id` - + (Required) + The unique id of the data store. + +* `schema_id` - + (Required) + The unique id of the schema. + + +- - - + + +* `json_schema` - + (Optional) + The JSON representation of the schema. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +## 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/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}` + +* `name` - + The unique full resource name of the schema. Values are of the format + `projects/{project}/locations/{location}/collections/{collection_id}/dataStores/{data_store_id}/schemas/{schema_id}`. + This field must be a UTF-8 encoded string with a length limit of 1024 + characters. + + +## Timeouts + +This resource provides the following +[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: + +- `create` - Default is 60 minutes. +- `delete` - Default is 60 minutes. + +## Import + + +Schema can be imported using any of these accepted formats: + +* `projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}` +* `{{project}}/{{location}}/{{data_store_id}}/{{schema_id}}` +* `{{location}}/{{data_store_id}}/{{schema_id}}` + + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Schema using one of the formats above. For example: + +```tf +import { + id = "projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}" + to = google_discovery_engine_schema.default +} +``` + +When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Schema can be imported using one of the formats above. For example: + +``` +$ terraform import google_discovery_engine_schema.default projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}} +$ terraform import google_discovery_engine_schema.default {{project}}/{{location}}/{{data_store_id}}/{{schema_id}} +$ terraform import google_discovery_engine_schema.default {{location}}/{{data_store_id}}/{{schema_id}} +``` + +## User Project Overrides + +This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).