-
Notifications
You must be signed in to change notification settings - Fork 53
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
Bucket import and creation inconsistency & delete_before_replace option not working properly #1065
Comments
@cristiciortea Apologies for this issue that you're running into. It appears that you may have gotten closer with a likely solution in the additional context that you have provided. When importing a GCP storage bucket, and having it managed by Pulumi, you will need to just use Would you be able to provide the code you're using when you just did:
In particular, it'd be helpful for me to see how you're importing your resources and attempting to update it using this approach. I've attempted to reproduce what you're trying to attempt, and was able to successfully import and create the bucket without issues. Here is a minimal code for reference: from pulumi import automation as auto
import pulumi_gcp
import os
import pulumi
def program_get() -> pulumi_gcp.storage.Bucket:
bucket_name = 'my-bucket' # this already exists in google cloud platform
buckets_location = 'us-central1'
# Import the existent bucket.
pulumi_gcp.storage.Bucket(
resource_name=bucket_name,
location=buckets_location,
name=bucket_name,
project=os.environ["GOOGLE_PROJECT"],
opts=pulumi.ResourceOptions(import_=bucket_name), # Note the import_ option here.
)
def program_create():
bucket_name = 'my-bucket' # this already exists in google cloud platform
buckets_location = 'us-central1'
pulumi_gcp.storage.Bucket(
resource_name=bucket_name,
location=buckets_location,
name=bucket_name,
force_destroy=True,
project=os.environ["GOOGLE_PROJECT"],
opts=pulumi.ResourceOptions(delete_before_replace=True),
)
auto.create_or_select_stack("test_stack", program=program_get, project_name="my-proj").up(on_output=print, diff=False)
auto.create_or_select_stack("test_stack", program=program_create, project_name="my-proj").up(on_output=print, diff=False) The error that is returned by the Google API in your example: |
Thank you for taking the time to look into my issue @rquitales . First of all, if I try to use only the
But if I add, the
The issue now, is that I am unable to create the bucket even after importing it using the import_ and id parameters with pulumi.ResourceOptions; I will get this error as a result when I try to create it
I also want to highlight this line from the logs, which clearly shows that pulumi is trying to create a replacement of the currently existing bucket: |
Unfortunately, it looks like this issue hasn't seen any updates in a while. If you're still encountering this problem, could you leave a quick comment to let us know so we can prioritize it? |
What happened?
I encountered an issue while trying to manage Google Cloud Storage buckets using Pulumi with the pulumi-gcp provider. My goal is to import an existing bucket, and then create a bucket with the same parameters (in my usecase, this happens when I import the bucket and then when I update my infrastructure). However, I'm facing two main problems:
After importing the existing bucket and attempting to create a new one with identical parameters, Pulumi still wants to replace the existing bucket. This suggests that there is a non-deterministic behavior in the way buckets are created and imported.
Furthermore the delete_before_replace=True option does not seem to function as expected. Pulumi attempts to replace the existing bucket but fails to delete it first, resulting in an error:
Error creating bucket nuc-test-bucket-0001: googleapi: Error 409: Your previous request to create the named bucket succeeded and you already own it., conflict
Stack trace
Expected Behavior
The expected behavior for the given scenario should have been as follows:
Upon importing the existing bucket with the same parameters, Pulumi should recognize that the new bucket has the same configuration as the existing one and avoid any replacement. Essentially, it should detect no differences between the two configurations, treating them as identical.
If there was any difference between the configurations and Pulumi decided to replace the existing bucket, the delete_before_replace=True option should have instructed Pulumi to first delete the existing bucket and then create a new one with the updated configuration. This would have avoided the conflict error (Error 409) caused by attempting to create a bucket with the same name as an existing one.
Steps to reproduce
In linux:
mkdir -p /pulumi-work-dir-testing/workspace_test
cd /pulumi-work-dir-testing/workspace_test
echo "description: Test infrastracture\n name: test-project-bucket\n runtime: python" >> Pulumi.yaml
pulumi login file:///pulumi-work-dir-testing/workspace_test
pulumi stack init test_stack
In ipython interractive shell:
Output of
pulumi about
In [4]: !pulumi about
CLI
Version 3.30.0
Go Version go1.17.9
Go Compiler gc
Plugins
NAME VERSION
gcp 6.53.0
kubernetes 3.24.2
python unknown
Host
OS debian
Version 11.1
Arch x86_64
This project is written in python (/usr/local/bin/python3 v3.9.7)
Current Stack: test_stack
TYPE URN
pulumi:pulumi:Stack urn:pulumi:test_stack::test-project-bucket::pulumi:pulumi:Stack::test-project-bucket-test_stack
pulumi:providers:gcp urn:pulumi:test_stack::test-project-bucket::pulumi:providers:gcp::default_6_53_0
gcp:storage/bucket:Bucket urn:pulumi:test_stack::test-project-bucket::gcp:storage/bucket:Bucket::nuc-test-bucket-0001
Found no pending operations associated with test_stack
Backend
Name backend-54777f96d-z69pz
URL file:///pulumi-work-dir-testing/workspace_test
User root
Organizations
NAME VERSION
central-backend 0.1.0
ipython 8.12.0
pip 21.2.4
pre-commit 2.21.0
pydevd-pycharm 222.4554.11
pytest-aioresponses 0.2.0
pytest-dotenv 0.5.2
ruff 0.0.254
types-toml 0.10.8.6
wheel 0.37.0
Pulumi locates its logs in /tmp by default
warning: A new version of Pulumi is available. To upgrade from version '3.30.0' to '3.64.0', visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.
Additional context
I found a workaround, if import the bucket with pulumi import instead of pulumi_gcp.storage.Bucket.get, this bug/s do not reproduce.
Additionally, if I attempt to import the bucket using the following approach, the issue still persists:
pulumi_gcp.storage.Bucket( resource_name=bucket_name, cors=[pulumi_gcp.storage.BucketCorArgs( max_age_seconds=3600, methods=[ "GET", "HEAD", "PUT", "POST", "DELETE", ], )], location=buckets_location, name=bucket_name, project=os.environ["GOOGLE_PROJECT"], storage_class=storage_class, uniform_bucket_level_access=True, opts=pulumi.ResourceOptions(delete_before_replace=True, id=bucket_name, import_=bucket_name), )
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).
The text was updated successfully, but these errors were encountered: