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

Input-only ComponentResource property accessible in Python #16134

Open
t0yv0 opened this issue May 6, 2024 · 2 comments
Open

Input-only ComponentResource property accessible in Python #16134

t0yv0 opened this issue May 6, 2024 · 2 comments
Labels
area/sdks Pulumi language SDKs kind/bug Some behavior is incorrect or out of spec language/javascript language/python

Comments

@t0yv0
Copy link
Member

t0yv0 commented May 6, 2024

What happened?

Squinting at pulumi/pulumi-aws#2491

It appears that repository.name works incorrectly in Python previewing to default. In TypeScript it is not accessible at all. Which seems right, since name is mentioned in inputProperties but not properties.

This somehow works:

# Set up app container image repository
repository = awsx.ecr.Repository(
    "backend",
    name="backend",
    lifecycle_policy={
        "rules": [
            {
                "description": "Delete build images after 90 days",
                "maximum_age_limit": 90,
                "tag_status": "any",
            },
        ],
    },
)

pulumi.export("ecr-name", repository.name)

But this is a type error:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

const repo = new awsx.ecr.Repository("backend", {
    name: "backend",
    lifecyclePolicy: {
        rules: [
            {
                "description": "Delete build images after 90 days",
                maximumAgeLimit: 90,
                tagStatus: "any",
            },
        ],
    }
})

export const ecrName = repo.name;

Example

See above

Output of pulumi about

CLI          
Version      3.111.1
Go Version   go1.22.1
Go Compiler  gc

Plugins
NAME    VERSION
aws     6.33.1
awsx    2.9.0
docker  4.5.3
docker  3.6.1
nodejs  unknown

Host     
OS       darwin
Version  14.4
Arch     arm64

This project is written in nodejs: executable='/Users/anton/bin/node' version='v18.18.2'

Current Stack: anton-pulumi-corp/ts/dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/anton-pulumi-corp
User           anton-pulumi-corp
Organizations  anton-pulumi-corp, moolumi, pulumi
Token type     personal

Dependencies:
NAME            VERSION
@pulumi/aws     v6.33.1
@pulumi/awsx    v2.9.0
@pulumi/pulumi  3.115.1
@types/node     18.19.32
typescript      5.4.5

Pulumi locates its logs in /var/folders/gd/3ncjb1lj5ljgk8xl5ssn_gvc0000gn/T/com.apple.shortcuts.mac-helper// by default

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

@t0yv0 t0yv0 added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 6, 2024
@justinvp justinvp added area/sdks Pulumi language SDKs language/python language/javascript and removed needs-triage Needs attention from the triage team labels May 8, 2024
@justinvp
Copy link
Member

justinvp commented May 8, 2024

Node and Python actually behave similarly here, the difference is that with TypeScript you're actually getting type checking from the compiler whereas you don't get that by default with Python. If it was JavaScript, or if the TypeScript was changed to export const ecrName = (<any>repo).name; it works just as it does in Python.

In both generated SDKs, we don't actually include a name property on the Repository class, which is why we get the error for TypeScript and why type checking the Python returns a similar error, like in VS Code:

Screenshot 2024-05-08 at 1 41 53 AM

The reason it works when we're not type checking (in either SDK) comes down to the way Outputs are initialized for the resources.

Consider the __init__ implementation in Python:

            __props__.__dict__["encryption_configurations"] = encryption_configurations
            __props__.__dict__["force_delete"] = force_delete
            __props__.__dict__["image_scanning_configuration"] = image_scanning_configuration
            __props__.__dict__["image_tag_mutability"] = image_tag_mutability
            __props__.__dict__["lifecycle_policy"] = lifecycle_policy
            __props__.__dict__["name"] = name
            __props__.__dict__["tags"] = tags
            __props__.__dict__["repository"] = None
            __props__.__dict__["url"] = None
        super(Repository, __self__).__init__(
            'awsx:ecr:Repository',
            resource_name,
            __props__,
            opts,
            remote=True)

What happens is we loop over each of those dict entries and create an Output and assign it as an attribute on the resource:

res.__dict__[name] = Output(
resolve_deps, resolve_value, resolve_is_known, resolve_is_secret
)

The Node.js SDK does the same thing.

Both SDKs have always done this and it hasn't caused any issues that I'm aware of. There's just this side effect that we're assigning some properties/attributes to the resource that don't strictly need to be there. We could consider making a change to not do it, but I'm slightly concerned that may end up breaking someone who unknowingly took a dependency on this behavior. If it's not actually causing any issues, I'm inclined to not change it.

@t0yv0
Copy link
Member Author

t0yv0 commented May 10, 2024

That makes sense, the risks outweigh the benefits of the change.

With pulumi/pulumi-aws#2491 the behavior of these outputs is unexpected (resource cycling) since the provider doesn't populate "name" for an already provisioned Component resource. Inclined to leave it closed by design for now, and we consider actually implementing "name" output in the future to simplify this scenario. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sdks Pulumi language SDKs kind/bug Some behavior is incorrect or out of spec language/javascript language/python
Projects
None yet
Development

No branches or pull requests

2 participants