Commit Graph

134 Commits

Author SHA1 Message Date
Will Jones e63ff72eda
Fix documentation comments in the NodeJS SDK ()
This commit fixes a few errant documentation comments that use `//`
instead of the recognised `/**`. This should hopefully improve
documentation generation as well as hover-over documentation provided by
e.g. TSServer.
2024-06-03 12:50:03 +00:00
Fraser Waters a514601236
Flip transforms to non-experimental ()
Co-authored-by: Thomas Gummerer <t.gummerer@gmail.com>
2024-04-29 10:54:41 +00:00
Julien P 029fcc3ce0
Export automation.tag.TagMap type & @param tag fixes ()
# Description

Noticed a couple warnings when building the docs using typedoc.

- Fix some typedoc `@param` tags
- Export automation.tag.TagMap type


Ref: https://github.com/pulumi/docs/pull/10964

## 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. -->
2024-03-25 14:33:15 +00:00
Fraser Waters a18399285f
NodeJS transforms ()
<!--- 
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. -->

This adds a new experimental feature to the NodeJS SDK to register
remote transform functions. These are currently all prefixed 'X' to show
they're experimental.

These transform functions will run even for resources created inside
MLCs.

## 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. -->
- [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-07 08:52:34 +00:00
Justin Van Patten 0650e8bbbb
[sdk/nodejs] Fix provider for resource methods ()
The `Resource` class in the Node.js SDK has the following internal
property:

```typescript
/** @internal */
readonly __prov?: ProviderResource;
```

When a resource is created, the provider specified for the resource is
stored in this property. If it is set, it is passed along in the `Call`
request when a method is called on the resource.

Prior to , the property was only set for custom resources in
`Resource`'s constructor:

```typescript
this.__prov = custom ? opts.provider : undefined;
```

With , it was changed to also store the value for remote
components:

```diff
- this.__prov = custom ? opts.provider : undefined;
+ this.__prov = custom || remote ? opts.provider : undefined;
```

This regressed the behavior when calling a method on a remote component
that had an explicit provider that wasn't the component provider, but
some other provider (e.g. AWS provider) specified as:

```typescript
const component = new MyRemoteComponent("comp", {
}, { provider: awsProvider });
```

The `awsProvider` was being stored in `Resource.__prov`, and when making
the method call on the resource, it would try to invoke `Call` on the
AWS provider, rather than calling the remote component provider's
`Call`, which resulted in an error.

Note that specifying the AWS provider using the more verbose `providers:
[awsProvider]` works around the issue.

The fix is to only set `__prov` if the provider's package is the same as
the resource's package. Otherwise, don't set it, because the user is
specifying a provider with the `provider: awsProvider` syntax as
shorthand for `providers: [awsProvider]`.

Fixes 
2023-08-30 14:49:53 +00:00
Pat Gavlin 248f78bafe [sdk/*] Add support for resource source positions
Add support to the core SDKs for reporting resource source positions.

In each SDK, this is implemented by crawling the stack when a resource
is registered in order to determine the position of the user code that
registered the resource.

This is somewhat brittle in that it expects a call stack of the form:
- Resource class constructor
- abstract Resource subclass constructor
- concrete Resource subclass constructor
- user code

This stack reflects the expected class hierarchy of "cloud resource /
component resource < customresource/componentresource < resource".

For example, consider the AWS S3 Bucket resource. When user code
instantiates a Bucket, the stack will look like
this in NodeJS:

    new Resource (/path/to/resource.ts:123:45)
    new CustomResource (/path/to/resource.ts:678:90)
    new Bucket (/path/to/bucket.ts:987:65)
    <user code> (/path/to/index.ts:4:3)

In order to determine the source position, we locate the fourth frame
(the `<user code>` frame).
2023-07-13 16:46:04 -07:00
Justin Van Patten bfcb67361b [sdk/nodejs] Support explicit providers for packaged components
Updates the Node.js SDK to support passing an explicit provider.
2023-07-13 07:16:56 -07:00
Fraser Waters 84d4cc6371 Fix isInstance methods on generated provider types in the nodejs sdks
Fixes https://github.com/pulumi/pulumi/issues/12584
2023-06-28 14:59:10 +01:00
Robbie McKinstry 42870b5db2
Don't use the `delete` operator.
This commit replaces uses of `delete` with a safer option,
assigning undefined. `delete` has unexpected behavior and can harm perf.
2023-04-28 22:07:35 -04:00
Robbie McKinstry e05a3bd81c
Apply autoformat
This commit applies the Rome autoformatter to the Node SDK.
These changes are automatically produced. To reproduce these
changes, run `make format` from inside sdk/nodejs.
2023-04-28 18:27:10 -04:00
Kyle Pitzen 92cb70996c feat(sdk/nodejs): delegates alias computation to the engine 2022-12-15 17:23:31 -05:00
Sam Eiderman 4bbe365f15 Add DeletedWith resource option
In many cases there is no need to delete resources if the container
resource is going to be deleted as well.

A few examples:
 * Database object (roles, tables) when database is being deleted
 * Cloud IAM bindings when user itself is being deleted

This helps with:
 * Speeding the deletion process
 * Removing unnecessary calls to providers
 * Avoiding failed deletions when the pulumi user running the
   plan has access to the container resource but not the contained
   ones

To avoid deleting contained resources, set the `DeletedWith` resource
option to the container resource.

TODO:
 Should we support DeletedWith with PendingDeletes?
 Special case might be when the contained resource is marked as pending
 deletion but we now want to delete the container resource, so
 ultimately there is no need to delete the contained anymore
2022-10-31 12:03:18 +02:00
Kyle Pitzen 5cfad4a909 fix: Allows for parallel pulumi programs to run in the node runtime 2022-10-13 07:15:25 -04:00
Anton Tayanovskyy f6fc099792
Avoid importing typescript unless necessary ()
* Avoid importing typescript in node SDK where possible

* Lazy-load runtime/closure in dynamic/index.ts

* More targeted runtime import in config.ts

* More precise imports in run-policy-pack/run.ts

* More precise imports for dynamic-provider/index.ts

* More precise imports for automation/server.ts

* Share typescript compiler option loading func in run.ts and run-policy-pack/run.ts

* Lazy-load ts-node that depends on TypeScript

* Break module import cycle

* Fix node lint
2022-07-20 17:38:55 -04:00
Fraser Waters 07fec39800
Fix createUrn when parent is the stack type ()
* Fix createUrn when parent is the stack type

* lint
2022-06-30 16:13:04 +01:00
Fraser Waters 0d0144bca2
Stop using Get/SetRootResource in nodejs ()
* Stop using Get/SetRootResource in nodejs

Just use globalThis to make the stack resource a global rather than a module variable. This ensures that even if we end up with multiple Pulumi modules they can all grab the stack object and read URN off it.

We'll keep calling SetRootResource so old modules SxS continue to pickup the stack URN, at some point (4.0 probably) we can clean all this up.

Note that we also need the stack resource to be global for stack transformations, the roundtripping of the URN via the engine didn't preserve those.

* Update CHANGELOG

* Try to resovle circular module imports

* Remove comment

* Readd comment, remove unneeed await

* Fix comments

* Get rid of getRootResource, just pass parent down explictly

* Fix stack parents

* Add stack transform test
2022-06-30 11:04:49 +01:00
Fraser Waters 5d91f8f322
Add RetainOnDelete resource option ()
* Plumb in basics of retainOnDelete

* Add test

* Make test pass

* Add to changelog

* Add to API list

* lint

* Add semicolon

* Fix Infof call

* Fix method call

* new delete mode work

* cleanup

* protectTest

* Fix up test

* Fix replace

* Fix up test

* Warn on drop

* lint

* Change to just a bool flag

* Regenerate proto

* Rework to just a bool flag with no error

* Remove old comment

* Fix C# typo

* rm extra space

* Add missing semicolon

* Reformat python

* False typo

* Fix typo in js function name

* Reword docs

* lint

* Read doesn't need retainOnDelete
2022-02-16 22:11:12 +00:00
Ian Wahbe 00c138c54e
[sdk/nodejs] Make provider and providers behavior consistent ()
* Correct mergeOptions behavior

This behavior was under test, so the tests needed to be changed as well.

* Update register resource update

* Update CHANGELOG_PENDING.md

* Cleanup documentation and correct ordering
2022-01-25 20:11:41 +01:00
Ian Wahbe 9a5ba09f47
[sdk/nodejs] Add pluginServerURL ()
* Add pluginServerURL to the nodejs SDK

Tests that this work are included in the PR.

* Update CHANGELOG_PENDING.md

* Add codegen change

* Add codegen test results

* Support invoke

* Setup defaults for InvokeOptions
2022-01-10 15:54:41 -08:00
Luke Hoban 73098262d9
[sdk] Compute full set of aliases when both parent and child are aliased () 2021-12-29 09:07:55 -08:00
Horace Lee a92a005d68
Use ESlint instead of TSlint ()
Migrated TSlint configs to ESlint ones using [tslint-to-eslint-config](https://github.com/typescript-eslint/tslint-to-eslint-config) tool, and refined the configs to better match the current coding style.

Changes:
- [member-delimiter-style](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md#options) that as suggested default for type definition to be  with `semicolon`
- Indentation fixes that is enforced by [eslint-indent](https://eslint.org/docs/rules/indent#options)
- Added dependencies for ESlint with Typescript
- Removed TSlint
2021-08-10 11:31:59 -07:00
Justin Van Patten a05c3a4e9b
Set the package on DependencyProviderResource ()
When initializing `DependencyProviderResource`, pass the package to the base constructor instead of an empty string s.t. the provider is usable when its package is read.
2021-07-27 06:50:24 -07:00
Justin Van Patten e8bd8e5e1f
Rehydrate provider resources in `Construct` ()
Previously, any provider resource passed to multi-lang components would be instantiated as a `DependencyProviderResource` inside `Construct`, which prevents the component from being able to easily access the provider's state as an instance of of the provider (e.g. `*aws.Provider`).

This change attempts to rehydrate the provider resource in the same way that resource references are rehydrated, if it's been registered, s.t. the specific provider resource type is instantiated with its state. Otherwise falling back to returning `DependencyProviderResource`.
2021-07-23 14:10:06 -07:00
Luke Hoban 0bcca3883e
[sdk] Wait on remote component dependencies ()
When a resource `dependsOn` a remote component, we were not correctly waiting on it, because we were skipping over waiting on comoponents, and only waiting on their custom resource children.  For remote components, we do not know the children, but waiting on the remote component will always wait on all children.

Co-authored-by: Mike Metral <1112768+metral@users.noreply.github.com>
2021-07-16 16:11:34 -07:00
Justin Van Patten c1f3e1c84b
[sdk/nodejs] Support for calling methods () 2021-07-07 16:03:56 -07:00
Luke Hoban eb32039013
Add `replaceOnChanges` resource option ()
Adds a new resource option to force replacement when certain properties report changes, even if the resource provider itself does not require a replacement.

Fixes .

Co-authored-by: Levi Blackstone <levi@pulumi.com>
2021-07-01 13:32:08 -06:00
Justin Van Patten 84b574f0df
Initial support for resource methods (authoring from Node.js, calling from Python) ()
Adds initial support for resource methods (via a new `Call` gRPC method similar to `Invoke`), with support for authoring methods from Node.js, and calling methods from Python.
2021-06-30 07:48:56 -07:00
Levi Blackstone a94892aa2b
[sdk/nodejs] Handle providers for RegisterResourceRequest ()
Resolve providers references and include the resulting refs in the
providers field of RegisterResourceRequest that was added in
d297db3.
2021-04-19 16:41:53 -06:00
Justin Van Patten edc79325fe
Add support for getResource to Node.js SDK ()
And update Node's resource ref deserialization to match Python.

Also, fixed a bug in Python resource ref deserialization that I noticed.
2020-12-01 10:58:15 -08:00
Pat Gavlin 2585b86aa4
Initial support for remote component construction. ()
These changes add initial support for the construction of remote
components. For now, this support is limited to the NodeJS SDK;
follow-up changes will implement support for the other SDKs.

Remote components are component resources that are constructed and
managed by plugins rather than by Pulumi programs. In this sense, they
are a bit like cloud resources, and are supported by the same
distribution and plugin loading mechanisms and described by the same
schema system.

The construction of a remote component is initiated by a
`RegisterResourceRequest` with the new `remote` field set to `true`.
When the resource monitor receives such a request, it loads the plugin
that implements the component resource and calls the `Construct`
method added to the resource provider interface as part of these
changes. This method accepts the information necessary to construct the
component and its children: the component's name, type, resource
options, inputs, and input dependencies. It is responsible for
dispatching to the appropriate component factory to create the
component, then returning its URN, resolved output properties, and
output property dependencies. The dependency information is necessary to
support features such as delete-before-replace, which rely on precise
dependency information for custom resources.

These changes also add initial support for more conveniently
implementing resource providers in NodeJS. The interface used to
implement such a provider is similar to the dynamic provider interface
(and may be unified with that interface in the future).

An example of a NodeJS program constructing a remote component resource
also implemented in NodeJS can be found in
`tests/construct_component/nodejs`.

This is the core of .
2020-09-07 19:33:55 -07:00
Justin Van Patten 9abcca345a
Mark internal APIs `@internal` to filter from API docs ()
Also:

 - Cleaned up existing tags so they're consistently at the bottom of doc comments where they should be
 - Cleaned up some unused imports while I was taking a pass over the files
 - Marked one function `@deprecated` that should be deprecated
2020-01-26 09:06:35 -08:00
CyrusNajmabadi 30bacfd8da
Make property internal () 2019-12-18 01:46:29 -08:00
CyrusNajmabadi 342b80b768
Add a supported api for components to indicate that they are asynchronously constructed. () 2019-12-17 15:34:30 -08:00
CyrusNajmabadi 9f00e95e87
Remove unnecessary casts () 2019-10-17 17:12:45 -07:00
CyrusNajmabadi b1f20115cf
Properly handle providers with unknown Ids () 2019-10-16 15:19:43 -07:00
CyrusNajmabadi 91addf2feb
New approach to move us to using `deasync` as little as possible (and with as little impact to users as possible). () 2019-10-14 22:08:06 -07:00
Luke Hoban 893e51d0ce
Add Python resource transformations support ()
Adds Python support for resource transformations aligned with the existing NodeJS support in .

This PR also moves processing of transformations to earlier in the resource construction process (for both NodeJS and Python) to ensure that invariants established in the constructor cannot be violated by transformations. This change can technically be a breaking change, but given that (a) the transformations features was just released in 1.3.0 and (b) the cases where this is a breaking change are uncommon and unlikely to have been reliable anyway - it feels like a change we should make now.

Fixes .
2019-10-14 19:35:00 -05:00
Luke Hoban 9374c374c3
Transformations ()
Adds the ability to provide `transformations` to modify the properties and resource options that will be used for any child resource of a component or stack.

This offers an "escape hatch" to modify the behaviour of a component by peeking behind it's abstraction.  For example, it can be used to add a resource option (`additionalSecretOutputs`, `aliases`, `protect`, etc.) to a specific known child of a component, or to modify some input property to a child resource if the component does not (yet) expose the ability to control that input directly.  It could also be used for more interesting scenarios - such as:
1. Automatically applying tags to all resources that support them in a stack (or component)
2. Injecting real dependencies between stringly-referenced  resources in a Helm Chart 
3. Injecting explicit names using a preferred naming convention across all resources in a stack
4. Injecting `import` onto all resources by doing a lookup into a name=>id mapping

Because this feature makes it possible to peek behind a component abstraction, it must be used with care in cases where the component is versioned independently of the use of transformations.  Also, this can result in "spooky action at a distance", so should be used judiciously.  That said - this can be used as an escape hatch to unblock a wide variety of common use cases without waiting on changes to be made in a component implementation.  

Each transformation is passed the `resource`, `name`, `type`, `props` and `opts` that are passed into the `Resource` constructor for any resource descended from the resource that has the transformation applied.  The transformation callback can optionally return alternate versions of the `props` and `opts` to be used in place of the original values provided to the resource constructor.

Fixes .
2019-09-29 11:27:37 -07:00
CyrusNajmabadi b135af10be
Enable full strict mode. () 2019-09-11 16:21:35 -07:00
CyrusNajmabadi 24e2c6f791
Workaround intermittent issue on some machines where Object.values can't be found. () 2019-08-08 12:11:46 -07:00
CyrusNajmabadi 93f0bd708d
Add helper function for merging ResourceOptions () 2019-07-29 12:01:10 -07:00
Luke Hoban fc38d7d4d9
Handle mixed versions of Resources in parent hierarchy ()
For new properties added to `Resource`, we need to make sure to handle cases where these are undefined as they may not be available on versions of `Resource` that come from older SDK versions, which could me side-by-side in a single Pulumi program execution.

Fixes 
2019-07-16 11:15:26 -07:00
Paul Stack 02ffff8840
Addition of Custom Timeouts ()
* Plumbing the custom timeouts from the engine to the providers

* Plumbing the CustomTimeouts through to the engine and adding test to show this

* Change the provider proto to include individual timeouts

* Plumbing the CustomTimeouts from the engine through to the Provider RPC interface

* Change how the CustomTimeouts are sent across RPC

These errors were spotted in testing. We can now see that the timeout
information is arriving in the RegisterResourceRequest

```
req=&pulumirpc.RegisterResourceRequest{
           Type:                    "aws:s3/bucket:Bucket",
           Name:                    "my-bucket",
           Parent:                  "urn:pulumi:dev::aws-vpc::pulumi:pulumi:Stack::aws-vpc-dev",
           Custom:                  true,
           Object:                  &structpb.Struct{},
           Protect:                 false,
           Dependencies:            nil,
           Provider:                "",
           PropertyDependencies:    {},
           DeleteBeforeReplace:     false,
           Version:                 "",
           IgnoreChanges:           nil,
           AcceptSecrets:           true,
           AdditionalSecretOutputs: nil,
           Aliases:                 nil,
           CustomTimeouts:          &pulumirpc.RegisterResourceRequest_CustomTimeouts{
               Create:               300,
               Update:               400,
               Delete:               500,
               XXX_NoUnkeyedLiteral: struct {}{},
               XXX_unrecognized:     nil,
               XXX_sizecache:        0,
           },
           XXX_NoUnkeyedLiteral: struct {}{},
           XXX_unrecognized:     nil,
           XXX_sizecache:        0,
       }
```

* Changing the design to use strings

* CHANGELOG entry to include the CustomTimeouts work

* Changing custom timeouts to be passed around the engine as converted value

We don't want to pass around strings - the user can provide it but we want
to make the engine aware of the timeout in seconds as a float64
2019-07-16 00:26:28 +03:00
Pat Gavlin e1a52693dc
Add support for importing existing resources. ()
A resource can be imported by setting the `import` property in the
resource options bag when instantiating a resource. In order to
successfully import a resource, its desired configuration (i.e. its
inputs) must not differ from its actual configuration (i.e. its state)
as calculated by the resource's provider.

There are a few interesting state transitions hiding here when importing
a resource:
1. No prior resource exists in the checkpoint file. In this case, the
   resource is simply imported.
2. An external resource exists in the checkpoint file. In this case, the
   resource is imported and the old external state is discarded.
3. A non-external resource exists in the checkpoint file and its ID is
   different from the ID to import. In this case, the new resource is
   imported and the old resource is deleted.
4. A non-external resource exists in the checkpoint file, but the ID is
   the same as the ID to import. In this case, the import ID is ignored
   and the resource is treated as it would be in all cases except for
   changes that would replace the resource. In that case, the step
   generator issues an error that indicates that the import ID should be
   removed: were we to move forward with the replace, the new state of
   the stack would fall under case (3), which is almost certainly not
   what the user intends.

Fixes .
2019-07-12 11:12:01 -07:00
CyrusNajmabadi 867abac947
Make it possible with aliases to say 'I had no parent before' () 2019-06-20 15:53:33 -07:00
CyrusNajmabadi 55d2f82170
Make private field internal () 2019-06-18 10:54:14 -07:00
CyrusNajmabadi 54cbda80c1
Store information about a CustomResource's provider in __providers. () 2019-06-11 16:57:37 -07:00
CyrusNajmabadi 55bb3b2486
Simplify API for passing providers to a ComponentResource. () 2019-06-06 16:20:12 -07:00
Alex Clemmer df5273e549 Add `__pulumiType` to `CustomResource` class
Running `pulumi query` over state resources will require the ability to
filter resources by type.

This commit begins the process of making this possible simply, using the
TypeScript user-defined type guards feature. This commit changes the
`CustomResource` constructor to record the `t` argument in the
`__pulumiType` field, which acts as a "sentinel" value in the resource
base, which deriving classes need only check to ensure they are of that
type. For example:

    aws.s3.Bucket.isInstance(someOb)

would check the `aws.s3.Bucket.__pulumiType` field, and make sure that
the type field lines up.
2019-06-03 14:56:49 -07:00
Luke Hoban 15e924b5cf
Support aliases for renaming, re-typing, or re-parenting resources ()
Adds a new resource option `aliases` which can be used to rename a resource.  When making a breaking change to the name or type of a resource or component, the old name can be added to the list of `aliases` for a resource to ensure that existing resources will be migrated to the new name instead of being deleted and replaced with the new named resource.

There are two key places this change is implemented. 

The first is the step generator in the engine.  When computing whether there is an old version of a registered resource, we now take into account the aliases specified on the registered resource.  That is, we first look up the resource by its new URN in the old state, and then by any aliases provided (in order).  This can allow the resource to be matched as a (potential) update to an existing resource with a different URN.

The second is the core `Resource` constructor in the JavaScript (and soon Python) SDKs.  This change ensures that when a parent resource is aliased, that all children implicitly inherit corresponding aliases.  It is similar to how many other resource options are "inherited" implicitly from the parent.

Four specific scenarios are explicitly tested as part of this PR:
1. Renaming a resource
2. Adopting a resource into a component (as the owner of both component and consumption codebases)
3. Renaming a component instance (as the owner of the consumption codebase without changes to the component)
4. Changing the type of a component (as the owner of the component codebase without changes to the consumption codebase)
4. Combining (1) and (3) to make both changes to a resource at the same time
2019-05-31 23:01:01 -07:00