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 user project overrides #4202

Merged
merged 1 commit into from
Aug 13, 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
2 changes: 1 addition & 1 deletion google/access_context_manager_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (w *AccessContextManagerOperationWaiter) QueryOp() (interface{}, error) {
}
// Returns the proper get.
url := fmt.Sprintf("https://accesscontextmanager.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", url, nil)
return sendRequest(w.Config, "GET", "", url, nil)
}

func accessContextManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error {
Expand Down
15 changes: 8 additions & 7 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ import (
// Config is the configuration structure used to instantiate the Google
// provider.
type Config struct {
Credentials string
AccessToken string
Project string
Region string
Zone string
Scopes []string
BatchingConfig *batchingConfig
Credentials string
AccessToken string
Project string
Region string
Zone string
Scopes []string
BatchingConfig *batchingConfig
UserProjectOverride bool

client *http.Client
userAgent string
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_client_openid_userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func dataSourceGoogleClientOpenIDUserinfoRead(d *schema.ResourceData, meta inter

// See https://github.com/golang/oauth2/issues/306 for a recommendation to do this from a Go maintainer
// URL retrieved from https://accounts.google.com/.well-known/openid-configuration
res, err := sendRequest(config, "GET", "https://openidconnect.googleapis.com/v1/userinfo", nil)
res, err := sendRequest(config, "GET", "", "https://openidconnect.googleapis.com/v1/userinfo", nil)
if err != nil {
return fmt.Errorf("error retrieving userinfo for your provider credentials; have you enabled the 'https://www.googleapis.com/auth/userinfo.email' scope? error: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_composer_image_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func dataSourceGoogleComposerImageVersionsRead(d *schema.ResourceData, meta inte
return err
}

versions, err := paginatedListRequest(url, config, flattenGoogleComposerImageVersions)
versions, err := paginatedListRequest(project, url, config, flattenGoogleComposerImageVersions)
if err != nil {
return fmt.Errorf("Error listing Composer image versions: %s", err)
}
Expand Down
11 changes: 8 additions & 3 deletions google/data_source_google_kms_crypto_key_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
}

log.Printf("[DEBUG] Getting attributes for CryptoKeyVersion: %#v", url)
res, err := sendRequest(config, "GET", url, nil)

cryptoKeyId, err := parseKmsCryptoKeyId(d.Get("crypto_key").(string), config)
if err != nil {
return err
}
res, err := sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("KmsCryptoKeyVersion %q", d.Id()))
}
Expand All @@ -89,7 +94,7 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
}

log.Printf("[DEBUG] Getting purpose of CryptoKey: %#v", url)
res, err = sendRequest(config, "GET", url, nil)
res, err = sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("KmsCryptoKey %q", d.Id()))
}
Expand All @@ -100,7 +105,7 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
return err
}
log.Printf("[DEBUG] Getting public key of CryptoKeyVersion: %#v", url)
res, _ = sendRequest(config, "GET", url, nil)
res, _ = sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)

