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

Dedup gcp preconfigure check #1552

Merged
merged 9 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions provider/provider_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
package gcp

import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"

"github.com/pulumi/providertest"
"github.com/pulumi/providertest/replay"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/assert"
)

func TestDNSRecordSet(t *testing.T) {
Expand Down Expand Up @@ -403,3 +407,19 @@ func TestOrganizationsProjectAutoNaming(t *testing.T) {
}
}`)
}

func TestWarningsNotDuplicated(t *testing.T) {
var outputBuf bytes.Buffer
opts := integration.ProgramTestOptions{
Dir: filepath.Join("test-programs", "simple-bucket"),
Stderr: &outputBuf,
Quick: true,
SkipRefresh: true,
ExpectFailure: true,
Env: []string{"GOOGLE_PROJECT="},
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.Equal(t, 1, strings.Count(outputBuf.String(), "Pulumi will rely on per-resource settings for this operation"))
},
}
integration.ProgramTest(t, &opts)
}
8 changes: 7 additions & 1 deletion provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"strings"
"sync/atomic"
"unicode"

"github.com/pulumi/pulumi/pkg/v3/resource/provider"
Expand Down Expand Up @@ -323,8 +324,13 @@ func lowercaseAutoName() *tfbridge.SchemaInfo {
})
}

func preConfigureCallbackWithLogger(ctx context.Context, host *provider.HostClient, vars resource.PropertyMap, c shim.ResourceConfig) error {
// We should only run the validation once to avoid duplicating the reported errors.
var credentialsValidationRun atomic.Bool

func preConfigureCallbackWithLogger(ctx context.Context, host *provider.HostClient, vars resource.PropertyMap, c shim.ResourceConfig) error {
if !credentialsValidationRun.CompareAndSwap(false, true) {
return nil
}
project := stringValue(vars, "project", []string{
"GOOGLE_PROJECT",
"GOOGLE_CLOUD_PROJECT",
Expand Down
12 changes: 12 additions & 0 deletions provider/test-programs/simple-bucket/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: vm
runtime: yaml
description: A minimal Google Cloud Pulumi YAML program
outputs:
# Export the DNS name of the bucket
bucketName: ${my-bucket.url}
resources:
# Create a GCP resource (Storage Bucket)
my-bucket:
properties:
location: US
type: gcp:storage:Bucket
Loading