Commit Graph

22 Commits

Author SHA1 Message Date
Justin Van Patten 5e6b7ef070
Bump .NET version after 3.66.2 release ()
See https://github.com/pulumi/pulumi-dotnet/releases/tag/v3.66.2
2024-08-21 16:19:35 +00:00
Justin Van Patten 856e71a3f7
Bump dotnet SDK version after release () 2024-08-09 21:06:37 +00:00
Zaid Ajaj 5fedf392e6
[sdk-gen] Support parameterized .NET provider SDKs ()
This PR extends sdk-gen for .NET to support parameterized providers.
When a schema has a parameterization, we emit a new function
`PackageParameterization()` in the `Utilities` class and call this
function for generated resources, invokes and methods.

It requires https://github.com/pulumi/pulumi-dotnet/pull/311 to be
merged first and a new version of Pulumi nuget package to be released,
then we can bump the version we use here.

EDIT: Now using Pulumi nuget package v3.66.0 
2024-08-09 13:16:20 +00:00
Julien 8afaf8dc47
Bump PulumiDotnetSDKVersion after dotnet release () 2024-08-08 20:42:57 +00:00
Thomas Gummerer 1d47a7d6e3
upgrade dotnet dependency to latest ()
Upgrade to the latest dotnet release.
2024-06-11 06:30:13 +00:00
Thomas Gummerer 76edb80dc1
update dotnet version in tests to latest ()
Update to the latest dotnet version. Pulumi.Awsx started depending on
that, so using an earlier version makes the tests fail.

This happened a few times now, so we should really fix this in a way
that doesn't require us to hardcode this version. But I want to get the
merge queue unblocked, and this is probably the quickest way to do that.
2024-05-15 06:07:24 +00:00
Fraser Waters 15331285ff
Update version of dotnet we run tests against ()
Fixes https://github.com/pulumi/pulumi/issues/16047.
2024-04-24 21:52:39 +00:00
Thomas Gummerer 4dbacf37af
update dotnet SDK version in codegen tests ()
Since we released a new SDK we should also update the version here.
Otherwise tests might end up failing as soon as a provider we're using
in the tests depends on the new dotnet SDK version.

Saw https://github.com/pulumi/pulumi/pull/15955 and realized we ran into
issues with this last time.
2024-04-17 08:15:06 +00:00
Zaid Ajaj 7627d8097e
[program-gen/go,dotnet] Fixes emited code for object expressions assigned to properties of type Any ()
# Description

Fixes  by specifically handling object expressions that are
annotated as `Any` and emitting the correct code.

- In case of Go, expression `X` is emitted as `pulumi.Any(X)` where the
type name here is `map[string]interface{}`.
- In case of C#, we generate `Dictionary<string, object?>` expressions
(similar to what we do inside `toJSON` calls)
- Updates the test aws-native schema from 0.13.0 to 0.99.0

## 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
  - [x] 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. -->
2024-03-24 00:06:57 +00:00
Thomas Gummerer 4f82720084
codegen testing: use latest pulumi dotnet version ()
We're currently failing tests because of a nuget error. It looks like
Pulumi.Awsx has started depending on the 3.60 dotnet SDK version, but
we're still using 3.59 here. It looks like this ends up in test as nuget
complains about "error NU1605: Warning As Error: Detected package
downgrade: Pulumi from 3.60.0 to 3.59.0. Reference the package directly
from the project to select a different version."

Not sure if this is the actual fix, not knowing much about dotnet, but
it looks like it might be the problem.

Right now the merge queue fails consistently because of this error.
2024-03-21 11:31:06 +00:00
Zaid Ajaj 8b3f94b89c
[program-gen] Fix panic when generating programs for MLC packages using external types ()
# Description

