Commit Graph

143 Commits

Author SHA1 Message Date
Zaid Ajaj f8236e125e
[docs/go-program-gen] Fix generating constructor syntax examples in Go for package awsx ()
Currently, when generating docs for the AWSX package, Go constructor
syntax examples were not generated due to a panic. This causes all
constructor examples to not be emitted in the docs.

The panic occurred when trying to get the version of referenced packages
in the PCL program to emit import paths. However, _transitive_ package
references were not resolved in the PCL binder when binding resource
types. This PR fixes the problem such that now we do find the transitive
package references from any input or output property of the resources
being bound.

In the case of the awsx package, the top-level package is awsx itself
and aws is the transitive dependency. Anytime in codegen we call
`program.PackageReferences()` we should get both of them. Added a unit
test for this as well.

Testing this fix locally against the awsx package showed constructor
examples being generated for every language, however there was still a
problem in the _formatting_ of Go code which is also fixed (see change
in `gen_program_expressions.go`)

Resolves part of 
2024-07-08 23:23:47 +00:00
Mikhail Shilkov 2f3f9f20e8
Vendor the inflector library ()
<!--- 
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

The gedex/inflector (singularization/pluralization) library has been
seemingly abandoned: still no go module support, no changes in years,
etc. It was decided that we want to fork it and maintain ourselves to
ensure both a) stability and backwards compatibility b) modernization
and quality.

This PR switches the inflector library. The next step will be TF bridge.

There are no functional changes in behavior - the library code is
exactly the same.

## 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
  - [ ] 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. -->
2024-06-20 09:04:33 +00:00
Zaid Ajaj b4c00f7e30
[go/program-gen] Fix union type type resolution in Go program generation ()
# Description

Fixes https://github.com/pulumi/pulumi-azure-native/issues/1554 

### Context
The problem here is that when we compute `InputType: model.Type` in
`pcl.Resource`, we map the types of input properties of resources from
`schema.Type` into `model.Type`. When one of these properties is a
`schema.UnionType` (union of objects to be exact), we map that _as is_
to `model.UnionType` which trips up Go program-gen as it doesn't know
how to reduce the type to the actual _selected_ object type based on the
resource inputs.

### Resolution
The way to fix this is not in Go program-gen, instead we _reduce_ the
computed union types during the binding phase into the actual object
types based on the resource inputs so that all program generators only
work against explicit objects rather than having to deal with unions of
objects

### Example:

```pcl
resource "example" "azure-native:eventgrid:EventSubscription" {
    destination = {
        endpointType = "EventHub"
        resourceId = "example"
    }
    expirationTimeUtc = "example"
    scope = "example"
}
```

Before:
```go
pulumi.Run(func(ctx *pulumi.Context) error {
	_, err := eventgrid.NewEventSubscription(ctx, "example", &eventgrid.EventSubscriptionArgs{
		Destination: eventgrid.EventHubEventSubscriptionDestination{
			EndpointType: "EventHub",
			ResourceId:   "example",
		},
		ExpirationTimeUtc: pulumi.String("example"),
		Scope:             pulumi.String("example"),
	})
	if err != nil {
		return err
	}
	return nil
})
```

After:
```go
pulumi.Run(func(ctx *pulumi.Context) error {
	_, err := eventgrid.NewEventSubscription(ctx, "example", &eventgrid.EventSubscriptionArgs{
		Destination: &eventgrid.EventHubEventSubscriptionDestinationArgs{
			EndpointType: pulumi.String("EventHub"),
			ResourceId:   pulumi.String("example"),
		},
		ExpirationTimeUtc: pulumi.String("example"),
		Scope:             pulumi.String("example"),
	})
	if err != nil {
		return err
	}
	return nil
})
```

## 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. -->
- [ ] 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-06-06 19:13:19 +00:00
Zaid Ajaj de54e1aa47
[docs] Fix generating constructor examples for resources that have numeric enums as input ()
# Description

Fixes  

The original issue is that the intermediate PCL we generate used enum
names instead of enum values for numeric enum inputs. This PR changes it
so that the PCL program now uses the first numeric value for the first
enum case then subsequently fixing downstream program-gen bugs that
didn't know how to handle numeric values as inputs for enums.

## 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-05-30 22:43:12 +00:00
guangwu ff8c44f9f5
fix: close files in PCL binder ()
<!--- 
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. -->

Close files in PCL parser after parsing.

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] 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. -->

---------

