Skip to content

Commit

Permalink
Add support for Firestore Index (#3484)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Apr 25, 2019
1 parent 104137d commit 6e57eff
Show file tree
Hide file tree
Showing 15 changed files with 721 additions and 6 deletions.
6 changes: 6 additions & 0 deletions google/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/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/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
GeneratedCloudBuildResourcesMap,
GeneratedCloudSchedulerResourcesMap,
GeneratedDnsResourcesMap,
GeneratedFirestoreResourcesMap,
GeneratedPubsubResourcesMap,
GeneratedRedisResourcesMap,
GeneratedResourceManagerResourcesMap,
Expand Down
21 changes: 21 additions & 0 deletions google/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/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var projectEnvVars = []string{
"CLOUDSDK_CORE_PROJECT",
}

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

var regionEnvVars = []string{
"GOOGLE_REGION",
"GCLOUD_REGION",
Expand Down Expand Up @@ -182,6 +186,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
2 changes: 1 addition & 1 deletion google/resource_access_context_manager_access_level.go
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

0 comments on commit 6e57eff

Please sign in to comment.