Skip to content

Commit

Permalink
Adding in disableGlobalProjectWarning, fixes #1168 (#2701)
Browse files Browse the repository at this point in the history
Adds `disableGlobalProjectWarning` to the ExtraConfig for the provider,
allowing users to disable the initial default project. This fixes #1168
  • Loading branch information
rshade authored Dec 11, 2024
1 parent 9fdc160 commit c3b597e
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 14 deletions.
7 changes: 4 additions & 3 deletions docs/installation-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ To provision resources with the Pulumi Google Cloud Provider, you need to have G

Pulumi can authenticate to Google Cloud via several methods:

- Google Cloud CLI
- OpenID Connect (OIDC)
- Service account
* Google Cloud CLI
* OpenID Connect (OIDC)
* Service account

## Configuration

Expand Down Expand Up @@ -95,3 +95,4 @@ Use `pulumi config set gcp:<option>` or pass options to the [constructor of `new
| `accessToken` | Optional | A temporary OAuth 2.0 access token obtained from the Google Authorization server, i.e. the `Authorization: Bearer` token used to authenticate HTTP requests to GCP APIs. Alternative to `credentials`. Ignores the `scopes` field. |
| `scopes` | Optional | List of OAuth 2.0 [scopes](https://developers.google.com/identity/protocols/oauth2/scopes) requested when generating an access token using the service account key specified in `credentials`. Defaults: `https://www.googleapis.com/auth/cloud-platform` and `https://www.googleapis.com/auth/userinfo.email` |
| `impersonateServiceAccount` | Optional | Setting to impersonate a [Google service account](https://cloud.google.com/iam/docs/create-short-lived-credentials-direct) If you authenticate as a service account, Google Cloud derives your quota project and permissions from that service account rather than your primary authentication method. A valid primary authentication mechanism must be provided for the impersonation call, and your primary identity must have the `roles/iam.serviceAccountTokenCreator` role on the service account you are impersonating. This can also be specified by setting the `GOOGLE_IMPERSONATE_SERVICE_ACCOUNT` environment variable. |
| `disableGlobalProjectWarning` | Optional | Boolean setting to disable the warning when the Google global `project` is not set |
9 changes: 9 additions & 0 deletions provider/cmd/pulumi-resource-gcp/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@
"dialogflowCxCustomEndpoint": {
"type": "string"
},
"disableGlobalProjectWarning": {
"type": "boolean",
"default": false,
"defaultInfo": {
"environment": [
"PULUMI_GCP_DISABLE_GLOBAL_PROJECT_WARNING"
]
}
},
"disableGooglePartnerName": {
"type": "boolean"
},
Expand Down
4 changes: 3 additions & 1 deletion provider/errors/no_project.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
unable to detect a global setting for GCP Project.
Pulumi will rely on per-resource settings for this operation.
Set the GCP Project by using:
`pulumi config set gcp:project <project>`
`pulumi config set gcp:project <project>`
If you would like to disable this warning use:
`pulumi config set gcp:disableGlobalProjectWarning true`
16 changes: 16 additions & 0 deletions provider/provider_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ func TestNoGlobalProjectWarning(t *testing.T) {
)
}

func TestGlobalProjectNoProjectWarning(t *testing.T) {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without GCP creds")
}
cwd, err := os.Getwd()
require.NoError(t, err)
proj := getProject()
test := pulumitest.NewPulumiTest(t, "test-programs/project-bucket",
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")))

test.SetConfig(t, "gcp:disableGlobalProjectWarning", "true")
test.SetConfig(t, "gcpProj", proj)
res := test.Up(t)
require.NotContains(t, res.StdOut, "If you would like to disable this warning use")
}

// Test programs that were automatically extracted from examples without autocorrection.
func TestAutoExtractedProgramsUpgrade(t *testing.T) {
type testCase struct {
Expand Down
35 changes: 25 additions & 10 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,7 @@ func preConfigureCallbackWithLogger(credentialsValidationRun *atomic.Bool, gcpCl
}),
ImpersonateServiceAccount: tfbridge.ConfigStringValue(vars,
"impersonateServiceAccount", []string{"GOOGLE_IMPERSONATE_SERVICE_ACCOUNT"}),
Project: tfbridge.ConfigStringValue(vars, "project", []string{
"GOOGLE_PROJECT",
"GOOGLE_CLOUD_PROJECT",
"GCLOUD_PROJECT",
"CLOUDSDK_CORE_PROJECT",
}),
Project: project,
Region: tfbridge.ConfigStringValue(vars, "region", []string{
"GOOGLE_REGION",
"GCLOUD_REGION",
Expand All @@ -432,16 +427,24 @@ func preConfigureCallbackWithLogger(credentialsValidationRun *atomic.Bool, gcpCl
}),
}

skipRegionValidation := tfbridge.ConfigBoolValue(
vars, "skipRegionValidation", []string{"PULUMI_GCP_SKIP_REGION_VALIDATION"},
)

disableGlobalProjectWarning := tfbridge.ConfigBoolValue(
vars, "disableGlobalProjectWarning", []string{"PULUMI_GCP_DISABLE_GLOBAL_PROJECT_WARNING"},
)

if disableGlobalProjectWarning {
return nil
}

// validate the gcloud config
err := config.LoadAndValidate(ctx)
if err != nil {
return fmt.Errorf(noCredentialsErr, err)
}

skipRegionValidation := tfbridge.ConfigBoolValue(
vars, "skipRegionValidation", []string{"PULUMI_GCP_SKIP_REGION_VALIDATION"},
)

if !skipRegionValidation && config.Region != "" && config.Project != "" {
regionList, err := getRegionsList(ctx, config.Project, gcpClientOpts)
if err != nil {
Expand Down Expand Up @@ -543,6 +546,18 @@ func Provider() tfbridge.ProviderInfo {
},
},
},
"disableGlobalProjectWarning": {
Schema: shimv2.NewSchema(&schema.Schema{
Type: schema.TypeBool,
Optional: true,
}),
Info: &tfbridge.SchemaInfo{
Default: &tfbridge.DefaultInfo{
Value: false,
EnvVars: []string{"PULUMI_GCP_DISABLE_GLOBAL_PROJECT_WARNING"},
},
},
},
},
PreConfigureCallbackWithLogger: preConfigureCallbackWithLogger(&credentialsValidationRun, nil),
Resources: map[string]*tfbridge.ResourceInfo{
Expand Down
7 changes: 7 additions & 0 deletions sdk/dotnet/Config/Config.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions sdk/go/gcp/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sdk/java/src/main/java/com/pulumi/gcp/Config.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions sdk/nodejs/config/vars.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sdk/python/pulumi_gcp/config/__init__.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions sdk/python/pulumi_gcp/config/vars.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3b597e

Please sign in to comment.