Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Datastream service & for ConnectionProfile resource #12475

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type Config struct {
DataprocBasePath string
DataprocMetastoreBasePath string
DatastoreBasePath string
DatastreamBasePath string
DeploymentManagerBasePath string
DialogflowBasePath string
DialogflowCXBasePath string
Expand Down Expand Up @@ -286,6 +287,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 @@ -374,6 +376,7 @@ var DefaultBasePaths = map[string]string{
DataprocBasePathKey: "https://dataproc.googleapis.com/v1/",
DataprocMetastoreBasePathKey: "https://metastore.googleapis.com/v1/",
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 @@ -1224,6 +1227,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/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/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,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 @@ -880,9 +888,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 229
// Generated resources: 230
// Generated IAM resources: 138
// Total generated resources: 367
// Total generated resources: 368
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1086,6 +1094,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_dataproc_metastore_service_iam_member": ResourceIamMember(DataprocMetastoreServiceIamSchema, DataprocMetastoreServiceIamUpdaterProducer, DataprocMetastoreServiceIdParseFunc),
"google_dataproc_metastore_service_iam_policy": ResourceIamPolicy(DataprocMetastoreServiceIamSchema, DataprocMetastoreServiceIamUpdaterProducer, DataprocMetastoreServiceIdParseFunc),
"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 @@ -1503,6 +1512,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