Skip to content

Commit

Permalink
Adding in support for a "No Project" setting for gcp:project, fixes 1168
Browse files Browse the repository at this point in the history
  • Loading branch information
rshade committed Nov 18, 2024
1 parent 678ddd9 commit 2c05a7f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
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 override global project setting:
`pulumi config set gcp:project "No Project"`
18 changes: 18 additions & 0 deletions provider/provider_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ 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)

test := pulumitest.NewPulumiTest(t, "test-programs/noproject-bucket",
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")))

test.SetConfig(t, "gcpProj", "No Project")
res := test.Up(t)
require.Contains(
t, res.StdOut,
"No Project",
)
}

// Test programs that were automatically extracted from examples without autocorrection.
func TestAutoExtractedProgramsUpgrade(t *testing.T) {
type testCase struct {
Expand Down
5 changes: 4 additions & 1 deletion provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ func preConfigureCallbackWithLogger(credentialsValidationRun *atomic.Bool, gcpCl
"CLOUDSDK_CORE_PROJECT",
})
if project == "" {
if project == "No Project" {
logOrPrint(ctx, host, "'No Project' set, continuing without global project setting, skipping region validation")
}
logOrPrint(ctx, host, noProjectErr)
return nil
}
Expand Down Expand Up @@ -442,7 +445,7 @@ func preConfigureCallbackWithLogger(credentialsValidationRun *atomic.Bool, gcpCl
vars, "skipRegionValidation", []string{"PULUMI_GCP_SKIP_REGION_VALIDATION"},
)

if !skipRegionValidation && config.Region != "" && config.Project != "" {
if !skipRegionValidation && config.Region != "" && (config.Project != "" && config.Project != "No Project") {
regionList, err := getRegionsList(ctx, config.Project, gcpClientOpts)
if err != nil {
logOrPrint(ctx, host, fmt.Sprintf("failed to get regions list: %v", err))
Expand Down
12 changes: 12 additions & 0 deletions provider/test-programs/noproject-bucket/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: simple-bucket
runtime: yaml
description: A minimal Google Cloud Pulumi YAML program
config:
gcpProj: string
resources:
# Create a GCP resource (Storage Bucket)
my-bucket:
properties:
location: US
project: "pulumi-development"
type: gcp:storage:Bucket

0 comments on commit 2c05a7f

Please sign in to comment.