Commit graph

471 commits

Author SHA1 Message Date
Sean Gillespie f284112b4e
Use nightly protoc gRPC plugin for node (#1948)
* Use nightly protoc gRPC plugin for Node

Newer versions of the Node gRPC plugin accept the 'minimum_node_version'
flag, which we can use to instruct protoc to not support Node versions
earlier than Node 6. This allows the compiler to use 'Buffer.from'
instead of the deprecated 'Buffer' constructor, which fixes a
deprecation warning on Node 10.

* Protobuf changes
2018-09-17 15:16:31 -07:00
CyrusNajmabadi 937391259e
Update linter version. (#1946) 2018-09-15 02:59:01 -07:00
Pat Gavlin d67e04247f
Fix a few dynamic provider issues. (#1935)
- Do not require replacement of dynamic resources due to provider
  changes. This is not necessary, and is almost certainly the wrong
  thing to do if the dynamic provider is managing a physical resource.

- Return all inputs by default from a dynamic provider's check method.
  Currently a dynamic provider that does not implement check will end up
  receiving no inputs. This is confusing, and is not the correct default.
2018-09-14 19:59:06 -07:00
Thomas Schersach c01023737e Copy missing pulumi-resource-pulumi-nodejs binary in node lang host dist target 2018-09-13 11:18:06 -07:00
CyrusNajmabadi 1b0780afda
Don't unwrap resources when producing an output. (#1923) 2018-09-11 21:49:36 -07:00
CyrusNajmabadi ba7be6a6dd
Update docts. (#1922) 2018-09-11 21:17:52 -07:00
CyrusNajmabadi 13800a89a0
Produce a strongly-typed 'unwrap' function to help with deep unwrapping of Input values. (#1915) 2018-09-11 19:38:45 -07:00
Sean Gillespie 559e1625df
Combine two gRPC servers into one for testing (#1918)
* Combine two gRPC servers into one for testing

For some reason, our current gRPC test setup has become flaky now that
we are spinning up two gRPC servers. Hopefully merging them into one
helps clarify what's going on.

* Add back error logging for CI
2018-09-11 15:45:15 -07:00
Sean Gillespie 679f55c355
Validate type tokens before using them (#1904)
* Validate type tokens before using them

When registering or reading a resource, we take the type token given to
us from the language host and assume that it's valid, which resulted in
assertion failures in various places in the engine. This commit
validates the format of type tokens given to us from the language host
and issues an appropriate error if it's not valid.

Along the way, this commit also improves the way that fatal exceptions
are rendered in the Node language host.

* Pre-allocate an exception for ReadResource

* Fix integration test

* CR Feedback

This commit is a lower-impact change that fixes the bugs associated with
invalid types on component resources and only checks that a type is
valid on custom resources.

* CR Take 2: Fix up IsProviderType instead of fixing call sites

* Please gometalinter
2018-09-07 15:19:18 -07:00
Matt Ellis 91827752d5 Use require.resolve to find @pulumi/pulumi/cmd/run
Instead of trying to probe for the normal path ourselves, just use
node's `require.resolve` statement to find `@pulumi/pulumi/cmd/run`.

This allows run to be found in cases where either yarn workspaces are
used, or the module has been installed globally.

Part of #1868
2018-09-07 11:30:54 -07:00
Pat Gavlin d243b49193
Make opts.providers robust to SxS scenarios. (#1901)
`opts.providers` is currently only read by the `Resource` constructor if
either `opts.parent` or `getRootResource` is not `undefined`. In
scnearios where exactly one copy of `@pulumi/pulumi` is loaded, one of
these conditions will always be true. In SxS scenarios, however, it is
possible for neither of these conditions to be true, and the created
resource will end up without a `providers` map. These changes fix that
by always copying the contents of `opts.providers` if it is defined.
2018-09-07 09:42:19 -07:00
Sean Gillespie 2bc3eb7507
Log any errors coming from the langhost during tests (#1899) 2018-09-06 16:35:24 -07:00
CyrusNajmabadi 0d6acebecd
Be resilient to encountering invalid data in a package.json file. (#1897) 2018-09-06 16:35:14 -07:00
Sean Gillespie 9acafcfe11
Don't call process.exit in exit callback (#1892)
Node calls 'exit' event callbacks when a process is preparing to exit,
via process.exit or otherwise, but it does not execute the next callback
in the chain if a callback calls process.exit.
2018-09-06 10:52:05 -07:00
Mikhail Shilkov 30fccc0773 computeCodePath won't find modules in an organization on Windows (#1889) 2018-09-05 22:07:21 -07:00
CyrusNajmabadi 193af7bda8
Simpler way of stating which dependencies need to be available at runtime. (#1890) 2018-09-05 16:18:31 -07:00
CyrusNajmabadi 9d0dc65f49
Provide helper to compute whihc sub-packages should be included even if we would exclude a higher package. (#1883) 2018-09-05 12:54:28 -07:00
CyrusNajmabadi ddd83fafc4
Support serializing regex instances. (#1870) 2018-09-03 23:14:00 -07:00
Joe Duffy 35b78abcf4
Merge pull request #1866 from pulumi/joeduffy/1611_allow_promise_exports
Allow promise exports
2018-09-02 13:50:08 -07:00
joeduffy fb6c0a43f5 Use serializeProperties, not serializeResourceProperties 2018-09-02 13:20:59 -07:00
joeduffy 70e1dbfe19 Incorporate PR feedback
* Use Promise.resolve.

* Use `Inputs | Promise<Inputs> | Output<Inputs>` rather than
  `Input<Inputs>`, which looks supremely bizarre.

* Update ComponentResource.registerOutputs also.
2018-09-02 12:15:58 -07:00
joeduffy 44c17e4877 Allow promise exports
This change partly addresses pulumi/pulumi#1611, by permitting you
to export a promise at the top-level, and have it be recognized as
a stack output. In other words, you can now say things like

    async function main() {
        ...
        return {
            a: "x",
            ...,
            z: 42,
        };
    }

    module.exports = main();

and your Pulumi program will record distinct outputs as you'd hope:

    ---outputs:---
    a: "x"
    ...
    z: 42

This is arguably just a bug in the way we implemented stack outputs.
The remainder of the requests in #1611 will remain open for future
design and discussion, as they have more subtle ramifications.
2018-09-02 10:41:04 -07:00
Joe Duffy 143d548b35
Merge pull request #1857 from pulumi/ellismg/fix-1772
Fix a "hang" when `tsconfig.json` is not present in the CWD
2018-09-02 08:49:06 -07:00
Alex Clemmer 3cc04a6f75 LogRequest.isStatus -> LogRequest.ephemeral 2018-08-31 15:56:53 -07:00
Matt Ellis aaf7c09384 Fix a "hang" when tsconfig.json is not present in the CWD
If a `tsconfig.json` file is not present at the root of the Pulumi
project, ts-node will look up the directory tree to see if there is
one. If there is, it will treat that as the root of the project. While
reasonable for some cases, this isn't the behavior we want for our use
of ts-node. We actually set compiler options such that in the common
case you don't even need a `tsconfig.json` and for pure JavaScript
projects, there wouldn't be a `tsconfig.json` file.

In both of these cases, there's a big foot-gun waiting. For example in
pulumi/pulumi#1772 we ran into a case where there was a tsconfig.json
file in $HOME, causing the entirety of $HOME to be analyzed by
TypeScript which made it look like Pulumi hung.

To address this, tell ts-node to not use a project in cases where
there is not a `tsconfig.json` at the root of the project.

Fixes #1772
2018-08-31 11:57:14 -07:00
Alex Clemmer 665b219a0e Allow log events to be marked "status" events
This commit will introduce a field, `IsStatus` to `LogRequest`. A
"status" logging event will be displayed in the `Info` column of the
main display, but will not be printed out at the end, when resource
operations complete.

For example, for complex resource initialization, we'd like to display a
series of intermediate results: `[1/4] Service object created`, for
example. We'd like these to appear in the `Info` column, but not at the
end, where they are not helpful to the user.
2018-08-30 17:17:20 -07:00
joeduffy 6883d08796 Fix a comment mistake 2018-08-29 11:29:18 -07:00
Joe Duffy f8d0ff87fd
Merge pull request #1834 from pulumi/joeduffy/1671_more_config_types
Add more config helpers
2018-08-28 21:57:34 -07:00
joeduffy c2258be408 Adopt code review feedback for config constraints
This change adopts the code review suggestion to use a bag of options
for config constraints rather than having overloaded function names.
This is a much cleaner approach, lets us use more descriptive names,
and is far more future proof in case we decide to add more capabilities.
2018-08-28 18:07:26 -07:00
joeduffy 834987bcd3 Add more config helpers
Everytime I convert a CloudFormation template to Pulumi, I inevitably
run into the fact that CloudFormation has advanced "schema" capabilities
for input variables, like min/max for numbers and string lengths, enums,
and regex pattern matching. This is always cumbersome to convert.

In this change, I've added a number of config helpers for these cases:

For string enums:

    getEnum(key: string, values: string[]): string | undefined;
    requireEnum(key: string: values: string[]): string;

For min/max strlen:

    getMinMax(key: string, min: number, max: number): string | undefined;
    requireMinMax(key: string, min: number, max: number): string;

For regex patterns:

    getPattern(key: string, regexp: string | RegExp): string | undefined;
    requirePattern(key: string, regexp: string | RegExp): string;

For min/max strlen _and_ regex patterns:

    getMinMaxPattern(key: string, min: number, max: number,
        regexp: string | RegExp): string | undefined;
    requireMinMaxPattern(key: string, min: number, max: number,
        regexp: string | RegExp): string;

For min/max numbers:

    getNumberMinMax(key: string, min: number, max: number): number | undefined;
    requireNumberMinMax(key: string, min: number, max: number): number;

Each function throws a detailed RunError-derived exception type if the
configuration value doesn't meet the constraint.

This fixes pulumi/pulumi#1671.
2018-08-28 13:22:53 -07:00
CyrusNajmabadi f4e04e4a5d
Add test to demonstrate issue is fixed. (#1829) 2018-08-27 14:25:37 -07:00
Sean Gillespie a0cf415179
Fix an issue with NodeJS host logging (#1819)
* Fix an issue with NodeJS host logging

Related to pulumi/pulumi#1694. This issue prevented the language host
from being aware that an engine (logging endpoint) was available and
thus no log messages were sent to the engine. By default, the language
host wrote them to standard out instead, which resulted in a pretty bad
error experience.

This commit fixes the PR and adds machinery to the NodeJS langhost tests
for testing the engine RPC endpoint. It is now possible to give a "log"
function to tests which will be hooked up to the "log" RPC endpoint
normally provided by the Pulumi engine.

* Remove accidental console.log
2018-08-24 16:50:09 -07:00
Pat Gavlin 73f4f2c464
Reimplement refresh. (#1814)
Replace the Source-based implementation of refresh with a phase that
runs as the first part of plan execution and rewrites the snapshot in-memory.

In order to fit neatly within the existing framework for resource operations,
these changes introduce a new kind of step, RefreshStep, to represent
refreshes. RefreshSteps operate similar to ReadSteps but do not imply that
the resource being read is not managed by Pulumi.

In addition to the refresh reimplementation, these changes incorporate those
from #1394 to run refresh in the integration test framework.

Fixes #1598.
Fixes pulumi/pulumi-terraform#165.
Contributes to #1449.
2018-08-22 17:52:46 -07:00
CyrusNajmabadi e05cad9424
Emit export at the end-of-file for factory functions. (#1812) 2018-08-22 12:33:01 -07:00
CyrusNajmabadi 4dab630a1b
Fix issue where we were sometimes filtering out certain node modules innapropriately. (#1807) 2018-08-21 15:35:37 -07:00
CyrusNajmabadi 8aed774f09
Properly capture modules that are in a non-local node_modules path. (#1803) 2018-08-21 12:43:52 -07:00
CyrusNajmabadi b927b5726d
Add support for serializing 'factory' functions. (#1804) 2018-08-21 12:29:30 -07:00
Matt Ellis c924c18d2c Do not make errors during plugin discovery fatal
The plugin host can ask the language host to provide a list of
resource plugins that it thinks will be nessecary for use at
deployment time, so they can be eagerly loaded.

In NodeJS (the only language host that implements this RPC) This works
by walking the directory tree rooted at the CWD of the project,
looking for package.json files, parsing them and seeing it they have
some marker property set. If they do, we add information about them
which we return at the end of our walk.

If there is *any* error, the entire operation fails. We've seen a
bunch of cases where this happens:

- Broken symlinks written by some editors as part of autosave.
- Access denied errors when part of the tree is unwalkable (Eric ran
  into this on Windows when he had a Pulumi program at the root of his
  file system.
- Recusive symlinks leading to errors when trying to walk down the
  infinite chain. (See #1634 for one such example).

The very frustrating thing about this is that when you hit an error
its not clear what is going on and fixing it can be non-trivial. Even
worse, in the normal case, all of these plugins are already installed
and could be loaded by the host (in the common case, plugins are
installed as a post install step when you run `npm install`) so if we
simply didn't do this check at all, things would work great.

This change does two things:

1. It does not stop at the first error we hit when discovering
   plugins, instead we just record the error and continue.

2. Does not fail the overall operation if there was an error. Instead,
   we return to the host what we have, which may be an incomplete view
   of the world. We glog the errors we did discover for diagnostics if
   we ever need them.

I believe that long term most of this code gets deleted anyway. I
expect we will move to a model long term where the engine faults in
the plugin (downloading it if needed) when a request for the plugin
arrives. But for now, we shouldn't block normal operations just
because we couldn't answer a question with full fidelity.

Fixes #1478
2018-08-20 15:39:39 -07:00
Cyrus Najmabadi bee8bb8a78 Add a provider-level check as well to ensure we don't add the same file multiple times. 2018-08-16 13:12:56 -07:00
Cyrus Najmabadi 57a404d4cc Revert "Add a provider-level check as well to ensure we don't add the same file multiple times. (#1784)"
This reverts commit f6cab57909.
2018-08-16 13:06:50 -07:00
CyrusNajmabadi f6cab57909
Add a provider-level check as well to ensure we don't add the same file multiple times. (#1784) 2018-08-16 10:41:54 -07:00
Thomas Schersach 3224cdfcec Use go env to resolve GOPATH but escape it properly 2018-08-13 10:54:20 -07:00
Thomas Schersach a254c05271 Fix gopath resolution in python makefile dist target 2018-08-13 10:54:20 -07:00
Pat Gavlin 58a75cbbf4
Pull default options from a resource's parent. (#1748)
If a resource's options bag does not specify `protect` or `provider`,
pull a default value from the resource's parent.

In order to allow a parent resource to specify providers for multiple
resource types, component resources now accept an optional map from
package name to provider instance. When a custom resource needs a
default provider from its parent, it checks its parent provider bag for
an entry under its package. If a component resource does not have a
provider bag, its pulls a default from its parent.

These changes also add a `parent` field to `InvokeOptions` s.t. calls to
invoke can use the same behavior as resource creation w.r.t. providers.

Fixes #1735, #1736.
2018-08-10 16:18:21 -07:00
Matt Ellis 84ac039661 Also copy python helper script during make dist
During Code Review, I forgot that for the python language host we need
both the go binary and the -exec script.
2018-08-08 20:51:02 -07:00
Matt Ellis c8b1872332
Merge pull request #1698 from pulumi/ellismg/fix-1581
Allow eliding name in pulumi.Config .ctor
2018-08-08 14:16:20 -07:00
Thomas Schersach 62463ab3bc Added dist target for make, will help with Homebrew (#1731)
* Added dist target for make, will help with Homebrew

* Try to install go dependencies before building

* Make sure dep ensure is called before trying to build SDKs

* Removed dep ensure from dist initial step
2018-08-08 13:00:42 -07:00
CyrusNajmabadi 152fde0867
Strip off the node_modules prefix from our require() calls. (#1729) 2018-08-07 20:27:02 -04:00
Pat Gavlin 7da3ba3e38
Expose the InvokeOptions type in the Node SDK. (#1724) 2018-08-07 13:14:16 -07:00
Pat Gavlin a222705143
Implement first-class providers. (#1695)
### First-Class Providers
These changes implement support for first-class providers. First-class
providers are provider plugins that are exposed as resources via the
Pulumi programming model so that they may be explicitly and multiply
instantiated. Each instance of a provider resource may be configured
differently, and configuration parameters may be source from the
outputs of other resources.

### Provider Plugin Changes
In order to accommodate the need to verify and diff provider
configuration and configure providers without complete configuration
information, these changes adjust the high-level provider plugin
interface. Two new methods for validating a provider's configuration
and diffing changes to the same have been added (`CheckConfig` and
`DiffConfig`, respectively), and the type of the configuration bag
accepted by `Configure` has been changed to a `PropertyMap`.

These changes have not yet been reflected in the provider plugin gRPC
interface. We will do this in a set of follow-up changes. Until then,
these methods are implemented by adapters:
- `CheckConfig` validates that all configuration parameters are string
  or unknown properties. This is necessary because existing plugins
  only accept string-typed configuration values.
- `DiffConfig` either returns "never replace" if all configuration
  values are known or "must replace" if any configuration value is
  unknown. The justification for this behavior is given
  [here](https://github.com/pulumi/pulumi/pull/1695/files#diff-a6cd5c7f337665f5bb22e92ca5f07537R106)
- `Configure` converts the config bag to a legacy config map and
  configures the provider plugin if all config values are known. If any
  config value is unknown, the underlying plugin is not configured and
  the provider may only perform `Check`, `Read`, and `Invoke`, all of
  which return empty results. We justify this behavior becuase it is
  only possible during a preview and provides the best experience we
  can manage with the existing gRPC interface.

### Resource Model Changes
Providers are now exposed as resources that participate in a stack's
dependency graph. Like other resources, they are explicitly created,
may have multiple instances, and may have dependencies on other
resources. Providers are referred to using provider references, which
are a combination of the provider's URN and its ID. This design
addresses the need during a preview to refer to providers that have not
yet been physically created and therefore have no ID.

All custom resources that are not themselves providers must specify a
single provider via a provider reference. The named provider will be
used to manage that resource's CRUD operations. If a resource's
provider reference changes, the resource must be replaced. Though its
URN is not present in the resource's dependency list, the provider
should be treated as a dependency of the resource when topologically
sorting the dependency graph.

Finally, `Invoke` operations must now specify a provider to use for the
invocation via a provider reference.

### Engine Changes
First-class providers support requires a few changes to the engine:
- The engine must have some way to map from provider references to
  provider plugins. It must be possible to add providers from a stack's
  checkpoint to this map and to register new/updated providers during
  the execution of a plan in response to CRUD operations on provider
  resources.
- In order to support updating existing stacks using existing Pulumi
  programs that may not explicitly instantiate providers, the engine
  must be able to manage the "default" providers for each package
  referenced by a checkpoint or Pulumi program. The configuration for
  a "default" provider is taken from the stack's configuration data.

The former need is addressed by adding a provider registry type that is
responsible for managing all of the plugins required by a plan. In
addition to loading plugins froma checkpoint and providing the ability
to map from a provider reference to a provider plugin, this type serves
as the provider plugin for providers themselves (i.e. it is the
"provider provider").

The latter need is solved via two relatively self-contained changes to
plan setup and the eval source.

During plan setup, the old checkpoint is scanned for custom resources
that do not have a provider reference in order to compute the set of
packages that require a default provider. Once this set has been
computed, the required default provider definitions are conjured and
prepended to the checkpoint's resource list. Each resource that
requires a default provider is then updated to refer to the default
provider for its package.

While an eval source is running, each custom resource registration,
resource read, and invoke that does not name a provider is trapped
before being returned by the source iterator. If no default provider
for the appropriate package has been registered, the eval source
synthesizes an appropriate registration, waits for it to complete, and
records the registered provider's reference. This reference is injected
into the original request, which is then processed as usual. If a
default provider was already registered, the recorded reference is
used and no new registration occurs.

### SDK Changes
These changes only expose first-class providers from the Node.JS SDK.
- A new abstract class, `ProviderResource`, can be subclassed and used
  to instantiate first-class providers.
- A new field in `ResourceOptions`, `provider`, can be used to supply
  a particular provider instance to manage a `CustomResource`'s CRUD
  operations.
- A new type, `InvokeOptions`, can be used to specify options that
  control the behavior of a call to `pulumi.runtime.invoke`. This type
  includes a `provider` field that is analogous to
  `ResourceOptions.provider`.
2018-08-06 17:50:29 -07:00