pulumi / pulumi-yaml

YAML language provider for Pulumi
Apache License 2.0
39 stars 12 forks source link

rename resource - gcp bucket in YAML #439

Closed terekete closed 1 year ago

terekete commented 1 year ago

What happened?

Issue

Trying to determine if this is a normal outcome. In Pulumi YAML I am creating a GCS bucket resource. It creates successfully with no issue. If I try to rename the resource name though, this error below appears.

Is this normal behaviour ? Should not the old resource be destroyed and a new resource be created ?

Test

Test in local: change the resource name to an existing bucket object. The issue is still the same; it is not possible to change the resource name.

warning: A new version of Pulumi is available. To upgrade from version '3.51.0' to '3.53.1', run $ curl -sSL https://get.pulumi.com/ | sh or visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes. tester@cloudshell:~/dull (dev-lab-23-lab-b8c934)$ pulumi up Enter your passphrase to unlock config/secrets (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember): Previewing update (gcstesto): Type Name Plan pulumi:pulumi:Stack testing-gcstesto

├─ gcp:storage:Bucket testBucket2 create └─ gcp:storage:Bucket testBucket delete Resources:

Do you want to perform this update? yes Updating (gcstesto): Type Name Status Info pulumi:pulumi:Stack testing-gcstesto failed 1 error; 1 message

└─ gcp:storage:Bucket testBucket2 creating failed 1 error Diagnostics: pulumi:pulumi:Stack (testing-gcstesto): error: update failed

Error creating bucket test-bucket-dev-lab-23-lab-b8c934: googleapi: Error 409: Your previous request to create the named bucket succeeded and you already own it., conflict gcp:storage:Bucket (testBucket2): error: 1 error occurred:

Resources: 1 unchanged

Duration: 2s

warning: A new version of Pulumi is available. To upgrade from version '3.51.0' to '3.53.1', run $ curl -sSL https://get.pulumi.com/ | sh or visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.

Expected Behavior

The old resource name is deleted and the new resource name is created.

Steps to reproduce

As above.

Output of pulumi about

This occurs with the latest pulumi and with the latest GCP provider.

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

AaronFriel commented 1 year ago

@terekete how did you rename the bucket, could you share the before and after snippets of YAML?

terekete commented 1 year ago

Ok this issue is resolved using aliases as of this: https://www.pulumi.com/docs/intro/concepts/resources/options/aliases

One can replicate the issue by building a bucket with the 'name' field already set, then rename the resource name and build again. It will produce the error seen. Seems odd to me that the resource name does not just update in the state.

Frassle commented 1 year ago

This sounds like https://github.com/pulumi/pulumi/issues/9925

AaronFriel commented 1 year ago

I think this is also slightly related to this issue, around handling identity for CRUD:

@terekete Pulumi does not look at the input fields on a resource to determine the "physical name" of the resource, even if the provider does. As a result, renaming a resource with a fixed physical name and changing the logical name (in YAML, the name of the key) such as the YAML program change below does not result in correct behavior:

# this is an example of a diff between two Pulumi YAML programs.
 resources:
-   my-first-bucket:
-   my-second-bucket:
     type: gcp:storage:Bucket
     properties:
       name: actual-bucket-name

In order to handle this scenario, you'll need to use the aliases resource option, like so:

# this is an example of a diff between two Pulumi YAML programs.
 resources:
-   my-first-bucket:
-   my-second-bucket:
     type: gcp:storage:Bucket
     properties:
       name: actual-bucket-name
+    options:
+      aliases:
+      - my-first-bucket