Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
6 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...31--programgen-dotnet--fixes-list-initializer-for-plain-lists-in-resource-properties.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
changes: | ||
- type: fix | ||
scope: programgen/dotnet | ||
description: Fixes list initializer for plain lists in resource properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
pkg/codegen/testing/test/testdata/csharp-plain-lists-pp/csharp-plain-lists.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource vpc "awsx:ec2:Vpc" { | ||
subnetSpecs = [ | ||
{ type = "Public", cidrMask = 22 }, | ||
{ type = "Private", cidrMask = 20 } | ||
] | ||
} |
26 changes: 26 additions & 0 deletions
26
pkg/codegen/testing/test/testdata/csharp-plain-lists-pp/dotnet/csharp-plain-lists.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Pulumi; | ||
using Awsx = Pulumi.Awsx; | ||
|
||
return await Deployment.RunAsync(() => | ||
{ | ||
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, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|