Signed-off-by: guoguangwu <guoguangwug@gmail.com>
Co-authored-by: Justin Van Patten <jvp@justinvp.com>
2024-05-07 23:36:10 +00:00
Fraser Waters 901c2f5e9c
Add StackReference conformance test ()
<!--- 
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. -->

Fixes https://github.com/pulumi/pulumi/issues/15932.

This adds a conformance test that checks that StackReferences work.
Tests a plain string and a secret string output.

To support this test we add a new intrinsic `getOutput` that takes a
stack reference resource and a string and calls the
`get_output/getOutput/GetOutput` method on the stack reference resource
type.


## 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
  - [ ] 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.
-->
- [ ] 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-04-16 11:13:25 +00:00
Aaron Friel e211f2e3d4
feat: declare a new type for 'any resource' ()
This commit exists to enable the Java SDK to update and use it, which
then unblocks the next commit passing tests.

Part of 

---------

Co-authored-by: Eron Wright <eron@pulumi.com>
2024-04-09 07:59:16 +00:00
Zaid Ajaj ad56486bf0
[docs] Emit example constructor syntax for resources in typescript, python, go and csharp ()
# Description

This PR is an initial implementation of emitting constructor syntax of
resources into the docs for typescript, python, go and csharp.

## 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-21 13:41:07 +00:00
Zaid Ajaj 3bdc65c6e5
[program-gen] Fix enum resolution from types of the form Union[string, Enum] and emit fully qualified enum cases ()
# Description

This PR improves enum type resolution from strings. When we try to
resolve `Union[string, Enum]` for a string expression, we choose
`string` because it is the more general type since not every string is
assignable to `Enum`. However, here we spacial case strings that are
actually part of that `Enum`.

The result is that `pcl.LowerConversion` will choose `Enum` from
`Union[string, Enum]` when the value of the input string is compatible
with the enum. This greatly improves program-gen for all of typescript,
python, csharp and go which now will emit the fully qualified enum cases
instead of emitting strings.

Closes https://github.com/pulumi/pulumi-dotnet/issues/41 which is
supposed to be a duplicate of
https://github.com/pulumi/pulumi-azure-native/issues/2616 but that is
not the case (the former is about unions of objects, the latter is
unions of enums and strings)

## 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-15 17:49:12 +00:00
Zaid Ajaj 3b9f5c09b7
[program-gen] Fix stack overflow when binding invoke that resolves to promise ()
# Description


Fixes  because using `ContainsPromises` doesn't account for
recursive object references where as `ContainsEventuals` does.

## 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. -->
- [ ] 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:49:08 +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
Zaid Ajaj b96f19b2fa
[program-gen/pcl] Fixes type-annotating nested resource properties when these have quoted keys ()
# Description

When binding resource properties and annotating these with types from
their schemas, we seem to skip this annotation process when resource
properties and their nested objects use _quoted_ keys `{ "key" = <value>
}` rather than using _literal_ keys `{ key = <value> }`.

This results in issues such as
https://github.com/pulumi/kube2pulumi/issues/60 where a csharp property
name override was not correctly applied because
1) kube2pulumi generated properties for resources that are quoted (this
should be fine)
2) binding the resource properties skipped annotating the nested object
with its corresponding schema type
3) program-gen in dotnet didn't have access to the schema type of the
nested object to correctly apply the property override

This PR fixes this issue by extending PCL resource binding to also check
for properties which have quoted keys.

Fixes https://github.com/pulumi/kube2pulumi/issues/60 and potentially
other issues that arise from converters generating PCL with quoted keys.

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
2023-12-27 12:42:52 +00:00
Fraser Waters 3560333ae6
Clean up uses of .Error() ()
Combination of a few cleanups.

1. Don't call .Error() on errors that are being passed to "%s" format
functions. Format will call `Error()` itself.
2. Don't call assert.Error then assert.Equal/Contains, just use
assert.ErrorEqual/ErrorContains instead.
3. Use "%w" if appropriate, instead of "%v"/"%s".
2023-12-20 15:54:06 +00:00
Zaid Ajaj 1430093ab0
[program-gen/pcl] Avoid pretty printing large object graphs when encountering bind error in resource properties ()
# Description

When we bind PCL program and a resource property doesn't type-check, we
pretty print the type of the resource property in its _entirety_ in the
error message and that includes nested objects, nested maps, nested
lists, unions etc. instead of using type references: we pretty print the
`model.Type` derived from `schema.Type` and this resolves the entire
graph.

This PR changes it such that we print the `schema.Type` in string form
in the error message when we encounter a bind error
in resource properties instead of fully resolving and printing the full
`model.Type`.

Fixes 

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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. -->
- [ ] 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. -->
2023-12-20 01:20:42 +00:00
Fraser Waters 797ab3d099
Replace some more uses of assert.Contains(err.Error()) with assert.ErrorContains () 2023-12-15 17:45:32 +00:00
Fraser Waters c56bb05174
Update golangci-lint () 2023-11-21 15:16:13 +00:00
Zaid Ajaj 0dd51644b4
[pcl/binder] Fixes panic when binding the signature of output-versioned invokes without arguments ()
# Description

Fixes  

## 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. -->
- [ ] 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. -->
2023-10-12 16:23:18 +00:00
Zaid Ajaj d90aef60f9
[go/sdk-gen] Generate output-versioned invokes for functions without inputs ()
# Description

Partially addressing  implements output-versioned invokes for
functions without inputs for go.


## 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. -->
2023-10-02 12:53:06 +00:00
Zaid Ajaj 28b92984e1 lint 2023-07-28 20:47:36 +02:00
Zaid Ajaj fe0b729889 Fixes code generation of ForExpressions 2023-07-28 20:30:00 +02:00
Zaid Ajaj 28deb6fb14 lint 2023-07-27 16:32:06 +02:00
Zaid Ajaj 3e39cb2820 Normalize the declaration name of generated resource components 2023-07-27 15:15:27 +02:00
Zaid Ajaj ef628d7ab0 Propagate SkipRangeTypechecking option down to program components 2023-07-14 19:00:38 +02:00
Zaid Ajaj 5841f220b1 Consistently use the same non-strict bind options when applicable 2023-07-13 15:16:06 +02:00
Zaid Ajaj 02d0c2a8fb lint 2023-07-13 01:08:42 +02:00
Zaid Ajaj fe5e65f0f4 Allow binding unsupported range and collection types in non-strict mode for pulumi convert 2023-07-12 19:13:57 +02:00
Zaid Ajaj ed02926277 Allow generating code for unknown invokes in non-strict mode 2023-07-10 15:05:18 +02:00
Fraser Waters 571fadae3f Use slice.Prealloc instead of make([]T, 0, ...)
Fixes https://github.com/pulumi/pulumi/issues/12738

https://github.com/pulumi/pulumi/pull/11834 turned on the prealloc
linter and changed a load of slice uses from just `var x T[]` to `x :=
make([]T, 0, preallocSize)`. This was good for performance but it turns
out there are a number of places in the codebase that treat a `nil`
slice as semnatically different to an empty slice.

Trying to test that, or even reason that through for every callsite is
untractable, so this PR replaces all expressions of the form `make([]T,
0, size)` with a call to `slice.Prealloc[T](size)`. When size is 0 that
returns a nil array, rather than an empty array.
2023-06-29 11:27:50 +01:00
Zaid Ajaj 7ab7ad5a58 Prefer output-versioned invokes in generated programs for nodejs and python 2023-06-23 02:42:18 +02:00
Zaid Ajaj e832a505f1 Implement lenient traversal for resources 2023-06-20 13:50:18 +02:00
Zaid Ajaj 464b07508e Allow traversing unknown properties from resources when skipping resource type checking 2023-06-16 15:06:08 +02:00
Zaid Ajaj 7e5e452909 Extend SkipResourceTypechecking to allow generating unknown resources 2023-06-14 19:02:56 +02:00
Zaid Ajaj a90ec3e20e Test that traversal of optional object works 2023-06-14 15:42:44 +02:00
Zaid Ajaj 6a174fa117 Fixes panic when trying to convert a null literal to a string value 2023-06-09 12:52:10 +02:00
bors[bot] d69e5f2d26
Merge
13131: [pcl/components] Fixes range scoping for PCL components r=Zaid-Ajaj a=Zaid-Ajaj

# Description

This PR implements proper `range` block scoping for `pcl.Component` so that when binding the component body, it understands references to the `range` expression. This fixes a couple of the PCL binder issues we have been seeing in TF converter such as  https://github.com/pulumi/pulumi-terraform-bridge/issues/1184, https://github.com/pulumi/pulumi-terraform-bridge/issues/1150, https://github.com/pulumi/pulumi-terraform-bridge/issues/1148 at least locally these errors are resolved for the linked TF example. 

Also small fix for the error we are seeing for `length(...)` because fields of object-typed config were implicitly optional and errored before. Now it flattens `option<T>` to just `T` and no longer errors. https://github.com/pulumi/pulumi-terraform-bridge/issues/1186

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] 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-08 23:37:53 +00:00
Zaid Ajaj e3e4dbdb02 lint 2023-06-08 22:07:18 +02:00
Zaid Ajaj 604d0f9b77 Fixes range scoping for PCL components 2023-06-08 21:43:54 +02:00
Fraser Waters ef7b123bba Don't return empty hcl.Diagnostics
Fixes https://github.com/pulumi/pulumi-terraform-bridge/issues/1201

