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

Python: provider version bleeds over between resources when reusing same opts object #9801

Closed
allixsenos opened this issue Jun 7, 2022 · 4 comments · Fixed by #9802
Closed
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec language/python resolution/fixed This issue was fixed
Milestone

Comments

@allixsenos
Copy link

allixsenos commented Jun 7, 2022

What happened?

Instantiating a pulumi.ResourceOptions object and then passing it into multiple resources as opts causes the version of one to bleed over to the other. This causes mayhem with using different providers.

Steps to reproduce

myopts = pulumi.ResourceOptions()

assume_role_ecs = {...abbreviated...}
app_policy={...abbreviated...}

TaskRole = pulumi_aws.iam.Role("TaskRole",
    path='/',
    assume_role_policy=json.dumps(assume_role_ecs),
    inline_policies=[
    pulumi_aws.iam.RoleInlinePolicyArgs(
        name="my_inline_policy",
        policy=json.dumps(app_policy))
    ],
    opts=myopts, # this one will not find anything in the version property and will record "5.7.0" to it
)

LogGroupApp = pulumi_aws_native.logs.LogGroup("LogGroupApp",
    log_group_name=f"/ecs/myservicename",
    retention_in_days=90,
    opts=myopts, # this one will see version=5.7.0 and try to get aws-native@5.7.0
)

Expected Behavior

it deploys two resources

Actual Behavior

~/d/n/experiments/pulumi-opts-repro on  master [!?] via  allixsenos@dev via 🐍 v3.9.12 (.venv) took 3s
✖255 ❯ pulumi up
Previewing update (dev)

View Live: https://app.pulumi.com/allixsenos/pulumi-opts-repro/dev/previews/3d89cef4-802a-4bfc-aa7e-9be8794cf647

     Type                            Name                   Plan       Info
 +   pulumi:pulumi:Stack             pulumi-opts-repro-dev  create
 +   ├─ aws:iam:Role                 TaskRole               create
     └─ pulumi:providers:aws-native  default_5_7_0                     1 error

Diagnostics:
  pulumi:providers:aws-native (default_5_7_0):
    error: no resource plugin 'pulumi-resource-aws-native' found in the workspace at version v5.7.0 or on your $PATH, install the plugin using `pulumi plugin install resource aws-native v5.7.0`



~/d/n/experiments/pulumi-opts-repro on  master [!?] via  allixsenos@dev via 🐍 v3.9.12 (.venv) took 6s
✖255 ❯ ls -al

Versions used

CLI
Version      3.33.2
Go Version   go1.17.10
Go Compiler  gc

Plugins
NAME        VERSION
aws         5.7.0
aws-native  0.18.0
python      unknown

Host
OS       darwin
Version  12.4
Arch     arm64

This project is written in python (/opt/homebrew/bin/python3 v3.9.12)

Current Stack: dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend
Name           pulumi.com
URL            https://app.pulumi.com/allixsenos
User           allixsenos
Organizations  allixsenos

NAME               VERSION
pip                22.1.2
pulumi-aws         5.7.0
pulumi-aws-native  0.18.0
setuptools         62.3.3
wheel              0.37.1

Pulumi locates its logs in /var/folders/wm/0h7dw_jj5l58rs0t2zq5d5140000gn/T/ by default

Additional context

I was following https://www.pulumi.com/learn/abstraction-encapsulation/component-resources/ which says to do

        # This definition ensures the new component resource acts like anything else in the Pulumi ecosystem when being called in code.
        child_opts = pulumi.ResourceOptions(parent=self)

and understood that to mean I was supposed to pass this into each resource I created as-is

full repro case can be downloaded from https://www.dropbox.com/s/va9bht5n5ypho8g/pulumi-opts-repro.tgz?dl=0

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).

@allixsenos allixsenos added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Jun 7, 2022
@Frassle
Copy link
Member

Frassle commented Jun 8, 2022

Interesting this might be the cause of #9779 as well.

@Frassle Frassle added language/python and removed needs-triage Needs attention from the triage team labels Jun 8, 2022
@Frassle
Copy link
Member

Frassle commented Jun 8, 2022

Can confirm the repro case shows this:

$ pulumi preview 
Previewing update (dev)

View Live: https://app.pulumi.com/Frassle/examplepy/dev/previews/6b62a8bb-2913-4b7f-9e6d-36df149f2a11

     Type                            Name           Plan       Info
 +   pulumi:pulumi:Stack             examplepy-dev  create     
     └─ pulumi:providers:aws-native  default_5_7_0             1 error
 
Diagnostics:
  pulumi:providers:aws-native (default_5_7_0):
    error: no resource plugin 'pulumi-resource-aws-native' found in the workspace at version v5.7.0 or on your $PATH, install the plugin using `pulumi plugin install resource aws-native v5.7.0`

@Frassle
Copy link
Member

Frassle commented Jun 8, 2022

I think this might also be the cause of #9548

@mikhailshilkov mikhailshilkov added this to the 0.74 milestone Jun 8, 2022
@Frassle
Copy link
Member

Frassle commented Jun 8, 2022

Found it!
When we codegen for python we add an _internal_init method which sets the opts.version:

        if opts.version is None:
            opts.version = _utilities.get_version()

That's not a copy of opts, so it's mutating whatever the user passed in. I think we just need a copy.copy at the start of this method.

Frassle added a commit that referenced this issue Jun 8, 2022
Frassle added a commit that referenced this issue Jun 9, 2022
* Make a copy of ResourceOptions before mutating it

Fixes #9801

* Add to CHANGELOG

* Update golden test data
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec language/python resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants