Commit graph

228 commits

Author SHA1 Message Date
Justin Van Patten de871cec8e
Add schema support for methods (#7141) 2021-06-10 09:47:25 -07:00
Justin Van Patten f1fa3a141d
[codegen/dotnet] Fix plain properties (#7180)
Fix the generated C# code for plain properties:

- Value types should not be initialized with `= null!`
- Arrays and maps should be `List<T>` and `Dictionary<string, TValue>`
2021-06-04 09:25:20 -07:00
Mike Metral 672feff428
Fix Go init.go codegen to be govet compliant (#7195)
Co-authored-by: Mike Metral <mmetral@apple.com>
2021-06-04 13:57:04 +03:00
Justin Van Patten ed9124972c
[codegen/go] Fix emitted type of resources and types (#7158)
In Go, resource types are modeled as pointers, but there were cases where the type was not being emitted as a pointer, leading to panics and marshaling errors in programs. Additionally, array and map values that are external references were being emitted as pointers, but only resources should be pointers (not types), regardless of whether the resource type is external or local.
2021-05-27 16:02:19 -07:00
Levi Blackstone aeb6857f7f
[codegen] Encrypt input args for secret properties (#7128)
The output side was already handled using the
addionalSecretOutputs property. This change
ensures both inputs and outputs are encrypted
in the state.
2021-05-26 16:00:51 -06:00
Evan Boyle b4323ea437
Relax readonly requirement for generated nodejs resource args (#6980) 2021-05-06 21:59:40 -07:00
James Nugent 73c8cc3ec5
Permit override of Python package naming (#6971)
This commit adds a new language option for Python generation to specify
the package name instead of using `pulumi_x` where x is the name defined
in the schema.

A new test is added, and this has also been shown to produce no diff
when run against `pulumi-eks`.
2021-05-06 11:18:14 -07:00
Mikhail Shilkov 1378c45849 Discriminated unions in schema and programgen 2021-05-05 10:01:22 +02:00
Christian Nunciato 3b8a0dd3e3
Remove leading and trailing whitespace in resource properties (#6959)
* Remove leading and trailing whitespace in resource properties

* Make tests pass

* Add PULUMI_ACCEPT support to docs gen tests

* Handle a couple more places

Co-authored-by: Pat Gavlin <pat@pulumi.com>
2021-05-04 17:59:30 -07:00
James Nugent 93d7057f80
[codegen/go] Respect baseImportPath in Go SDKs (#6866)
If `rootPackageName` is set, we can look for the version in the
baseImportPath rather than at a location based on the package name -
which currently fails if every component is not named `pulumi-*`. To err
on the side of caution, this method is only used for packages where
`rootPackageName` is set, meaning existing SDKs retain their current
behavior.

The new behavior is confirmed via the test added in #6862.
2021-04-29 17:09:05 -06:00
Anton Tayanovskyy 6f1ea08993
Import subpackages lazily (#6827)
* Import subpackages lazily

* Tighten up lazy_import impl

* Eagerly register resources, but lazily load their impl

* Add CHANGELOG entry

* Satisfy lint

* Restore mypy behavior so the change is not breaking

* Fix golden tests
2021-04-29 16:08:22 -04:00
James Nugent f73ec2fc71
[codegen/go] Permit production of flat Go packages (#6862)
When working in a monorepo environment, it can be desirable to generate
Go SDKs into a structure less like the upstream SDKs, and more like
this:

github.com/x/mymonorepo/sdk/go/package-name

Where `package-name` is also the root of a Go module. Since
`package-name` is not a valid package name in Go, it's also desirable to
be able to choose a replacement name and reduce the amount of nesting.

This commit adds a new Go option to the schema, `rootPackageName`, which
can be used to modify the generated root package name (e.g. to
`mypackage` instead of `package-name`, and remove the additional layer
of nesting.

Test coverage is added to ensure that the correct file structure and
package names are generated.
2021-04-29 13:30:01 -06:00
Pat Gavlin 6a33b4b7ee
Distinguish between inputty and plain args types. (#6811)
These changes fix a regression introduced by #6686 that caused the SDK
code generators for .NET, Python, and Typescript to omit definitions for
plain object types. This regression occurred because #6686 drew a
clearer line between types used as resource arguments and types used
as function arguments, but conflated "resource arguments" with "inputty
types". This caused the code generators to generate inputty types for
any types used as resource arguments, even those that are used for
plainly-typed properties.

Fixes #6796.
2021-04-19 16:40:39 -07:00
Pat Gavlin 89595a3365
Do not wrap types in Input<> when generating docs. (#6812)
Just what it says on the tin. These changes also add more expansive
tests for documentation generation using our existing example schemas.

Fixes #6797.
2021-04-19 14:05:23 -07:00
Pat Gavlin 1cc084dc0e
Fix inconsistent object type naming. (#6686)
See #6200 for a complete description of the issue. In short, we generate
inconsistent names for object types depending on whether or not they are
transitively reachable from resources or functions, which risks
unintentional breaking changes due to schema updates.

1. Name "input" types differently: `TArgs` for a type that is used in
   resource inputs, having `Input<T>` properties, and `T` for a type
   that is used in invoke inputs. The same schema type can produce both.

2. Always keep the name `T` for output types, avoid appending `Result` to
   the name.

3. As needed, introduce a flag in the existing providers' schemas to avoid
   breaking changes. Consider removing it on a major version bump.

Fixes #6200.
2021-04-15 19:03:28 -07:00
Justin Van Patten f7f33d92af [codegen/python] Remove deprecated __name__ and __opts__ args (#6765)
These have been deprecated for a very long time and it's a trivial change to remove them from the generated code. Let's clean this up for the 3.0-based providers.
2021-04-14 19:32:18 +01:00
Justin Van Patten fef3157b18 [codegen/python] Adopt improved key translation (#6696)
This change updates the Python SDK codegen to opt-in to the new casing
translation behavior, which will use the passed-in props type's property
name metadata for translations, rather than calling the resource's
`translate_input_property` and `translate_output_property` methods.

- FIX: Keys in user-defined dicts will no longer be unintentionally
  translated/modified.

- BREAKING: Dictionary keys in nested output classes are now
  consistently snake_case. If accessing camelCase keys from such output
  classes, move to accessing the values via the snake_case property
  getters (or snake_case keys). A warning will be logged when accessing
  camelCase keys.

When serializing inputs:

- If a value is a dict and the associated type is an input type, the
dict's keys will be translated based on the input type's property
name metadata.

- If a value is a dict and the associated type is a dict (or Mapping),
the dict's keys will _not_ be translated.

When resolving outputs:

- If a value is a dict and the associated type is an output type, the
dict's keys will be translated based on the output type's property
name metadata.

- If a value is a dict and the associated type is a dict (or Mapping),
the dict's keys will _not_ be translated.
2021-04-14 19:32:18 +01:00
stack72 e05477b8d6 [deps] Ensuring pulumi/pulumi pkg references pulumi sdk v3.0.0-beta.1 2021-04-14 19:32:18 +01:00
pulumi-bot 73a66f48ea [breaking] Changing the version of go.mod in sdk / pkg to be v3 2021-04-14 19:32:18 +01:00
Justin Van Patten dcf4359c57
[codegen/python] Support <Resource>Args classes (#6525)
Add support for creating instances of resources in Python using a
`<Resource>Args` class. This capability aligns with how args are passed
to resources in all the other language SDKs and the separate object bag
allows the properties to be manipulated/validated/passed-around before
creating the resource.
2021-04-02 10:09:17 -07:00
Justin Van Patten a9f0aead13
[codegen/go] Fix Go resource registrations (#6641)
We've been emitting calls to `New<Resource>` for resource registrations
in Go, passing `nil` for args. However, some of those `New<Resource>`
functions actually check for `nil` args and return an error if the
resource has required arguments.

At first, I was looking for a way to check inside `New<Resource>` if
the `URN` option was specified and in that case not error on
`nil` args (like we do in other languages), but we don't provide a way
to access the resource option values outside the Go SDK), so I don't
think there is a way to do it this way for Go.

So instead, this change updates the registration code to call
`ctx.RegisterResource` directly instead of `New<Resource>`, where we can
pass a `nil` args.
2021-03-31 16:50:30 -06:00
Vivek Lakshmanan 78c48d5d31 Fix comment/example handling 2021-03-30 22:24:45 -07:00
Vivek Lakshmanan 3151d23f09 Fix to create inputs for nested collections types 2021-03-30 22:24:11 -07:00
Vivek Lakshmanan 700a576b70 Support nested collection types 2021-03-30 22:24:11 -07:00
Paul Stack 1f16423ede
Change nodejs codegen to use coalescing operator when when default values are present (#6496) 2021-03-10 21:16:18 +00:00
Justin Van Patten 572c74826c
Add schema & codegen support for plain properties (#6481)
This change adds schema and codegen support for plain properties which
are emitted typed as the plain type rather than wrapped as an `Input`.
Plain properties require a prompt value and do not accept a value that
is `Output`.
2021-03-10 07:08:08 -08:00
Komal 8616390418
[codegen/python] - Fix python .get() codegen (#6433) 2021-03-01 09:54:25 -08:00
Vivek Lakshmanan 8d022e39e8 Fix tests 2021-02-25 22:26:54 -08:00
Vivek Lakshmanan 92571f8f12 Adding enum container types support for go codegen 2021-02-25 22:26:37 -08:00
Justin Van Patten bdc309bb4a
[codegen/python] Fix issues related to referencing external resources/types (#6328)
- Fix bugs referencing external resources/types
- Fix circular import issue
- Avoid panic when referencing external nested types
2021-02-12 15:54:19 -08:00
Luke Hoban f4b0fa86fe
Don't mutate the opts argument in resource constructors in Node.js (#6321) 2021-02-13 05:10:59 +11:00
Justin Van Patten e86a69bedd
[codegen/nodejs] Emit externally referenced resources/types (#6225) 2021-01-29 16:52:00 -08:00
Vivek Lakshmanan 1452709e97 Fix test 2021-01-29 10:14:24 -08:00
Vivek Lakshmanan 82020af298 Various fixes go codegen to fix SDK compilation problems 2021-01-26 23:16:42 -08:00
Justin Van Patten d7dc6bf404
[codegen/dotnet]: Fix bugs referencing external resources/types (#6182)
- Avoids problematic `using` statements.
- Fixes fully qualified names of external resources.
- Avoids emitting directories with README.md files for external modules.
2021-01-26 11:02:34 -08:00
Vivek Lakshmanan b8e0d53b9b Fix tests for other languages for updated enum test schema 2021-01-22 17:30:44 -08:00
Vivek Lakshmanan fd3bbca5aa Fix default value handling for enums 2021-01-22 17:30:44 -08:00
Vivek Lakshmanan 88d54c0c64 Cleanup 2021-01-21 16:09:08 -08:00
Vivek Lakshmanan f5c76031ae Cleanup test go.mod
Follow up from https://github.com/pulumi/pulumi/pull/6124
2021-01-21 16:00:10 -08:00
Vivek Lakshmanan 4da8a45eb2 Option to generate container types resources now specified in GoPackageInfo 2021-01-20 11:29:01 -08:00
Vivek Lakshmanan 38ac84038c Make resource container-type generation optional 2021-01-20 11:29:01 -08:00
Vivek Lakshmanan 3aa566d286 Fix tests 2021-01-20 11:29:01 -08:00
Vivek Lakshmanan 68b655bba6 Test fixes for other languages due to change in schema. 2021-01-20 11:29:01 -08:00
Vivek Lakshmanan 8f2901df01 Test data to cover types generated for external references 2021-01-20 11:29:01 -08:00
Vivek Lakshmanan 22896074f3 Expand testing to cover all generated files 2021-01-20 11:29:01 -08:00
Levi Blackstone 2dfec71a5c
[codegen/go] Register resource modules/packages (#6121) 2021-01-19 16:59:51 -07:00
Vivek Lakshmanan b70c89eeec Allow optional strict enum types to be omitted
Fixes https://github.com/pulumi/pulumi/issues/6068
2021-01-11 09:58:32 -08:00
Mikhail Shilkov 0f9273fc7b
[codegen] Add support for default values in enum properties (#6017) 2020-12-30 12:46:01 +01:00
Levi Blackstone d3c75afce1
[codegen/go] Fix Input/Output methods for Go resources (#5916) 2020-12-11 11:49:08 -07:00
Mikhail Shilkov cab39dcfa0
[dotnet] Resource package registration in .NET (attributes) (#5875)
* Resource package registration in .NET
* Refactor to attribute-based discovery
* Refactor to derived attributes
2020-12-09 23:28:58 +01:00
Justin Van Patten 260620430c
[codegen/(nodejs|python)] package/module registration with version info (#5839)
Generate ResourcePackage and ResourceModule implementations and
registrations. A ResourcePackage is generated for any module that
includes a provider resource (which should be the root module only), and
a ResourceModule is generated for any module that includes a resource.

And add version info to Python registrations.
2020-12-02 13:45:25 -08:00
Komal 600e296ee2
[codegen/python] - Enums (#5553) 2020-11-24 23:43:32 -06:00
Komal 995d3b9b6c
Remove UsesIOClasses check. (#5827) 2020-11-24 19:15:37 -06:00
Paul Stack d64c58c731
Ensure the correct qualified code is emitted for Python ResourceOptions (#5824) 2020-11-24 02:21:25 +00:00
Justin Van Patten a9d213107b
[codegen/(dotnet|python)]: Emit refs to provider resources (#5810) 2020-11-23 12:28:00 -08:00
Mikhail Shilkov a056daafd7
[codegen/dotnet] Handle external resource refs (#5791) 2020-11-20 21:09:34 +01:00
Pat Gavlin f527e06b21
Allow schemas to reference to provider types. (#5788)
These changes extend the type reference parser in the schema package to
accept references of the form "(package/version/schema.json)?#/provider".
These references refer to the package's provider type, which is
otherwise not referenceable, as it is not present in the "resources"
array.
2020-11-20 09:16:45 -08:00
Levi Blackstone 3586ab5d85
[codegen/python] Handle external schema refs (#5684) 2020-11-19 13:56:28 -07:00
Vivek Lakshmanan da5c01f9ca Fix build/tests 2020-11-18 00:13:41 -08:00
Vivek Lakshmanan 65e027062d Add an underscore if enum values have underscores 2020-11-18 00:07:42 -08:00
Vivek Lakshmanan 41fff5dc08 Add type as prefix for enum values 2020-11-18 00:07:42 -08:00
Vivek Lakshmanan 169fb47154 Consolidate tests 2020-11-18 00:07:42 -08:00
Vivek Lakshmanan 3c2b7a8945 Add additional test to demonstrate strict/relaxed enum semantics 2020-11-18 00:07:42 -08:00
Vivek Lakshmanan 43e48950df Adding support for go enum generation 2020-11-18 00:07:42 -08:00
Levi Blackstone 64e5de1edc
[codegen/go] Add support for ResourceType and isComponent (#5497) 2020-11-09 11:55:53 -07:00
Paul Stack 3d8068e355
adding the import documentation where specified (#5667) 2020-11-09 14:12:58 +00:00
Komal 00f8966a9a
[codegen/nodejs] - Fix typescript enum issues (#5696)
Co-authored-by: Levi Blackstone <levi@pulumi.com>
2020-11-06 09:29:49 -08:00
Komal e9dbada593
[codegen/dotnet] - Enums (#5551) 2020-11-06 09:01:03 -08:00
Levi Blackstone 5188ec4c9f
[codegen/schema] Add support for external schema refs (#5606) 2020-10-29 17:41:12 -06:00
Komal ec9c02f578
Add tests for ts enums (#5605) 2020-10-22 10:53:29 -07:00
Levi Blackstone 99ba1ab943
[codegen/dotnet] Add support for ResourceType and isComponent (#5460) 2020-10-13 12:33:22 -06:00
Komal af9f636eef
Split schema tests by language (#5540) 2020-10-10 13:47:23 -07:00
Komal 6c51e6ce1c
[codegen/nodejs] - Update enum generation (#5525) 2020-10-09 08:27:01 -07:00
Vivek Lakshmanan 08272ff49a
Merge pull request #5520 from pulumi/vl/dotnetProgramGen
Fix config params and default handling for .NET programgen
2020-10-08 00:30:11 -07:00
Komal 7039e67284
[codegen/nodejs] - Enums (#5472) 2020-10-07 18:13:10 -07:00
Vivek Lakshmanan a0ee220243 Convert config params to outputs only if promise types are seen 2020-10-07 12:29:33 -07:00
Vivek Lakshmanan f4235f27a1 Fix config params and default handling for .NET programgen
Fixes https://github.com/pulumi/pulumi-azure-nextgen/issues/42
2020-10-07 09:59:23 -07:00
Vivek Lakshmanan e49ba01f8f PR comments 2020-10-06 16:13:49 -07:00
Vivek Lakshmanan ea75755d88 Add test scaffolding for azure provider 2020-10-06 16:13:30 -07:00
Levi Blackstone 38172999e7
[codegen] Extract common test logic (#5480) 2020-09-30 14:41:52 -06:00
Levi Blackstone 64602798b1
[codegen/python] Don't generate get methods for ComponentResources (#5459) 2020-09-30 10:16:25 -06:00
Komal 59b906eb76
Update nodejs gen-tests (#5477) 2020-09-29 16:00:03 -07:00
Levi Blackstone 9363f606b6
[codegen/schema] Add IsComponent to resource schema (#5395)
Add support for ComponentResources to the schema by
adding a new IsComponent field to the Resource spec.
2020-09-23 18:23:46 -06:00
Levi Blackstone 81580289a7
[codegen/python] Handle ResourceType (#5444) 2020-09-23 13:39:25 -06:00
Levi Blackstone 3ea59ebbb8
[codegen/schema]: Add ResourceType to support resource refs (#5325) 2020-09-22 11:09:27 -06:00
Komal a334b60193
Only allow type-matching enum values (#5417)
* Only allow type-matching enum values

* More tests and fixes
2020-09-21 12:23:04 -07:00
Evan Boyle c9d8549ae6
[Go Program Gen] Only generate a single literal when traversing a union type (#5154) 2020-08-11 11:43:56 -07:00
Komal 2f2e62e2e4
[codegen/python] - Normalize module names in program gen (#5128) 2020-08-07 09:30:07 -07:00
Mikhail Shilkov 0c9d1fdd0e
Fix C# program gen for Kubernetes examples (#5129) 2020-08-07 09:31:42 -06:00
Pat Gavlin e5f44a7b0c
Use a package map where appropriate (#5127)
* Use a package map where appropriate

* Fix imports

* handle NoneType for literal value expressions in go program gen

* add operator tests for c#, python, and node

Co-authored-by: evanboyle <evan@pulumi.com>
2020-08-06 19:09:18 -07:00
Komal ff219a2381
Use input/output classes in program gen (#5086) 2020-08-06 15:09:23 -07:00
Evan Boyle fbf391fd4b
Merge pull request #5115 from pulumi/evan/fixKubeProgramGen
[Go Program Gen] Fix various Kubernetes issues
2020-08-05 17:30:23 -07:00
evanboyle 2f71fbbf2d traverse object and tuple cons expressions for imports 2020-08-05 15:23:36 -07:00
Komal 269b537e57
[codegen/python] - Fix python resource tokens (#5107) 2020-08-05 12:50:54 -07:00
evanboyle 8af3be1e3f account for import aliases in program expressions 2020-08-05 12:44:46 -07:00
evanboyle e2e6db47f7 use import aliases in Go program gen 2020-08-05 11:42:38 -07:00
Evan Boyle 13ee9fd4c8
tests for kubernetes program generation (#5105) 2020-08-05 09:15:36 -07:00
Pat Gavlin a8a20ecb4b
[codegen/*] Add support for explicit secrets. (#4927)
- Add a new builtin function, secret, that marks its input value as
  secret
- Add support for this function to the various code generators

Fixes #4924.
2020-06-30 11:35:24 -07:00
Evan Boyle 395a68e0f6
[Go program gen]: namespaceless resources (#4915) 2020-06-29 18:10:34 -07:00
Pat Gavlin 69ba47cff2
[codegen/*] Add support for resource options. (#4925)
The PCL binder has supported resource options for some time, but these
options haven't been used or processed by the various code generators.
These options--particularly the parent and provider options0--are
critical for import codegen. These changes implement the basic set of
options, and add a note about fleshing out the rest as necessary.

One component of these changes is a new rewriter that rewrites property
references into property paths that are understood by the Pulumi engine.
This rewriter is used to preprocess the contents of the `ignoreChanges`
resource option.

These changes also hack around a weakness in the HCL2 type system:
In Go, references to resources should be typed as `hcl2.ResourceType`.
Unfortunately, this breaks the existing collection semantics associated
with resources. Because of this, the Go code generator does not have
enough information to know that it should generate a `[]pulumi.Resource`
for lists of resources. These changes hack around that limitation using
a Go-specific opaque type and some hardcoded comparisons in
`argumentTypeName`.

Fixes #4923.
2020-06-29 16:33:52 -07:00
Evan Boyle 91828b4310
[Go Program Gen] Improved handling for pulumi.Map types (#4914) 2020-06-29 15:29:41 -07:00
Evan Boyle 31770c3300
go program gen: prompt array conversion, unused range vars, id handling (#4884) 2020-06-24 11:07:26 -07:00
Evan Boyle b302dbcbca
go program gen: lift expressions where prompt optionals are required (#4875) 2020-06-23 10:59:26 -07:00
evanboyle 2ba1fd608a go program gen All.Apply func rewriter 2020-06-18 17:17:51 -07:00
evanboyle 7f2a83ae5a Revert "go program gen All.Apply rewriter"
This reverts commit bdd240f522.
2020-06-18 16:57:55 -07:00
evanboyle bdd240f522 go program gen All.Apply rewriter 2020-06-18 16:56:26 -07:00
Evan Boyle 8b8170252b
[Go Program Gen] multiline strings, get/lookup disambiguation, webserver example (#4850) 2020-06-18 13:34:22 -07:00
Evan Boyle 9cdddd2566
[Go Program Gen] Support for EKS example (#4831) 2020-06-17 17:19:39 -07:00
Evan Boyle 2d61852e4f
Go program gen: resource range, readDir, template strings, etc (#4818) 2020-06-15 23:00:02 -07:00
Evan Boyle 94cd67b564
[Go Program Gen] Improved type handling and invokes (#4749) 2020-06-05 18:52:00 -07:00
Evan Boyle ea114b04ee
output generation for s3 logging example (#4681) 2020-05-26 07:07:54 -07:00
Evan Boyle 8dd329f57f
Go basic program gen (#4667) 2020-05-21 10:23:33 -07:00
Mikhail Shilkov f66100ce28
Initial support for C# program gen (#4611)
Initial support for C# program gen
2020-05-19 10:18:38 +02:00
Evan Boyle 0d257bb32d
go gen_program shell + test + sample (#4630) 2020-05-14 08:43:12 -07:00
Pat Gavlin 255620ea1e
[codegen/nodejs] Await invokes in async contexts. (#4598)
If we are generating code into an async context (e.g. an async main),
await calls to invoke rather than leaving them as promises. This results
in more idiomatic code withing such contexts.
2020-05-11 10:21:56 -07:00
Pat Gavlin fc00c16e31
[codegen/hcl2] Fix iterator apply rewrites. (#4589)
There are two expressions in HCL2 that are used to iterate over
collections:

- Splat expressions, e.g. `foo.*.bar`, and
- For expressions, e.g. `[for v in foo: v.bar]`

In both of these cases, the parts of the expression that are not the
collection being iterated behave like callbacks, and must be treated as
such by the apply rewriter.
2020-05-07 12:15:40 -07:00
Pat Gavlin f23b98a7df
[codegen/nodejs] Fix #4563. (#4579)
Do not wrap non-output-typed arguments to `pulumi.all` in
`pulumi.output`. `pulumi.all` does this implicitly.

Fixes #4563.
2020-05-06 10:09:20 -07:00
Pat Gavlin 0e512aa0ef
[codegen/{nodejs,python}] Parse more proxy applies (#4576)
Specifically, handle index and relative traversal expressions, and clean
up the code a little bit.

This should also help us pick up more `pulumi.interpolate` calls in TS.
2020-05-05 21:51:53 -07:00
Pat Gavlin 96300f12d9
[codegen/*] Improve range type binding + codegen. (#4552)
- Determine variable types for ranged resources by typechecking an
  equivalent expression
- Detect top-level await in NodeJS and generate an async main
- Fix `pulumi.all` generation for NodeJS
- Fix a bug in the lowering of relative traversals in Python
2020-05-04 15:04:35 -07:00
Pat Gavlin 1d6cce98fe
[codegen/python] Fix nested quotes. (#4539)
Unlike most languages with interpolated strings, Python's formatted
string literals do not allow the nesting of quotes. For example,
this expression is not legal Python:

    f"Foo {"bar"} baz"

If an interpolation requires quotes, those quotes nust differ from the
quotes used by the enclosing literal. We can fix the previous example
by rewriting it with single quotes:

    f"Foo {'bar'} baz"

However, this presents a problem if there are more than two levels of
nesting, as Python only has two kinds of quotes (four if the outermost
string uses """ or '''): in this case, the expression becomes
unspellable, and must be assigned to a local that is then used in place
of the original expression. So this:

    f"Foo {bar[f'index {baz["qux"]}']} zed"

becomes this:

    index = "qux"
    f"Foo {bar[f'index {baz[index]}']}"

To put it bluntly, Python code generation reqiures register allocation,
but for quotes. These changes implement exactly that.

These changes also include a fix for traversals that access values that
are dictionaries rather than objects, and must use indexers rather than
attributes.
2020-04-30 16:34:25 -07:00
Pat Gavlin 5271eda247
[codegen/python] Fix case mapping. (#4538)
Mapping happens at package scope, not type scope. This is what causes
some of the surprising mixes of camel and snake casing in our packages.

In order to accommodate this, build the case mapping tables up front,
and refer to them when performing case mapping.
2020-04-30 14:16:56 -07:00
Pat Gavlin 9204d70c54 Fix Python input property names.
- Fix input property names and forms for invokes. Previously we
  generated a dict; now we generate properly-named args.
- Fix nested property names for resources.
2020-04-21 13:55:33 -07:00
Pat Gavlin 1d672563da Fix output property names in Python codegen.
Some property names are mapped from their `camelCase` Pulumi name to a
`snake_case` Python name. This mapping is irregular, and only occurs for
resources properties and function calls.

Note that there's still more work to do here: this only fixes names on
the output side; the input side is still broken for nested resource
proprerties and function calls.

The underlying design--annotated types in `hcl2/model`--may need some
additional work in the future, but I _believe_ it's good enough for now.
2020-04-21 10:25:27 -07:00
Pat Gavlin 807cf44cd7
Codegen: collect imports from function calls. (#4445)
Codegen: collect imports from function calls; fix Python resource names.

Just what it says on the tin.
2020-04-21 10:24:42 -07:00
Pat Gavlin 398878de31
Various codegen updates. (#4424)
- Define `null` in Pulumi HCL2
- Bind Pulumi HCL2 in topological order s.t. variable types can be
  properly computed
- Fix resources that range over bools and numbers
- Add element, length, lookup, readFile, and split functions
- Do not rewrite function signatures with input types during binding
- Fix splat expression binding for non-lists
- Add support for evaluating expressions
- Add support for operator precedence to code generators
- Add support for constants to the HCL2 IR
- Add support for generating ranged resources in Python
- Add support for generating conditional resource in Node and Python
- Fix various naming issues in Python
2020-04-16 16:44:34 -07:00
CyrusNajmabadi 66bd3f4aa8
Breaking changes due to Feature 2.0 work
* Make `async:true` the default for `invoke` calls (#3750)

* Switch away from native grpc impl. (#3728)

* Remove usage of the 'deasync' library from @pulumi/pulumi. (#3752)

* Only retry as long as we get unavailable back.  Anything else continues. (#3769)

* Handle all errors for now. (#3781)


* Do not assume --yes was present when using pulumi in non-interactive mode (#3793)

* Upgrade all paths for sdk and pkg to v2

* Backport C# invoke classes and other recent gen changes (#4288)

Adjust C# generation

* Replace IDeployment with a sealed class (#4318)

Replace IDeployment with a sealed class

* .NET: default to args subtype rather than Args.Empty (#4320)

* Adding system namespace for Dotnet code gen

This is required for using Obsolute attributes for deprecations

```
Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'ObsoleteAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj]
Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'Obsolete' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj]
```

* Fix the nullability of config type properties in C# codegen (#4379)
2020-04-14 09:30:25 +01:00
Pat Gavlin 00f1433706
HCL2/NodeJS: fix proxy apply lowering for promises (#4317)
Applies cannot be proxied when the applied value is a promise.

Fixes #4315.
2020-04-07 09:25:50 -07:00
Pat Gavlin 2f22c1c59c
HCL2 updates (#4309)
Pulumi HCL2 IR:
- Add support for invokes
- Add support for resource options, incl. ranged resources
- Allow the apply rewriter to ignore promise-typed values
- Add tests for the binder
- Add support functions for TF: entries and range

NodeJS codegen:
- Simplify for expression codegen
- Add support for invoke codegen
- Add support for entries and range functions
- Add tests

Python codegen:
- Implement codegen for most expression types
- Add support for invoke codegen
- Add tests
2020-04-06 19:43:16 -07:00