pulumi/pkg/codegen
bors[bot] 656cf29179
Merge #13251
13251: [convert] Prefer output-versioned invokes in generated programs for nodejs and python r=Zaid-Ajaj a=Zaid-Ajaj

### Description

This PR implements a new PCL bind option called `PreferOutputVersionedInvokes` which as the name suggests gives higher priority to using output-versioned invokes in generated programs if they exist* but only for python and nodejs. Previously we have enabled this for all languages but it breaks go and dotnet programs so here it is only applied to python and typescript. 

Binding component programs carry over this option if the main program has it too. 

This work is a continuation of #13051

<details>
   <summary>PCL program example</summary>

```
vpc = invoke("aws:ec2:getVpc", {
	default = true
})
subnets = invoke("aws:ec2:getSubnetIds", {
	vpcId = vpc.id
})

resource webSecurityGroup "aws:ec2:SecurityGroup" {
	vpcId = vpc.id
	egress = [{
		protocol = "-1"
		fromPort = 0
		toPort = 0
		cidrBlocks = ["0.0.0.0/0"]
	}]
	ingress = [{
		protocol = "tcp"
		fromPort = 80
		toPort = 80
		cidrBlocks = ["0.0.0.0/0"]
	}]
}
```

</details>

<details>
   <summary>Generated TypeScript Before</summary>

```typescript
const vpc = aws.ec2.getVpc({
    "default": true,
});
const subnets = vpc.then(vpc => aws.ec2.getSubnetIds({
    vpcId: vpc.id,
}));
const webSecurityGroup = new aws.ec2.SecurityGroup("webSecurityGroup", {
    vpcId: vpc.then(vpc => vpc.id),
    egress: [{
        protocol: "-1",
        fromPort: 0,
        toPort: 0,
        cidrBlocks: ["0.0.0.0/0"],
    }],
    ingress: [{
        protocol: "tcp",
        fromPort: 80,
        toPort: 80,
        cidrBlocks: ["0.0.0.0/0"],
    }],
});
```

</details>

<details>
   <summary>Generated TypeScript After</summary>

```typescript
const vpc = aws.ec2.getVpcOutput({
    "default": true,
});
const subnets = aws.ec2.getSubnetIdsOutput({
    vpcId: vpc.id,
});
const webSecurityGroup = new aws.ec2.SecurityGroup("webSecurityGroup", {
    vpcId: vpc.id,
    egress: [{
        protocol: "-1",
        fromPort: 0,
        toPort: 0,
        cidrBlocks: ["0.0.0.0/0"],
    }],
    ingress: [{
        protocol: "tcp",
        fromPort: 80,
        toPort: 80,
        cidrBlocks: ["0.0.0.0/0"],
    }],
});
```

</details>

> * The existence of output-versioned invokes depends on whether they have any arguments. The idea is to change that later such that every function invoke emits an output-versioned invoke regardless of whether it has input args or not. 

## 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>
2023-06-26 11:30:24 +00:00
..
cgstrings Revert "Revert "Go and Python codegen support symbols with hyphens in their names"" 2022-10-17 09:37:07 -07:00
convert Send old inputs to diff and update 2023-06-21 21:04:50 +01:00
docs remove icons 2023-06-09 14:13:11 -04:00
dotnet Extend SkipResourceTypechecking to allow generating unknown resources 2023-06-14 19:02:56 +02:00
gen_program_test all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
go Merge #13212 2023-06-23 09:52:45 +00:00
hcl2 Regen TypeScript examples 2023-06-07 10:54:25 +02:00
nodejs Remove extra tab that convert TS outputs in JSON file 2023-06-20 14:28:12 -07:00
pcl Prefer output-versioned invokes in generated programs for nodejs and python 2023-06-23 02:42:18 +02:00
python [sdk/python] remove deprecation warning on result types. 2023-06-21 08:55:30 -07:00
report all: Fix revive issues 2023-03-21 08:55:11 -07:00
schema Don't return empty hcl.Diagnostics 2023-06-08 19:14:41 +01:00
testing Merge #13251 2023-06-26 11:30:24 +00:00
README.md fix some links 2023-05-19 19:39:26 -07:00
docs.go Support "lifting" single-valued method returns to their return type (#8111) 2021-10-01 11:33:02 -07:00
docs_test.go ci: radical idea - what if slow tests & no stdout makes GH consider runner dead? 2022-03-06 14:52:13 -08:00
utilities.go Make SortedKeys type safe with generics 2023-02-13 20:59:13 +00:00
utilities_test.go ci: radical idea - what if slow tests & no stdout makes GH consider runner dead? 2022-03-06 14:52:13 -08:00
utilities_types.go Initial implementation of simplified invokes for dotnet and nodejs 2023-01-11 14:17:14 -08:00

README.md

Pulumi CrossCode

The github.com/pulumi/pulumi/pkg/v3/codegen package defines the core components of Pulumi's CrossCode technology. CrossCode provides a set of foundational capabilities for working across a variety of programming languages supported by the Pulumi platform.

The core components of CrossCode in this package are:

  • Schema: The definition of Pulumi Schema, a language-neutral specification of cloud resource models. Pulumi Schema is the interface definition language for all Pulumi Packages, and is used as input to SDK code generation for each supported Pulumi language.
  • SDK Code Generation for Node.js, Python, Go and .NET: These libraries define how to create Pulumi SDKs from a Pulumi Schema definition of a package. The resulting SDKs expose the resource, components and functions from that package into the the Pulumi programming model defined for the given language.
  • Docs Generation: In addition to generating per-language SDKs, CrossCode supports generating language-neutral documentation for a package from it's Pulumi Schema. This documentation is currently hosted in the Pulumi Registry, but can in principle be hosted in other contexts as well.
  • Pulumi Configuration Language: An internal representation of Pulumi programs which supports all core concepts of the Pulumi programming model in a minimal form. Although not exposed directly to users today, this intermediate representation is used to support a variety of program conversion tasks, from and to various supported Pulumi languages.
  • Program Generation for Node.js, Python, Go and .NET: Support for lowering Pulumi Configuration Language into each of the supported Pulumi languages, such that examples and programs can be generated for the language.

These foundations enable a vast array of features supported in the Pulumi Platform, including:

  • Pulumi support for Node.js, Python, Go, .NET, Java and YAML: Each Pulumi language is supported by defining a representation of the Pulumi resource model in that language, and then implementing SDK Code Generation and Program Generation for the language.
  • Pulumi Packages: Pulumi packages define a set of resources using Pulumi Schema, and use the CrossCode SDK Code Generators for every Pulumi language automatically.
  • pulumi import: Cloud infrastructure resources deployed outside of Pulumi can be imported into Pulumi, including generated Pulumi code in your language of choice which defines the infrastructure. This builds on the program generation support from CrossCode.
  • tf2pulumi, arm2pulumi, crd2pulumi, kube2pulumi and cf2pulumi: These tools convert the source IaC format into an intermediate Pulumi Configuration Language model, and then use the CrossCode program generation support to convert that ultimately into the language a Pulumi user wants to use for their infrastructure.
  • pulumi convert: The pulumi convert command allows Pulumi YAML programs to be converted into programs in any other Pulumi language. Because Pulumi YAML is a proper subset of what can be expressed in Pulumi Configuration Language, this conversion from Pulumi YAML to Pulumi Configuration Language and then into each Pulumi language can be done faithfully.
  • Pulumi Registry: The Pulumi Registry provides discovery and documentation hosting for all Pulumi Packages. It is powered by the Pulumi Schema and CrossCode documentation generation features.

Learn more about Pulumi CrossCode at https://www.pulumi.com/crosscode/.