Skip to content

Commit

Permalink
Added support for Datastream service & for ConnectionProfile resource (
Browse files Browse the repository at this point in the history
…#6479) (#4657)

* Added datastream connection profile

* Updated resource and tests to get to passing basic/full tests

* Added update test

* Corrected license dates

* Moved url params into parameters array

* Removed long timeouts

* Ensured that update test actually tests update

* Made update test move from gcs bucket to postgresql database instance

* Switched to handwritten operation due to unexpected error structure

* Added authorized networks to sql database instance

* fixed whitespace

* Re-added async definitions

Async definitions are used to figure out whether to call async code even if the async code isn't autogenerated

* Added postgresql password to importstateverifyignore

Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 6, 2022
1 parent 73c7f33 commit 9122286
Show file tree
Hide file tree
Showing 9 changed files with 2,283 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6479.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
google_datastream_connection_profile
```
4 changes: 4 additions & 0 deletions google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ type Config struct {
DataprocBasePath string
DataprocMetastoreBasePath string
DatastoreBasePath string
DatastreamBasePath string
DeploymentManagerBasePath string
DialogflowBasePath string
DialogflowCXBasePath string
Expand Down Expand Up @@ -296,6 +297,7 @@ const DataLossPreventionBasePathKey = "DataLossPrevention"
const DataprocBasePathKey = "Dataproc"
const DataprocMetastoreBasePathKey = "DataprocMetastore"
const DatastoreBasePathKey = "Datastore"
const DatastreamBasePathKey = "Datastream"
const DeploymentManagerBasePathKey = "DeploymentManager"
const DialogflowBasePathKey = "Dialogflow"
const DialogflowCXBasePathKey = "DialogflowCX"
Expand Down Expand Up @@ -391,6 +393,7 @@ var DefaultBasePaths = map[string]string{
DataprocBasePathKey: "https://dataproc.googleapis.com/v1beta2/",
DataprocMetastoreBasePathKey: "https://metastore.googleapis.com/v1beta/",
DatastoreBasePathKey: "https://datastore.googleapis.com/v1/",
DatastreamBasePathKey: "https://datastream.googleapis.com/v1/",
DeploymentManagerBasePathKey: "https://www.googleapis.com/deploymentmanager/v2/",
DialogflowBasePathKey: "https://dialogflow.googleapis.com/v2/",
DialogflowCXBasePathKey: "https://{{location}}-dialogflow.googleapis.com/v3/",
Expand Down Expand Up @@ -1262,6 +1265,7 @@ func ConfigureBasePaths(c *Config) {
c.DataprocBasePath = DefaultBasePaths[DataprocBasePathKey]
c.DataprocMetastoreBasePath = DefaultBasePaths[DataprocMetastoreBasePathKey]
c.DatastoreBasePath = DefaultBasePaths[DatastoreBasePathKey]
c.DatastreamBasePath = DefaultBasePaths[DatastreamBasePathKey]
c.DeploymentManagerBasePath = DefaultBasePaths[DeploymentManagerBasePathKey]
c.DialogflowBasePath = DefaultBasePaths[DialogflowBasePathKey]
c.DialogflowCXBasePath = DefaultBasePaths[DialogflowCXBasePathKey]
Expand Down
85 changes: 85 additions & 0 deletions google-beta/datastream_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package google

import (
"bytes"
"encoding/json"
"fmt"
datastream "google.golang.org/api/datastream/v1"
"time"
)

type DatastreamOperationWaiter struct {
Config *Config
UserAgent string
Project string
CommonOperationWaiter
}

func (w *DatastreamOperationWaiter) 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.DatastreamBasePath, w.CommonOperationWaiter.Op.Name)

return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
}

func (w *DatastreamOperationWaiter) Error() error {
if w != nil && w.Op.Error != nil {
return DatastreamError(*w.Op.Error)
}
return nil
}

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

// nolint: deadcode,unused
func datastreamOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createDatastreamWaiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func datastreamOperationWaitTime(config *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 := createDatastreamWaiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeout, config.PollInterval)
}

// DatastreamError wraps datastream.Status and implements the
// error interface so it can be returned.
type DatastreamError datastream.Status

func (e DatastreamError) Error() string {
var buf bytes.Buffer

for _, err := range e.Details {
buf.Write(err)
buf.WriteString("\n")
}

return buf.String()
}
14 changes: 12 additions & 2 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ func Provider() *schema.Provider {
"GOOGLE_DATASTORE_CUSTOM_ENDPOINT",
}, DefaultBasePaths[DatastoreBasePathKey]),
},
"datastream_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_DATASTREAM_CUSTOM_ENDPOINT",
}, DefaultBasePaths[DatastreamBasePathKey]),
},
"deployment_manager_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -944,9 +952,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 257
// Generated resources: 258
// Generated IAM resources: 171
// Total generated resources: 428
// Total generated resources: 429
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1196,6 +1204,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_dataproc_metastore_federation_iam_member": ResourceIamMember(DataprocMetastoreFederationIamSchema, DataprocMetastoreFederationIamUpdaterProducer, DataprocMetastoreFederationIdParseFunc),
"google_dataproc_metastore_federation_iam_policy": ResourceIamPolicy(DataprocMetastoreFederationIamSchema, DataprocMetastoreFederationIamUpdaterProducer, DataprocMetastoreFederationIdParseFunc),
"google_datastore_index": resourceDatastoreIndex(),
"google_datastream_connection_profile": resourceDatastreamConnectionProfile(),
"google_deployment_manager_deployment": resourceDeploymentManagerDeployment(),
"google_dialogflow_agent": resourceDialogflowAgent(),
"google_dialogflow_intent": resourceDialogflowIntent(),
Expand Down Expand Up @@ -1644,6 +1653,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.DataprocBasePath = d.Get("dataproc_custom_endpoint").(string)
config.DataprocMetastoreBasePath = d.Get("dataproc_metastore_custom_endpoint").(string)
config.DatastoreBasePath = d.Get("datastore_custom_endpoint").(string)
config.DatastreamBasePath = d.Get("datastream_custom_endpoint").(string)
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)
Expand Down
Loading

0 comments on commit 9122286

Please sign in to comment.