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

Add support for Firestore Index #632

Merged
merged 1 commit into from
Apr 25, 2019
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
6 changes: 6 additions & 0 deletions google-beta/common_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform/helper/resource"
cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/googleapi"
)

type Waiter interface {
Expand Down Expand Up @@ -96,6 +97,11 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc {
if err != nil {
// Importantly, this error is in the GET to the operation, and isn't an error
// with the resource CRUD request itself.
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[DEBUG] Dismissed an operation GET as retryable based on error code being 404: %s", err)
return op, "done: false", nil
}

return nil, "", fmt.Errorf("error while retrieving operation: %s", err)
}

Expand Down
46 changes: 46 additions & 0 deletions google-beta/firestore_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 google

import (
"fmt"
)

type FirestoreOperationWaiter struct {
Config *Config
CommonOperationWaiter
}

func (w *FirestoreOperationWaiter) 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("https://firestore.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", url, nil)
}

func firestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w := &FirestoreOperationWaiter{
Config: config,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return err
}
return OperationWait(w, activity, timeoutMinutes)
}
1 change: 1 addition & 0 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
GeneratedCloudBuildResourcesMap,
GeneratedCloudSchedulerResourcesMap,
GeneratedDnsResourcesMap,
GeneratedFirestoreResourcesMap,
GeneratedPubsubResourcesMap,
GeneratedRedisResourcesMap,
GeneratedResourceManagerResourcesMap,
Expand Down
21 changes: 21 additions & 0 deletions google-beta/provider_firestore_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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 google

import "github.com/hashicorp/terraform/helper/schema"

var GeneratedFirestoreResourcesMap = map[string]*schema.Resource{
"google_firestore_index": resourceFirestoreIndex(),
}
11 changes: 11 additions & 0 deletions google-beta/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var projectEnvVars = []string{
"CLOUDSDK_CORE_PROJECT",
}

var firestoreProjectEnvVars = []string{
"GOOGLE_FIRESTORE_PROJECT",
}

var regionEnvVars = []string{
"GOOGLE_REGION",
"GCLOUD_REGION",
Expand Down Expand Up @@ -191,6 +195,13 @@ func getTestZoneFromEnv() string {
return multiEnvSearch(zoneEnvVars)
}

// Firestore can't be enabled at the same time as Datastore, so we need a new
// project to manage it until we can enable Firestore programatically.
func getTestFirestoreProjectFromEnv(t *testing.T) string {
skipIfEnvNotSet(t, firestoreProjectEnvVars...)
return multiEnvSearch(firestoreProjectEnvVars)
}

func getTestOrgFromEnv(t *testing.T) string {
skipIfEnvNotSet(t, orgEnvVars...)
return multiEnvSearch(orgEnvVars)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func resourceAccessContextManagerAccessLevelDelete(d *schema.ResourceData, meta
func resourceAccessContextManagerAccessLevelImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)

// current import_formats can't import ids with forward slashes in them.
// current import_formats can't import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func resourceAccessContextManagerServicePerimeterDelete(d *schema.ResourceData,
func resourceAccessContextManagerServicePerimeterImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)

// current import_formats can't import ids with forward slashes in them.
// current import_formats can't import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}
Expand Down
Loading