Skip to content

Commit 5bea460

Browse files
Add a resource: Discovery Engine Data Store (#9860) (#6892)
* Create a configuration file product.yaml for product discoveryengine * Create resource DataStore configuration file template DataStore.yaml * Modify resource DataStore configuration file template to match the API resource's documented behavior * Add each API resource field to configuration file properties attribute * Add IAM support in Terraform to match DataStore API resource IAM support * Polish field contents in product configuration file. * Modify DataStore.yaml for LRO handling, parameters matching and readability improvement. * Add a DataStore create test. * Modify product name from DiscoveryEngine to Discoveryengine so that generated resource name would be google_discoveryengine_data_store * change to GA in doc (#9491) * Add value of to template into the generated tests to fix error 'fmt.Sprintf format %s reads arg #3, but call has 2 args'. * Remove Api::Product::ApiReference to match the change GoogleCloudPlatform/magic-modules#9536 * Add var collection_id to unit test examples in resource config. * Fix argument missing error in unit tests. * Update resource create unit test case fields to contain display_name, industry_vertical, content_config. * Fix errors in acceptance tests: now acc test fails at invalid parent field of CreateDataStoreRequest. * Set collection_id as default_collection. * Remove uncessary variables under unit test example. * Fix acceptance tests issues by (1) removing iam_policy and (2) adding import_format. * Clean up configs: (1) update api version for tpg-beta to v1alpha; (2) remove fields for std Update method; (3) rename structured datastore example. * Add examples and tests for all types of DataStore. * Remove redundant field project from create test examples. * Fix lint-yaml check failure. * Add field solution_types to acceptance tests to satisfy coverage requirements. * Clean up industry_vertical enum values. * Add a new query parameter createAdvancedSiteSearch to create_url. * Add a create test for advanced site search data store. * Add IAM roles/discoveryengine.admin. * Remove role config from .ci/infra/terraform/main.tf * Remove beta version in product.yaml because both ga and beta versions have the same base_url. * Rename product from Discoveryengine to DiscoveryEngine. * Remove unnecessary configs and improve description readability. * Mark property solution_types as immutable. * Add update related settings and update test. * Add delete_url for resource's Delete method. * Remove all but one test example. * Rename test example to make it more generic. * Modify first template in update test to omit all non-required fields. * Fix the update test: update display_name not data_store_id. * Modify property description: remove brackets. * Update API version from v1alpha to v1. * Support regional APIs. * Modify API reference link. --------- [upstream:22bc30cf4a1c101412f34ef2ac84b3b089f63e0c] Signed-off-by: Modular Magician <[email protected]>
1 parent cf2e5c2 commit 5bea460

15 files changed

+1097
-2
lines changed

.changelog/9860.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_discovery_engine_data_store`
3+
```

.teamcity/components/generated/services.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ var services = mapOf(
301301
"displayName" to "Dialogflowcx",
302302
"path" to "./google-beta/services/dialogflowcx"
303303
),
304+
"discoveryengine" to mapOf(
305+
"name" to "discoveryengine",
306+
"displayName" to "Discoveryengine",
307+
"path" to "./google-beta/services/discoveryengine"
308+
),
304309
"dns" to mapOf(
305310
"name" to "dns",
306311
"displayName" to "Dns",

google-beta/fwmodels/provider_model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type ProviderModel struct {
7878
DeploymentManagerCustomEndpoint types.String `tfsdk:"deployment_manager_custom_endpoint"`
7979
DialogflowCustomEndpoint types.String `tfsdk:"dialogflow_custom_endpoint"`
8080
DialogflowCXCustomEndpoint types.String `tfsdk:"dialogflow_cx_custom_endpoint"`
81+
DiscoveryEngineCustomEndpoint types.String `tfsdk:"discovery_engine_custom_endpoint"`
8182
DNSCustomEndpoint types.String `tfsdk:"dns_custom_endpoint"`
8283
DocumentAICustomEndpoint types.String `tfsdk:"document_ai_custom_endpoint"`
8384
DocumentAIWarehouseCustomEndpoint types.String `tfsdk:"document_ai_warehouse_custom_endpoint"`

google-beta/fwprovider/framework_provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
449449
transport_tpg.CustomEndpointValidator(),
450450
},
451451
},
452+
"discovery_engine_custom_endpoint": &schema.StringAttribute{
453+
Optional: true,
454+
Validators: []validator.String{
455+
transport_tpg.CustomEndpointValidator(),
456+
},
457+
},
452458
"dns_custom_endpoint": &schema.StringAttribute{
453459
Optional: true,
454460
Validators: []validator.String{

google-beta/fwtransport/framework_config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ type FrameworkProviderConfig struct {
103103
DeploymentManagerBasePath string
104104
DialogflowBasePath string
105105
DialogflowCXBasePath string
106+
DiscoveryEngineBasePath string
106107
DNSBasePath string
107108
DocumentAIBasePath string
108109
DocumentAIWarehouseBasePath string
@@ -264,6 +265,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
264265
p.DeploymentManagerBasePath = data.DeploymentManagerCustomEndpoint.ValueString()
265266
p.DialogflowBasePath = data.DialogflowCustomEndpoint.ValueString()
266267
p.DialogflowCXBasePath = data.DialogflowCXCustomEndpoint.ValueString()
268+
p.DiscoveryEngineBasePath = data.DiscoveryEngineCustomEndpoint.ValueString()
267269
p.DNSBasePath = data.DNSCustomEndpoint.ValueString()
268270
p.DocumentAIBasePath = data.DocumentAICustomEndpoint.ValueString()
269271
p.DocumentAIWarehouseBasePath = data.DocumentAIWarehouseCustomEndpoint.ValueString()
@@ -877,6 +879,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
877879
data.DialogflowCXCustomEndpoint = types.StringValue(customEndpoint.(string))
878880
}
879881
}
882+
if data.DiscoveryEngineCustomEndpoint.IsNull() {
883+
customEndpoint := transport_tpg.MultiEnvDefault([]string{
884+
"GOOGLE_DISCOVERY_ENGINE_CUSTOM_ENDPOINT",
885+
}, transport_tpg.DefaultBasePaths[transport_tpg.DiscoveryEngineBasePathKey])
886+
if customEndpoint != nil {
887+
data.DiscoveryEngineCustomEndpoint = types.StringValue(customEndpoint.(string))
888+
}
889+
}
880890
if data.DNSCustomEndpoint.IsNull() {
881891
customEndpoint := transport_tpg.MultiEnvDefault([]string{
882892
"GOOGLE_DNS_CUSTOM_ENDPOINT",

google-beta/provider/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ func Provider() *schema.Provider {
395395
Optional: true,
396396
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
397397
},
398+
"discovery_engine_custom_endpoint": {
399+
Type: schema.TypeString,
400+
Optional: true,
401+
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
402+
},
398403
"dns_custom_endpoint": {
399404
Type: schema.TypeString,
400405
Optional: true,
@@ -998,6 +1003,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
9981003
config.DeploymentManagerBasePath = d.Get("deployment_manager_custom_endpoint").(string)
9991004
config.DialogflowBasePath = d.Get("dialogflow_custom_endpoint").(string)
10001005
config.DialogflowCXBasePath = d.Get("dialogflow_cx_custom_endpoint").(string)
1006+
config.DiscoveryEngineBasePath = d.Get("discovery_engine_custom_endpoint").(string)
10011007
config.DNSBasePath = d.Get("dns_custom_endpoint").(string)
10021008
config.DocumentAIBasePath = d.Get("document_ai_custom_endpoint").(string)
10031009
config.DocumentAIWarehouseBasePath = d.Get("document_ai_warehouse_custom_endpoint").(string)

google-beta/provider/provider_mmv1_resources.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/deploymentmanager"
5858
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dialogflow"
5959
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dialogflowcx"
60+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/discoveryengine"
6061
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/dns"
6162
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/documentai"
6263
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/documentaiwarehouse"
@@ -424,9 +425,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
424425
}
425426

426427
// Resources
427-
// Generated resources: 424
428+
// Generated resources: 425
428429
// Generated IAM resources: 255
429-
// Total generated resources: 679
430+
// Total generated resources: 680
430431
var generatedResources = map[string]*schema.Resource{
431432
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
432433
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -779,6 +780,7 @@ var generatedResources = map[string]*schema.Resource{
779780
"google_dialogflow_cx_test_case": dialogflowcx.ResourceDialogflowCXTestCase(),
780781
"google_dialogflow_cx_version": dialogflowcx.ResourceDialogflowCXVersion(),
781782
"google_dialogflow_cx_webhook": dialogflowcx.ResourceDialogflowCXWebhook(),
783+
"google_discovery_engine_data_store": discoveryengine.ResourceDiscoveryEngineDataStore(),
782784
"google_dns_managed_zone": dns.ResourceDNSManagedZone(),
783785
"google_dns_managed_zone_iam_binding": tpgiamresource.ResourceIamBinding(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc),
784786
"google_dns_managed_zone_iam_member": tpgiamresource.ResourceIamMember(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc),
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package discoveryengine
19+
20+
import (
21+
"encoding/json"
22+
"errors"
23+
"fmt"
24+
"time"
25+
26+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
27+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
28+
)
29+
30+
type DiscoveryEngineOperationWaiter struct {
31+
Config *transport_tpg.Config
32+
UserAgent string
33+
Project string
34+
tpgresource.CommonOperationWaiter
35+
}
36+
37+
func (w *DiscoveryEngineOperationWaiter) QueryOp() (interface{}, error) {
38+
if w == nil {
39+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
40+
}
41+
// Returns the proper get.
42+
url := fmt.Sprintf("%s%s", w.Config.DiscoveryEngineBasePath, w.CommonOperationWaiter.Op.Name)
43+
44+
return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
45+
Config: w.Config,
46+
Method: "GET",
47+
Project: w.Project,
48+
RawURL: url,
49+
UserAgent: w.UserAgent,
50+
})
51+
}
52+
53+
func createDiscoveryEngineWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*DiscoveryEngineOperationWaiter, error) {
54+
w := &DiscoveryEngineOperationWaiter{
55+
Config: config,
56+
UserAgent: userAgent,
57+
Project: project,
58+
}
59+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
60+
return nil, err
61+
}
62+
return w, nil
63+
}
64+
65+
// nolint: deadcode,unused
66+
func DiscoveryEngineOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
67+
w, err := createDiscoveryEngineWaiter(config, op, project, activity, userAgent)
68+
if err != nil {
69+
return err
70+
}
71+
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
72+
return err
73+
}
74+
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
75+
if len(rawResponse) == 0 {
76+
return errors.New("`resource` not set in operation response")
77+
}
78+
return json.Unmarshal(rawResponse, response)
79+
}
80+
81+
func DiscoveryEngineOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
82+
if val, ok := op["name"]; !ok || val == "" {
83+
// This was a synchronous call - there is no operation to wait for.
84+
return nil
85+
}
86+
w, err := createDiscoveryEngineWaiter(config, op, project, activity, userAgent)
87+
if err != nil {
88+
// If w is nil, the op was synchronous.
89+
return err
90+
}
91+
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
92+
}

0 commit comments

Comments
 (0)