Skip to content

Commit

Permalink
Add a resource: Discovery Engine Data Store (#9860) (#17084)
Browse files Browse the repository at this point in the history
* 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 <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jan 23, 2024
1 parent bd712c2 commit 17b403b
Show file tree
Hide file tree
Showing 15 changed files with 1,097 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/9860.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_discovery_engine_data_store`
```
5 changes: 5 additions & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ var services = mapOf(
"displayName" to "Dialogflowcx",
"path" to "./google/services/dialogflowcx"
),
"discoveryengine" to mapOf(
"name" to "discoveryengine",
"displayName" to "Discoveryengine",
"path" to "./google/services/discoveryengine"
),
"dns" to mapOf(
"name" to "dns",
"displayName" to "Dns",
Expand Down
1 change: 1 addition & 0 deletions google/fwmodels/provider_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type ProviderModel struct {
DeploymentManagerCustomEndpoint types.String `tfsdk:"deployment_manager_custom_endpoint"`
DialogflowCustomEndpoint types.String `tfsdk:"dialogflow_custom_endpoint"`
DialogflowCXCustomEndpoint types.String `tfsdk:"dialogflow_cx_custom_endpoint"`
DiscoveryEngineCustomEndpoint types.String `tfsdk:"discovery_engine_custom_endpoint"`
DNSCustomEndpoint types.String `tfsdk:"dns_custom_endpoint"`
DocumentAICustomEndpoint types.String `tfsdk:"document_ai_custom_endpoint"`
DocumentAIWarehouseCustomEndpoint types.String `tfsdk:"document_ai_warehouse_custom_endpoint"`
Expand Down
6 changes: 6 additions & 0 deletions google/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
transport_tpg.CustomEndpointValidator(),
},
},
"discovery_engine_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
transport_tpg.CustomEndpointValidator(),
},
},
"dns_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
10 changes: 10 additions & 0 deletions google/fwtransport/framework_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type FrameworkProviderConfig struct {
DeploymentManagerBasePath string
DialogflowBasePath string
DialogflowCXBasePath string
DiscoveryEngineBasePath string
DNSBasePath string
DocumentAIBasePath string
DocumentAIWarehouseBasePath string
Expand Down Expand Up @@ -248,6 +249,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.DeploymentManagerBasePath = data.DeploymentManagerCustomEndpoint.ValueString()
p.DialogflowBasePath = data.DialogflowCustomEndpoint.ValueString()
p.DialogflowCXBasePath = data.DialogflowCXCustomEndpoint.ValueString()
p.DiscoveryEngineBasePath = data.DiscoveryEngineCustomEndpoint.ValueString()
p.DNSBasePath = data.DNSCustomEndpoint.ValueString()
p.DocumentAIBasePath = data.DocumentAICustomEndpoint.ValueString()
p.DocumentAIWarehouseBasePath = data.DocumentAIWarehouseCustomEndpoint.ValueString()
Expand Down Expand Up @@ -827,6 +829,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
data.DialogflowCXCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.DiscoveryEngineCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_DISCOVERY_ENGINE_CUSTOM_ENDPOINT",
}, transport_tpg.DefaultBasePaths[transport_tpg.DiscoveryEngineBasePathKey])
if customEndpoint != nil {
data.DiscoveryEngineCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.DNSCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_DNS_CUSTOM_ENDPOINT",
Expand Down
6 changes: 6 additions & 0 deletions google/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ func Provider() *schema.Provider {
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"discovery_engine_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"dns_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -929,6 +934,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.DeploymentManagerBasePath = d.Get("deployment_manager_custom_endpoint").(string)
config.DialogflowBasePath = d.Get("dialogflow_custom_endpoint").(string)
config.DialogflowCXBasePath = d.Get("dialogflow_cx_custom_endpoint").(string)
config.DiscoveryEngineBasePath = d.Get("discovery_engine_custom_endpoint").(string)
config.DNSBasePath = d.Get("dns_custom_endpoint").(string)
config.DocumentAIBasePath = d.Get("document_ai_custom_endpoint").(string)
config.DocumentAIWarehouseBasePath = d.Get("document_ai_warehouse_custom_endpoint").(string)
Expand Down
6 changes: 4 additions & 2 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/hashicorp/terraform-provider-google/google/services/deploymentmanager"
"github.com/hashicorp/terraform-provider-google/google/services/dialogflow"
"github.com/hashicorp/terraform-provider-google/google/services/dialogflowcx"
"github.com/hashicorp/terraform-provider-google/google/services/discoveryengine"
"github.com/hashicorp/terraform-provider-google/google/services/dns"
"github.com/hashicorp/terraform-provider-google/google/services/documentai"
"github.com/hashicorp/terraform-provider-google/google/services/documentaiwarehouse"
Expand Down Expand Up @@ -379,9 +380,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 368
// Generated resources: 369
// Generated IAM resources: 222
// Total generated resources: 590
// Total generated resources: 591
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -687,6 +688,7 @@ var generatedResources = map[string]*schema.Resource{
"google_dialogflow_cx_test_case": dialogflowcx.ResourceDialogflowCXTestCase(),
"google_dialogflow_cx_version": dialogflowcx.ResourceDialogflowCXVersion(),
"google_dialogflow_cx_webhook": dialogflowcx.ResourceDialogflowCXWebhook(),
"google_discovery_engine_data_store": discoveryengine.ResourceDiscoveryEngineDataStore(),
"google_dns_managed_zone": dns.ResourceDNSManagedZone(),
"google_dns_managed_zone_iam_binding": tpgiamresource.ResourceIamBinding(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc),
"google_dns_managed_zone_iam_member": tpgiamresource.ResourceIamMember(dns.DNSManagedZoneIamSchema, dns.DNSManagedZoneIamUpdaterProducer, dns.DNSManagedZoneIdParseFunc),
Expand Down
92 changes: 92 additions & 0 deletions google/services/discoveryengine/discovery_engine_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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 (
"encoding/json"
"errors"
"fmt"
"time"

"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

type DiscoveryEngineOperationWaiter struct {
Config *transport_tpg.Config
UserAgent string
Project string
tpgresource.CommonOperationWaiter
}

func (w *DiscoveryEngineOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("%s%s", w.Config.DiscoveryEngineBasePath, w.CommonOperationWaiter.Op.Name)

return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: w.Config,
Method: "GET",
Project: w.Project,
RawURL: url,
UserAgent: w.UserAgent,
})
}

func createDiscoveryEngineWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*DiscoveryEngineOperationWaiter, error) {
w := &DiscoveryEngineOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func DiscoveryEngineOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createDiscoveryEngineWaiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
if len(rawResponse) == 0 {
return errors.New("`resource` not set in operation response")
}
return json.Unmarshal(rawResponse, response)
}

func DiscoveryEngineOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := createDiscoveryEngineWaiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
}
Loading

0 comments on commit 17b403b

Please sign in to comment.