if err := d.Set("public_key", flattenKmsCryptoKeyVersionPublicKey(res, d)); err != nil {
return fmt.Errorf("Error reading CryptoKeyVersion public key: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion google/data_source_google_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package google

import (
"fmt"

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

Expand Down Expand Up @@ -44,7 +45,7 @@ func datasourceGoogleProjectsRead(d *schema.ResourceData, meta interface{}) erro
return err
}

res, err := sendRequest(config, "GET", url, nil)
res, err := sendRequest(config, "GET", "", url, nil)
if err != nil {
return fmt.Errorf("Error retrieving projects: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_storage_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func dataSourceGoogleStorageBucketObjectRead(d *schema.ResourceData, meta interf
// Using REST apis because the storage go client doesn't support folders
url := fmt.Sprintf("https://www.googleapis.com/storage/v1/b/%s/o/%s", bucket, name)

res, err := sendRequest(config, "GET", url, nil)
res, err := sendRequest(config, "GET", "", url, nil)
if err != nil {
return fmt.Errorf("Error retrieving storage bucket object: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_tpu_tensorflow_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func dataSourceTpuTensorFlowVersionsRead(d *schema.ResourceData, meta interface{
return err
}

versionsRaw, err := paginatedListRequest(url, config, flattenTpuTensorflowVersions)
versionsRaw, err := paginatedListRequest(project, url, config, flattenTpuTensorflowVersions)
if err != nil {
return fmt.Errorf("Error listing TPU Tensorflow versions: %s", err)
}
Expand Down
8 changes: 5 additions & 3 deletions google/filestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
)

type FilestoreOperationWaiter struct {
Config *Config
Config *Config
Project string
CommonOperationWaiter
}

Expand All @@ -28,7 +29,7 @@ func (w *FilestoreOperationWaiter) QueryOp() (interface{}, error) {
}
// Returns the proper get.
url := fmt.Sprintf("https://file.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", url, nil)
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func filestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
Expand All @@ -37,7 +38,8 @@ func filestoreOperationWaitTime(config *Config, op map[string]interface{}, proje
return nil
}
w := &FilestoreOperationWaiter{
Config: config,
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions google/firestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
)

type FirestoreOperationWaiter struct {
Config *Config
Config *Config
Project string
CommonOperationWaiter
}

Expand All @@ -28,7 +29,7 @@ func (w *FirestoreOperationWaiter) QueryOp() (interface{}, error) {
}
// Returns the proper get.
url := fmt.Sprintf("https://firestore.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", url, nil)
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func firestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
Expand All @@ -37,7 +38,8 @@ func firestoreOperationWaitTime(config *Config, op map[string]interface{}, proje
return nil
}
w := &FirestoreOperationWaiter{
Config: config,
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return err
Expand Down
14 changes: 12 additions & 2 deletions google/iam_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ func PubsubTopicIdParseFunc(d *schema.ResourceData, config *Config) error {
func (u *PubsubTopicIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url := u.qualifyTopicUrl("getIamPolicy")

policy, err := sendRequest(u.Config, "GET", url, nil)
project, err := getProject(u.d, u.Config)
if err != nil {
return nil, err
}

policy, err := sendRequest(u.Config, "GET", project, url, nil)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -121,7 +126,12 @@ func (u *PubsubTopicIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanage

url := u.qualifyTopicUrl("setIamPolicy")

_, err = sendRequestWithTimeout(u.Config, "POST", url, obj, u.d.Timeout(schema.TimeoutCreate))
project, err := getProject(u.d, u.Config)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", project, url, obj, u.d.Timeout(schema.TimeoutCreate))
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down
14 changes: 12 additions & 2 deletions google/iam_source_repo_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ func SourceRepoRepositoryIdParseFunc(d *schema.ResourceData, config *Config) err
func (u *SourceRepoRepositoryIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url := u.qualifyRepositoryUrl("getIamPolicy")

policy, err := sendRequest(u.Config, "GET", url, nil)
project, err := getProject(u.d, u.Config)
if err != nil {
return nil, err
}

policy, err := sendRequest(u.Config, "GET", project, url, nil)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -121,7 +126,12 @@ func (u *SourceRepoRepositoryIamUpdater) SetResourceIamPolicy(policy *cloudresou

url := u.qualifyRepositoryUrl("setIamPolicy")

_, err = sendRequestWithTimeout(u.Config, "POST", url, obj, u.d.Timeout(schema.TimeoutCreate))
project, err := getProject(u.d, u.Config)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", project, url, obj, u.d.Timeout(schema.TimeoutCreate))
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down
12 changes: 9 additions & 3 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func Provider() terraform.ResourceProvider {
},
},

"user_project_override": {
Type: schema.TypeBool,
Optional: true,
},

// Generated Products
AccessContextManagerCustomEndpointEntryKey: AccessContextManagerCustomEndpointEntry,
AppEngineCustomEndpointEntryKey: AppEngineCustomEndpointEntry,
Expand Down Expand Up @@ -357,9 +362,10 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Project: d.Get("project").(string),
Region: d.Get("region").(string),
Zone: d.Get("zone").(string),
Project: d.Get("project").(string),
Region: d.Get("region").(string),
Zone: d.Get("zone").(string),
UserProjectOverride: d.Get("user_project_override").(bool),
}

// Add credential source
Expand Down
Loading