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

List property initializer not valid #21

Closed
Tracked by #13503
danielrbradley opened this issue Dec 15, 2022 · 1 comment · Fixed by pulumi/pulumi#13630
Closed
Tracked by #13503

List property initializer not valid #21

danielrbradley opened this issue Dec 15, 2022 · 1 comment · Fixed by pulumi/pulumi#13630
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed

Comments

@danielrbradley
Copy link
Member

What happened?

Cannot implicitly convert type 'Pulumi.Awsx.Ec2.Inputs.SubnetSpecArgs[]' to 'System.Collections.Generic.List<Pulumi.Awsx.Ec2.Inputs.SubnetSpecArgs>'

Steps to reproduce

resources:
  vpc:
    type: awsx:ec2:Vpc
    properties:
      subnetSpecs:
        - type: "Public"
          cidrMask: 22
        - type: "Private"
          cidrMask: 20

Expected Behavior

    var vpc = new Awsx.Ec2.Vpc("vpc", new()
    {
        SubnetSpecs = new List<Awsx.Ec2.Inputs.SubnetSpecArgs>
        {
            new Awsx.Ec2.Inputs.SubnetSpecArgs
            {
                Type = Awsx.Ec2.SubnetType.Public,
                CidrMask = 22,
            },
            new Awsx.Ec2.Inputs.SubnetSpecArgs
            {
                Type = Awsx.Ec2.SubnetType.Private,
                CidrMask = 20,
            },
        }
    });

Actual Behavior

    var vpc = new Awsx.Ec2.Vpc("vpc", new()
    {
        SubnetSpecs = new[]
        {
            new Awsx.Ec2.Inputs.SubnetSpecArgs
            {
                Type = Awsx.Ec2.SubnetType.Public,
                CidrMask = 22,
            },
            new Awsx.Ec2.Inputs.SubnetSpecArgs
            {
                Type = Awsx.Ec2.SubnetType.Private,
                CidrMask = 20,
            },
        },
    });

Output of pulumi about

CLI          
Version      3.49.0
Go Version   go1.19.4
Go Compiler  gc

Plugins
NAME  VERSION
awsx  unknown
yaml  unknown

Host     
OS       darwin
Version  13.0.1
Arch     arm64

Current Stack: daniel-pulumi/scratch-yaml/dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/daniel-pulumi
User           daniel-pulumi
Organizations  daniel-pulumi, pulumi

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

@danielrbradley danielrbradley added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Dec 15, 2022
@Zaid-Ajaj Zaid-Ajaj self-assigned this Dec 16, 2022
@Zaid-Ajaj Zaid-Ajaj removed the needs-triage Needs attention from the triage team label Dec 19, 2022
bors bot added a commit to pulumi/pulumi that referenced this issue Aug 7, 2023
13630: [dotnet/program-gen] Fixes list initializer for plain lists in resource properties r=Zaid-Ajaj a=Zaid-Ajaj

# Description

Some resources, especially custom resources like those in `awsx` have properties which are _plain_ lists. This means that the generated dotnet SDK for them uses `List<T>` rather than `InputList<T>`. In case of the former, when initializing the list, we cannot use `new[]` (this works for `InputList<T>` because of an implicit conversion from arrays). Instead we have to use `new()` which initializes an instance of the `List<T>` class. 

This PR implements a fix such that the code generator knows when the current resource property is plain or not and subsequently emitting `new()` instead of `new[]`

Fixes pulumi/pulumi-dotnet#21

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
bors bot added a commit to pulumi/pulumi that referenced this issue Aug 7, 2023
13630: [dotnet/program-gen] Fixes list initializer for plain lists in resource properties r=Zaid-Ajaj a=Zaid-Ajaj

# Description

Some resources, especially custom resources like those in `awsx` have properties which are _plain_ lists. This means that the generated dotnet SDK for them uses `List<T>` rather than `InputList<T>`. In case of the former, when initializing the list, we cannot use `new[]` (this works for `InputList<T>` because of an implicit conversion from arrays). Instead we have to use `new()` which initializes an instance of the `List<T>` class. 

This PR implements a fix such that the code generator knows when the current resource property is plain or not and subsequently emitting `new()` instead of `new[]`

Fixes pulumi/pulumi-dotnet#21

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
@Zaid-Ajaj Zaid-Ajaj added the resolution/fixed This issue was fixed label Aug 7, 2023
@Zaid-Ajaj
Copy link
Contributor

Should be fixed as of pulumi/pulumi#13630

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 resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants