Skip to content

Commit 75b633e

Browse files
stefan-malin-dbstefan-malin-ingmelinath
authored andcommitted
Fix: Address issue hashicorp#19621 in discoveryengine module (GoogleCloudPlatform#13021)
Co-authored-by: stefan.malin <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 2d605d0 commit 75b633e

File tree

8 files changed

+96
-10
lines changed

8 files changed

+96
-10
lines changed

mmv1/products/discoveryengine/ChatEngine.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ timeouts:
3434
insert_minutes: 20
3535
update_minutes: 20
3636
delete_minutes: 20
37-
autogen_async: true
37+
autogen_async: false
3838
async:
3939
actions: ['create', 'delete']
4040
type: 'OpAsync'

mmv1/products/discoveryengine/DataStore.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ timeouts:
3434
insert_minutes: 20
3535
update_minutes: 20
3636
delete_minutes: 20
37-
autogen_async: true
37+
autogen_async: false
3838
async:
3939
actions: ['create', 'delete']
4040
type: 'OpAsync'

mmv1/products/discoveryengine/Schema.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ timeouts:
3131
insert_minutes: 60
3232
update_minutes: 60
3333
delete_minutes: 60
34-
autogen_async: true
34+
autogen_async: false
3535
async:
3636
actions: ['create', 'delete', 'update']
3737
type: 'OpAsync'

mmv1/products/discoveryengine/SearchEngine.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ timeouts:
3333
insert_minutes: 20
3434
update_minutes: 20
3535
delete_minutes: 20
36-
autogen_async: true
36+
autogen_async: false
3737
async:
3838
actions: ['create', 'delete']
3939
type: 'OpAsync'

mmv1/products/discoveryengine/TargetSite.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ timeouts:
3131
insert_minutes: 60
3232
update_minutes: 60
3333
delete_minutes: 60
34-
autogen_async: true
34+
autogen_async: false
3535
async:
3636
actions: ['create', 'delete', 'update']
3737
type: 'OpAsync'
@@ -42,9 +42,8 @@ async:
4242
update_minutes: 60
4343
delete_minutes: 60
4444
result:
45-
resource_inside_response: false
45+
resource_inside_response: true
4646
custom_code:
47-
post_create: 'templates/terraform/post_create/set_computed_name.tmpl'
4847
custom_import: 'templates/terraform/custom_import/discoveryengine_targetsite_set_id.go.tmpl'
4948
examples:
5049
- name: 'discoveryengine_targetsite_basic'
@@ -79,7 +78,6 @@ parameters:
7978
type: String
8079
description: |
8180
The unique id of the target site.
82-
8381
url_param_only: true
8482
immutable: true
8583
output: true

mmv1/templates/terraform/examples/discoveryengine_targetsite_advanced.tf.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "google_discovery_engine_target_site" "advanced" {
22
location = google_discovery_engine_data_store.advanced.location
33
data_store_id = google_discovery_engine_data_store.advanced.data_store_id
4-
provided_uri_pattern = "http://cloud.google.com/docs/*"
4+
provided_uri_pattern = "cloud.google.com/docs/*"
55
type = "INCLUDE"
66
exact_match = false
77
}

mmv1/templates/terraform/examples/discoveryengine_targetsite_basic.tf.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "google_discovery_engine_target_site" "basic" {
22
location = google_discovery_engine_data_store.basic.location
33
data_store_id = google_discovery_engine_data_store.basic.data_store_id
4-
provided_uri_pattern = "http://cloud.google.com/docs/*"
4+
provided_uri_pattern = "cloud.google.com/docs/*"
55
type = "INCLUDE"
66
exact_match = false
77
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package discoveryengine
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"fmt"
7+
"strings"
8+
"time"
9+
10+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
11+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
12+
)
13+
14+
type DiscoveryEngineOperationWaiter struct {
15+
Config *transport_tpg.Config
16+
UserAgent string
17+
Project string
18+
tpgresource.CommonOperationWaiter
19+
}
20+
21+
func (w *DiscoveryEngineOperationWaiter) QueryOp() (interface{}, error) {
22+
if w == nil {
23+
return nil, fmt.Errorf("cannot query operation, it's unset or nil")
24+
}
25+
26+
opName := w.CommonOperationWaiter.Op.Name
27+
28+
// Extract location from opName. Example:
29+
// "projects/<project>/locations/<location>/operations/<operation-id>"
30+
// Requires error handling if not properly formatted.
31+
parts := strings.Split(opName, "/")
32+
if len(parts) < 5 || parts[2] != "locations" {
33+
return nil, fmt.Errorf("unexpected operation name format: %s", opName) // Handle invalid format appropriately
34+
}
35+
location := parts[3]
36+
37+
basePath := strings.Replace(w.Config.DiscoveryEngineBasePath, "{{location}}", location, 1)
38+
url := fmt.Sprintf("%s%s", basePath, opName)
39+
40+
return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
41+
Config: w.Config,
42+
Method: "GET",
43+
Project: w.Project,
44+
RawURL: url,
45+
UserAgent: w.UserAgent,
46+
})
47+
}
48+
49+
func createDiscoveryEngineWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*DiscoveryEngineOperationWaiter, error) {
50+
w := &DiscoveryEngineOperationWaiter{
51+
Config: config,
52+
UserAgent: userAgent,
53+
Project: project,
54+
}
55+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
56+
return nil, err
57+
}
58+
return w, nil
59+
}
60+
61+
// nolint: deadcode,unused
62+
func DiscoveryEngineOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
63+
w, err := createDiscoveryEngineWaiter(config, op, project, activity, userAgent)
64+
if err != nil {
65+
return err
66+
}
67+
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
68+
return err
69+
}
70+
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
71+
if len(rawResponse) == 0 {
72+
return errors.New("`resource` not set in operation response")
73+
}
74+
return json.Unmarshal(rawResponse, response)
75+
}
76+
77+
func DiscoveryEngineOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
78+
if val, ok := op["name"]; !ok || val == "" {
79+
// This was a synchronous call - there is no operation to wait for.
80+
return nil
81+
}
82+
w, err := createDiscoveryEngineWaiter(config, op, project, activity, userAgent)
83+
if err != nil {
84+
// If w is nil, the op was synchronous.
85+
return err
86+
}
87+
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
88+
}

0 commit comments

Comments
 (0)