hcl.Diagnostics implements the Error interface, but this means a list of
zero diagnostics still looks like a non-nil error, which throws of
normal "if err == nil" checks.

This changes a few use sites of hcl.Diagnostics to ensure we return nil
when there aren't any diagnostics rather than an empty slice. This
ensures if they get cast to `Error` they don't trip up standard `err ==
nil` checks.
2023-06-08 19:14:41 +01:00
Fraser Waters 46332e7d17 Make convert more lenient
Fixes https://github.com/pulumi/pulumi/issues/13117

This adds a new "--strict" flag to `pulumi convert` which defaults to
false. When strict is NOT set we bind the PCL with the extra options of
`SkipResourceTypechecking`, `AllowMissingVariables`, and
`AllowMissingProperties`. This will change some errors to warnings in
code generation.

The `strict` flag is sent over the gRPC interface to the Go/Node plugins
for their `GenerateProject` methods as they have to do PCL binding
plugin side currently.
2023-06-08 11:14:31 +01:00
Zaid Ajaj da875885bf Allow output variables to have the same identifier as other program nodes 2023-06-07 02:37:40 +02:00
Fraser Waters 5c999e28ca Test components in convert 2023-06-01 20:54:44 +01:00
bors[bot] 30d9980e35
Merge
13032: [pcl/program-gen] Implement singleOrNone intrinsic for python and typescript r=Zaid-Ajaj a=Zaid-Ajaj

### Description

Implements the `singleOrNone` PCL intrinsic function and its implementation for python and typescript. This function is used when converting terraform's dynamic block that are used with resource attributes where `maxItems == 1` which means the dynamic block (compiled to a for-expression) should evaluate to a single value or none at all. 

The PR adds unit tests to assert the possible error messages produced by the binder when it doesn't type-check correctly

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


Co-authored-by: Fraser Waters <fraser@pulumi.com>
Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
2023-05-30 13:45:47 +00:00
Zaid Ajaj f4a5c931fd use require no error when asserting in tests 2023-05-29 20:13:23 +02:00
Zaid Ajaj 4f0c9426cb lint 2023-05-25 22:16:00 +02:00
Zaid Ajaj 65ad123780 Implement singleOrNone intrinsic for typescript and python 2023-05-25 22:12:13 +02:00
Zaid Ajaj 0f25ea6471 include file name of component in diagnostic 2023-05-24 18:17:22 +02:00
Zaid Ajaj 1f1158ef94 Include the component source directory in diagnostics when reporting PCL errors 2023-05-24 16:29:01 +02:00
Fraser Waters cca81e50ff Add singleOrNone intrinsic 2023-05-24 14:35:09 +01:00
Abhinav Gupta ed5706ddb9
lint(govet): Enable nilness linter
govet includes a nilness linter that detects a few nil issues.
This linter is not enabled by default in govet because the `go` tool
does not want a dependency on the libraries necessary to implement this
().

Enable the nilness linter and fix the following issues found by it
(commentary below each check mine):

    pkg/cmd/pulumi/new.go:283:9: nilness: impossible condition: nil != nil (govet)
        ^- the error was very likely supposed to be the `os.Remove`
    pkg/cmd/pulumi/new.go:633:10: nilness: impossible condition: nil != nil (govet)
        ^- same error checked on the previous line
    pkg/cmd/pulumi/preview.go:190:11: nilness: impossible condition: nil != nil (govet)
        ^- same error checked a few blocks above
    pkg/codegen/pcl/binder_component.go:101:64: nilness: nil dereference in dynamic method call (govet)
        ^- err is guaranteed nil
    pkg/codegen/pcl/binder_component.go:133:10: nilness: impossible condition: nil != nil (govet)
        ^- err is guaranteed nil
    sdk/go/auto/errors_test.go:374:34: nilness: nil dereference in index operation (govet)
        ^- this is intentional; I replaced it with a deliberate panic
    tests/integration/construct_component_methods_resources/testcomponent-go/random.go:30:10: nilness: impossible condition: non-nil == nil (govet)
        ^- args is rejected if it's nil
2023-05-19 15:32:00 -07:00
Zaid Ajaj cb573d2aa2 Fix stack overflow panic when pretty printing recursive types 2023-05-11 16:28:16 +02:00