diff --git a/examples/examples_py_test.go b/examples/examples_py_test.go index e45333f743..cddadb0492 100644 --- a/examples/examples_py_test.go +++ b/examples/examples_py_test.go @@ -62,3 +62,13 @@ func TestAccWebserverPy(t *testing.T) { }) } } + +func TestRegress1843(t *testing.T) { + skipIfShort(t) + test := getPythonBaseOptions(t). + With(integration.ProgramTestOptions{ + Dir: filepath.Join(getCwd(t), "regress-1843"), + }) + + integration.ProgramTest(t, &test) +} diff --git a/examples/regress-1843/.gitignore b/examples/regress-1843/.gitignore new file mode 100644 index 0000000000..a3807e5bdb --- /dev/null +++ b/examples/regress-1843/.gitignore @@ -0,0 +1,2 @@ +*.pyc +venv/ diff --git a/examples/regress-1843/Pulumi.yaml b/examples/regress-1843/Pulumi.yaml new file mode 100644 index 0000000000..403e4a6b59 --- /dev/null +++ b/examples/regress-1843/Pulumi.yaml @@ -0,0 +1,10 @@ +name: regress-1843 +runtime: + name: python + options: + virtualenv: venv +description: A minimal Google Cloud Python Pulumi program +config: + pulumi:tags: + value: + pulumi:template: gcp-python diff --git a/examples/regress-1843/__main__.py b/examples/regress-1843/__main__.py new file mode 100644 index 0000000000..d19d0764d3 --- /dev/null +++ b/examples/regress-1843/__main__.py @@ -0,0 +1,45 @@ +"""A Google Cloud Python Pulumi program""" + +import pulumi_gcp as gcp + +gcp.cloudrun.Service( + resource_name="test-gcr", + args=gcp.cloudrun.ServiceArgs( + location="us-west1", + template=gcp.cloudrun.ServiceTemplateArgs( + spec=gcp.cloudrun.ServiceTemplateSpecArgs( + containers=[ + gcp.cloudrun.ServiceTemplateSpecContainerArgs( + image="us-docker.pkg.dev/cloudrun/container/hello", + resources=gcp.cloudrun.ServiceTemplateSpecContainerResourcesArgs( + limits={ + "memory": "512Mi", + "cpu": "1", + } + ), + ) + ], + timeout_seconds=60, + container_concurrency=30, + ), + metadata=gcp.cloudrun.ServiceTemplateMetadataArgs( + annotations={ + "autoscaling.knative.dev/maxScale": "100", + }, + ), + ), + autogenerate_revision_name=True, + metadata=gcp.cloudrun.ServiceMetadataArgs( + labels={"env": "dev"}, + annotations={ + "run.googleapis.com/ingress": "all", + }, + ), + traffics=[ + gcp.cloudrun.ServiceTrafficArgs( + percent=100, + latest_revision=True, + ) + ], + ), +) diff --git a/examples/regress-1843/requirements.txt b/examples/regress-1843/requirements.txt new file mode 100644 index 0000000000..43e5d368ad --- /dev/null +++ b/examples/regress-1843/requirements.txt @@ -0,0 +1,2 @@ +pulumi>=3.0.0,<4.0.0 +pulumi-gcp>=7.0.0,<8.0.0 diff --git a/provider/provider_test.go b/provider/provider_test.go index 91681b962a..5489f947c2 100644 --- a/provider/provider_test.go +++ b/provider/provider_test.go @@ -27,6 +27,14 @@ const ( testProject = "pulumi-development" ) +func getProject() string { + proj := os.Getenv("GOOGLE_PROJECT") + if proj == "" { + proj = testProject + } + return proj +} + func TestUpgradeCoverage(t *testing.T) { providertest.ReportUpgradeCoverage(t) } diff --git a/provider/provider_yaml_test.go b/provider/provider_yaml_test.go index 750e6f6a4a..c65f1ffb21 100644 --- a/provider/provider_yaml_test.go +++ b/provider/provider_yaml_test.go @@ -141,7 +141,7 @@ func TestNoGlobalProjectWarning(t *testing.T) { } cwd, err := os.Getwd() require.NoError(t, err) - proj := os.Getenv("GOOGLE_PROJECT") + proj := getProject() t.Setenv("GOOGLE_PROJECT", "") test := pulumitest.NewPulumiTest(t, "test-programs/project-bucket", @@ -491,10 +491,7 @@ func TestRegress1488(t *testing.T) { // Test that going from replication.automatic: true (v6-style) to replication.auto: {} // (v7-style) is not a replacement. - proj := os.Getenv("GOOGLE_PROJECT") - if proj == "" { - proj = "pulumi-development" - } + proj := getProject() replay.ReplaySequence(t, providerServer(t), fmt.Sprintf(`[ { "method": "/pulumirpc.ResourceProvider/Configure", @@ -583,10 +580,7 @@ func TestEnvTokenNotInState(t *testing.T) { test := pulumitest.NewPulumiTest(t, filepath.Join("test-programs", "storage-bucket"), opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")), ) - googleProj := os.Getenv("GOOGLE_PROJECT") - if googleProj == "" { - googleProj = testProject - } + googleProj := getProject() test.SetConfig("gcp:config:project", googleProj) test.Up() @@ -595,3 +589,236 @@ func TestEnvTokenNotInState(t *testing.T) { require.NoError(t, err) require.NotContains(t, string(data), "accessToken") } + +//nolint:lll +func TestCloudrunServiceDiffNoErrorLabelsDuplicate(t *testing.T) { + if testing.Short() { + t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without GCP creds") + } + + proj := getProject() + replay.ReplaySequence(t, providerServer(t), fmt.Sprintf(`[ + { + "method": "/pulumirpc.ResourceProvider/Configure", + "request": { + "variables": { + "gcp:config:project": %q + }, + "args": { + "project": %q, + "version": "7.4.0" + }, + "acceptSecrets": true, + "acceptResources": true, + "sendsOldInputs": true, + "sendsOldInputsToDelete": true + }, + "response": { + "supportsPreview": true + } + }, + { + "method": "/pulumirpc.ResourceProvider/Diff", + "request": { + "id": "locations/us-west1/namespaces/pulumi-development/services/test-gcr-5a4eed9", + "urn": "urn:pulumi:dev::gcp_labels::gcp:cloudrun/service:Service::test-gcr", + "olds": { + "__meta": "{\"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0\":{\"create\":1200000000000,\"delete\":1200000000000,\"update\":1200000000000},\"schema_version\":\"2\"}", + "autogenerateRevisionName": true, + "id": "locations/us-west1/namespaces/pulumi-development/services/test-gcr-5a4eed9", + "location": "us-west1", + "metadata": { + "annotations": { + "run.googleapis.com/ingress": "all" + }, + "effectiveAnnotations": { + "run.googleapis.com/ingress": "all" + }, + "effectiveLabels": { + "env": "dev" + }, + "generation": 0, + "labels": { + "env": "dev" + }, + "namespace": "", + "pulumiLabels": { + "env": "dev" + }, + "resourceVersion": "", + "selfLink": "", + "uid": "" + }, + "name": "test-gcr-5a4eed9", + "project": "pulumi-development", + "template": { + "metadata": { + "annotations": { + "autoscaling.knative.dev/maxScale": "100" + }, + "generation": 0, + "labels": {}, + "name": "", + "namespace": "", + "resourceVersion": "", + "selfLink": "", + "uid": "" + }, + "spec": { + "containerConcurrency": 30, + "containers": [ + { + "args": [], + "commands": [], + "envFroms": [], + "envs": [], + "image": "gcr.io/example", + "livenessProbe": null, + "name": "", + "ports": [], + "resources": { + "limits": { + "cpu": "1", + "memory": "512Mi" + }, + "requests": {} + }, + "startupProbe": null, + "volumeMounts": [], + "workingDir": "" + } + ], + "serviceAccountName": "", + "servingState": "", + "timeoutSeconds": 60, + "volumes": [] + } + }, + "traffics": [ + { + "latestRevision": true, + "percent": 100, + "revisionName": "", + "tag": "", + "url": "" + } + ] + }, + "news": { + "__defaults": [ + "name" + ], + "autogenerateRevisionName": true, + "location": "us-west1", + "metadata": { + "__defaults": [], + "annotations": { + "run.googleapis.com/ingress": "all" + }, + "labels": { + "env": "dev" + } + }, + "name": "test-gcr-5a4eed9", + "template": { + "__defaults": [], + "metadata": { + "__defaults": [], + "annotations": { + "autoscaling.knative.dev/maxScale": "100" + } + }, + "spec": { + "__defaults": [], + "containerConcurrency": 30, + "containers": [ + { + "__defaults": [], + "image": "hello-world", + "resources": { + "__defaults": [], + "limits": { + "cpu": "1", + "memory": "512Mi" + } + } + } + ], + "timeoutSeconds": 60 + } + }, + "traffics": [ + { + "__defaults": [], + "latestRevision": true, + "percent": 100 + } + ] + }, + "oldInputs": { + "__defaults": [ + "name" + ], + "autogenerateRevisionName": true, + "location": "us-west1", + "metadata": { + "__defaults": [], + "annotations": { + "run.googleapis.com/ingress": "all" + }, + "labels": { + "env": "dev" + } + }, + "name": "test-gcr-5a4eed9", + "template": { + "__defaults": [], + "metadata": { + "__defaults": [], + "annotations": { + "autoscaling.knative.dev/maxScale": "100" + } + }, + "spec": { + "__defaults": [], + "containerConcurrency": 30, + "containers": [ + { + "__defaults": [], + "image": "gcr.io/example", + "resources": { + "__defaults": [], + "limits": { + "cpu": "1", + "memory": "512Mi" + } + } + } + ], + "timeoutSeconds": 60 + } + }, + "traffics": [ + { + "__defaults": [], + "latestRevision": true, + "percent": 100 + } + ] + } + }, + "response": { + "stables": "*", + "changes": "*", + "hasDetailedDiff": "*", + "diffs": "*", + "detailedDiff": "*" + }, + "metadata": { + "kind": "resource", + "mode": "client", + "name": "gcp" + } + } + ]`, proj, proj)) +}