For an MLC package such as `aws-static-website`, it has some types which
are referenced from the `aws` package. Program-gen assumes packages are
inferred from resources and invokes, not types which caused panics in Go
(), dotnet and python
(https://github.com/pulumi/pulumi-converter-constructor-syntax/issues/2)

This PR fixes those panics. In Go the panic was due to using package
name instead of the package reference from the imported type. In dotnet
and python was due to assuming no external type references. Now we
generate nice code for all these languages.

That said, there is still an issue of resolving imports for the packages
of these external types. It works in Go, TypeScript doesn't need it but
dotnet and python do. That is why the latter are added in `SkipCompile`
in the test program.


Fixes 
Fixes
https://github.com/pulumi/pulumi-converter-constructor-syntax/issues/3
Fixes
https://github.com/pulumi/pulumi-converter-constructor-syntax/issues/2

## 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. -->
2024-03-10 17:23:15 +00:00
Zaid Ajaj c5ae74a74e
[program-gen] Emit Output-returning JSON serialization methods without rewriting applies ()
### Description

A while ago we started implementing [specialized JSON serialization
methods](https://github.com/pulumi/pulumi/issues/12519) for Pulumi
programs which can accept nested outputs without having to rewrite and
combine applies.
 - `Output.SerializeJson` in .NET
 - `pulumi.jsonStringify` in nodejs
 - `pulumi.Output.json_dumps` in Python

This PR extends program-gen for TypeScript, C# and Python to start
emitting these JSON serialization functions (when necessary). The PR
special-cases the `toJSON` PCL function when rewriting applies so that
nested outputs aren't rewritted.

Example PCL program and generated results:

> Also check out the downstream codegen tests to see improved generated
examples

```
resource vpc "aws:ec2:Vpc" {
	cidrBlock = "10.100.0.0/16"
	instanceTenancy = "default"
}

resource policy "aws:iam/policy:Policy" {
	description = "test"
	policy = toJSON({
		"Version" = "2012-10-17"
		"Interpolated" = "arn:${vpc.arn}:value"
		"Value" = vpc.id
	})
}
```


### Generated TypeScript Before
```typescript
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const vpc = new aws.ec2.Vpc("vpc", {
    cidrBlock: "10.100.0.0/16",
    instanceTenancy: "default",
});
const policy = new aws.iam.Policy("policy", {
    description: "test",
    policy: pulumi.all([vpc.arn, vpc.id]).apply(([arn, id]) => JSON.stringify({
        Version: "2012-10-17",
        Interpolated: `arn:${arn}:value`,
        Value: id,
    })),
});
```

### Generated TypeScript After
```typescript
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const vpc = new aws.ec2.Vpc("vpc", {
    cidrBlock: "10.100.0.0/16",
    instanceTenancy: "default",
});
const policy = new aws.iam.Policy("policy", {
    description: "test",
    policy: pulumi.jsonStringify({
        Version: "2012-10-17",
        Interpolated: pulumi.interpolate`arn:${vpc.arn}:value`,
        Value: vpc.id,
    }),
});
```
### Generated Python Before
```python
import pulumi
import json
import pulumi_aws as aws

vpc = aws.ec2.Vpc("vpc",
    cidr_block="10.100.0.0/16",
    instance_tenancy="default")
policy = aws.iam.Policy("policy",
    description="test",
    policy=pulumi.Output.all(vpc.arn, vpc.id).apply(lambda arn, id: json.dumps({
        "Version": "2012-10-17",
        "Interpolated": f"arn:{arn}:value",
        "Value": id,
    })))
```

### Generated Python After
```python
import pulumi
import json
import pulumi_aws as aws

vpc = aws.ec2.Vpc("vpc",
    cidr_block="10.100.0.0/16",
    instance_tenancy="default")
policy = aws.iam.Policy("policy",
    description="test",
    policy=pulumi.Output.json_dumps({
        "Version": "2012-10-17",
        "Interpolated": vpc.arn.apply(lambda arn: f"arn:{arn}:value"),
        "Value": vpc.id,
    }))
```

### Generated C# Before
```csharp
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var vpc = new Aws.Ec2.Vpc("vpc", new()
    {
        CidrBlock = "10.100.0.0/16",
        InstanceTenancy = "default",
    });

    var policy = new Aws.Iam.Policy("policy", new()
    {
        Description = "test",
        PolicyDocument = Output.Tuple(vpc.Arn, vpc.Id).Apply(values =>
        {
            var arn = values.Item1;
            var id = values.Item2;
            return JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["Version"] = "2012-10-17",
                ["Interpolated"] = $"arn:{arn}:value",
                ["Value"] = id,
            });
        }),
    });

});
```

### Generated C# After
```csharp
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var vpc = new Aws.Ec2.Vpc("vpc", new()
    {
        CidrBlock = "10.100.0.0/16",
        InstanceTenancy = "default",
    });

    var policy = new Aws.Iam.Policy("policy", new()
    {
        Description = "test",
        PolicyDocument = Output.JsonSerialize(Output.Create(new Dictionary<string, object?>
        {
            ["Version"] = "2012-10-17",
            ["Interpolated"] = vpc.Arn.Apply(arn => $"arn:{arn}:value"),
            ["Value"] = vpc.Id,
        })),
    });

});
```

## 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
  - [x] 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. -->
2024-02-20 15:48:46 +00:00
Fraser Waters 16d9f4c167
Enable perfsprint linter ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Prompted by a comment in another review:
https://github.com/pulumi/pulumi/pull/14654#discussion_r1419995945

This lints that we don't use `fmt.Errorf` when `errors.New` will
suffice, it also covers a load of other cases where `Sprintf` is
sub-optimal.

Most of these edits were made by running `perfsprint --fix`.

## Checklist

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

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] 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. -->
2023-12-12 12:19:42 +00:00
bors[bot] 3e22568b94
Merge
12347: all: Reformat with gofumpt r=abhinav a=abhinav

Per team discussion, switching to gofumpt.

[gofumpt][1] is an alternative, stricter alternative to gofmt.
It addresses other stylistic concerns that gofmt doesn't yet cover.

  [1]: https://github.com/mvdan/gofumpt

See the full list of [Added rules][2], but it includes:

- Dropping empty lines around function bodies
- Dropping unnecessary variable grouping when there's only one variable
- Ensuring an empty line between multi-line functions
- simplification (`-s` in gofmt) is always enabled
- Ensuring multi-line function signatures end with
  `) {` on a separate line.

  [2]: https://github.com/mvdan/gofumpt#Added-rules

gofumpt is stricter, but there's no lock-in.
All gofumpt output is valid gofmt output,
so if we decide we don't like it, it's easy to switch back
without any code changes.

gofumpt support is built into the tooling we use for development
so this won't change development workflows.

- golangci-lint includes a gofumpt check (enabled in this PR)
- gopls, the LSP for Go, includes a gofumpt option
  (see [installation instrutions][3])

  [3]: https://github.com/mvdan/gofumpt#installation

This change was generated by running:

```bash
gofumpt -w $(rg --files -g '*.go' | rg -v testdata | rg -v compilation_error)
```

The following files were manually tweaked afterwards:

- pkg/cmd/pulumi/stack_change_secrets_provider.go:
  one of the lines overflowed and had comments in an inconvenient place
- pkg/cmd/pulumi/destroy.go:
  `var x T = y` where `T` wasn't necessary
- pkg/cmd/pulumi/policy_new.go:
  long line because of error message
- pkg/backend/snapshot_test.go:
  long line trying to assign three variables in the same assignment

I have included mention of gofumpt in the CONTRIBUTING.md.


Co-authored-by: Abhinav Gupta <abhinav@pulumi.com>
2023-03-03 19:30:12 +00:00
Abhinav Gupta 6ae75053c8
testdata/schema: Add random 4.11.2
Adds the most recent relese of pulumi-random to included schemas.
We need something newer than 4.2.0 or 4.3.1 (both from 2021)
to test options added since then, like retainOnDelete.

Refs https://github.com/pulumi/pulumi/pull/12306#issuecomment-1450923083
2023-03-03 09:13:55 -08:00
Abhinav Gupta 7aa5b77a0c
all: Reformat with gofumpt
Per team discussion, switching to gofumpt.

[gofumpt][1] is an alternative, stricter alternative to gofmt.
It addresses other stylistic concerns that gofmt doesn't yet cover.

  [1]: https://github.com/mvdan/gofumpt

See the full list of [Added rules][2], but it includes:

- Dropping empty lines around function bodies
- Dropping unnecessary variable grouping when there's only one variable
- Ensuring an empty line between multi-line functions
- simplification (`-s` in gofmt) is always enabled
- Ensuring multi-line function signatures end with
  `) {` on a separate line.

  [2]: https://github.com/mvdan/gofumpt#Added-rules

gofumpt is stricter, but there's no lock-in.
All gofumpt output is valid gofmt output,
so if we decide we don't like it, it's easy to switch back
without any code changes.

gofumpt support is built into the tooling we use for development
so this won't change development workflows.

- golangci-lint includes a gofumpt check (enabled in this PR)
- gopls, the LSP for Go, includes a gofumpt option
  (see [installation instrutions][3])

  [3]: https://github.com/mvdan/gofumpt#installation

This change was generated by running:

```bash
gofumpt -w $(rg --files -g '*.go' | rg -v testdata | rg -v compilation_error)
```

The following files were manually tweaked afterwards:

- pkg/cmd/pulumi/stack_change_secrets_provider.go:
  one of the lines overflowed and had comments in an inconvenient place
- pkg/cmd/pulumi/destroy.go:
  `var x T = y` where `T` wasn't necessary
- pkg/cmd/pulumi/policy_new.go:
  long line because of error message
- pkg/backend/snapshot_test.go:
  long line trying to assign three variables in the same assignment

I have included mention of gofumpt in the CONTRIBUTING.md.
2023-03-03 09:00:24 -08:00
Abhinav Gupta 1158d4acee
all: Drop ioutil
Stop using io/ioutil across the entire repository.
The io/ioutil package was deprecated in Go 1.16 (2021-02)
with replacements provided in other packages.
Specifically:

    ioutil.Discard   => io.Discard
    ioutil.NopCloser => io.NopCloser
    ioutil.ReadAll   => io.ReadAll
    ioutil.ReadFile  => os.ReadFile
    ioutil.TempDir   => os.MkdirTemp
    ioutil.TempFile  => os.CreateTemp
    ioutil.WriteFile => os.WriteFile

This change switches all of these entities
across the repository.

Following this change,
the only references to ioutil are in schema files:

    % rg -l ioutil
    pkg/codegen/testing/test/testdata/aws-4.26.0.json
    pkg/codegen/testing/test/testdata/aws-4.36.0.json
    pkg/codegen/testing/test/testdata/aws-4.37.1.json
    pkg/codegen/testing/test/testdata/aws-5.4.0.json
    pkg/codegen/testing/test/testdata/aws-5.16.2.json

The bulk of this change was generated automatically
with manual touch ups afterwards.
2023-01-06 16:35:14 -08:00
Ian Wahbe f87d407ca2 Use the test loader when binding files 2022-10-24 16:47:54 -07:00
Fraser Waters 53f28c487e
Consistently disable HTML escaping in JSON output ()
* Consistently disable HTML escaping in JSON output

* Add to CHANGELOG

* Add test

* fix warning

* Add RawJSON

* Change to RawJSON

* Change MarshalIndent to JSON

* Don't try to replace everywhere

* Targeted fix for stack state
2022-08-19 13:27:34 +01:00
Aaron Friel d08c79315e
testing: add eks schema for codegen tests () 2022-05-02 15:52:03 -07:00
Ian Wahbe 7da81c1d7f
PCL: Use resource aliases when resolving a type ()
* PCL: Use resource aliases when resolving a type

* Add a test

* Fix lint

* Fetch schemas in the makefile

Because we have exposed the `TestProgramCodegen` function to the public,
we can no longer pin specific schema version from that function. In
general, we should avoid mutating global state in tests. This becomes
especially important when the tests are used by other packages.

Using the makefile to setup global state both simplifies how we fetch
schemas and ensures that the fetches are intentional.

* Fix path

* remove unused imports

* Add comments
2022-03-18 11:48:39 -07:00
Ian Wahbe a1e18dae4d
export codegen tests for internal use ()
* Export Codegen test modules

* Document pkg stability guarantee

* Expose programgen

* Recommendation: Improve wording

* Move `internal` to `testing`

* Re-rout references to codegen/internal

* Fix some other "internal" references
2022-02-07 12:10:04 +01:00