Commit graph

127 commits

Author SHA1 Message Date
CyrusNajmabadi 3e25bc80c8
Add test with complex output scenarios. (#2118) 2018-10-28 13:02:25 -07:00
CyrusNajmabadi 13d9043771
Produce values like the v8 Inspector does. (#2119) 2018-10-28 01:01:48 -07:00
Joe Duffy 4647aa6cdb
Merge pull request #2114 from pulumi/joeduffy/994_combinators
Add some helpful input/output combinators
2018-10-27 15:41:22 -07:00
joeduffy 930c86cb50 Fix some lint errors 2018-10-27 13:27:04 -07:00
joeduffy 1daad93ccd Add tests for the new combinators 2018-10-27 12:56:16 -07:00
CyrusNajmabadi c83eaf428b
Add a simple test to validate a regex without flags. (#2117) 2018-10-27 00:42:52 -07:00
CyrusNajmabadi 1d7f35352d
Properly serialize certain special JavaScript number values that JSON serialization cannot handle. (#2116) 2018-10-26 23:46:57 -07:00
CyrusNajmabadi 19a313b628
Do not analyze user source code for required packages. We'll analyze their project.json for that. (#1612) 2018-10-18 11:21:47 -07:00
Alex Clemmer 00a22b27f8 Don't unwrap functions
Suppose you have `pulumi.output(o).apply(foo)`, with `o` being type `O`
and `foo` taking type `O` as an argument. If `O` is a type with methods,
this will fail to type check.

The reason is that `UnwrappedObject<T>` (as well as the other
`Unwrapped*` types) will recursively wrap the types of field values
whose type was `Function`. Since `UnwrappedObject<Function>` is not the
same as `Function`, we fail to type check. Note that this does not
result in an actual "boxed" object -- this is purely at the type level.

This commit resolves this by considering `Function` a primitive type,
which will cause us to not wrap the types of field values, instead
leaving them as `Function`.
2018-10-15 14:28:28 -07:00
CyrusNajmabadi 177f0f7ca1
Fix computation of the isKnown bit for an Output (when the apply function returns an Output itself). (#1974) 2018-09-25 21:29:27 -07:00
Sean Gillespie 2d4a3f7a6a
Move management of root resource state to engine (#1944)
* Protobuf changes

* Move management of root resource state to engine

This commit fixes a persistent side-by-side issue in the NodeJS SDK by
moving the management of root resource state to the engine. Doing so
adds two new endpoints to the Engine gRPC service: 1) GetRootResource
and 2) SetRootResource, which get and set the root resource
respectively.

* Rebase against master, regenerate proto
2018-09-18 11:47:34 -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 2bc3eb7507
Log any errors coming from the langhost during tests (#1899) 2018-09-06 16:35:24 -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
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 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
CyrusNajmabadi e05cad9424
Emit export at the end-of-file for factory functions. (#1812) 2018-08-22 12:33:01 -07:00
CyrusNajmabadi b927b5726d
Add support for serializing 'factory' functions. (#1804) 2018-08-21 12:29:30 -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 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
CyrusNajmabadi 152fde0867
Strip off the node_modules prefix from our require() calls. (#1729) 2018-08-07 20:27:02 -04:00
Matt Ellis 153729683a Allow eliding name in pulumi.Config .ctor
When this argument is not provided, we'll default to the value of
pulumi.getProject(). This is what you want for application level code
anyway and it matches the CLI behavior where if you don't qualify a
key with a package we use the name of the current project.

Fixes #1581
2018-08-06 16:03:54 -07:00
Matt Ellis 5eb78af779 Do not lazy initialize config or settings
The pulumi runtime used to lazily load and parse both config and
settings data set by the language host. The initial reason for this
design was that we wanted the runtime to be usable in a normal node
environment, but we have moved away from supporting that.

In addition, while we claimed we loaded these value "lazily", we
actually forced their loading quite eagerly when we started
up. However, when capturing config (or settings, as we now do), we
would capture all the logic about loading these values from the
environment.

Even worse, in the case where you had two copies of @pulumi/pulumi
loaded, it would be possible to capture a config object which was not
initialized and then at runtime the initialization logic would try to
read PULUMI_CONFIG from the process environment and fail.

So we adopt a new model where configuration and settings are parsed as
we load their containing modules. In addition, to support SxS
scinerios, we continue to use `process.env` as a way to control both
configuration and settings. This means that `run.ts` must now ensure
that these values are present in the environment before either the
config or runtime modules have been loaded.
2018-08-06 15:53:38 -07:00
CyrusNajmabadi c57aef785b
Ensure we can capture non-built-in modules with 'require'. (#1685) 2018-08-02 16:25:49 -04:00
CyrusNajmabadi d19942f2b0
Go back to capturing *non-user* modules by 'require' reference. (#1655) 2018-07-31 11:37:46 -04:00
CyrusNajmabadi 48df5bfe1e
Update pulumi/pulumi to run on Nodejs v10. (#1658) 2018-07-25 16:55:20 -07:00
CyrusNajmabadi 4cebc381ae
Do a better job preventing serialization of unnecessary objects in closure serialization (#1543) 2018-06-20 12:57:57 -07:00
Luke Hoban 076d8887c9
Compute required packages during closure serialization (#1457)
Closure serialization now keeps track of the `require`d packages it sees in the function bodies that are serialized during a call to `serializeFunction`.

Also, replaces `serializeFunctionAsync` with `serializeFunction` which accepts richer parameters and return type, deprecating the former API (but leaving it available for now to avoid a breaking change).
2018-06-03 21:55:37 -07:00
Sean Gillespie 38cf2de39e
Issue a better error message if you capture a V8 intrinsic (#1423) 2018-05-24 11:54:31 -07:00
Pat Gavlin a2c30f75ed
Resolve missing outputs as undefined. (#1427)
Before the changes in #1414, all output properties were guaranteed to
have values after deserialization. After #1414, any properties with no
value were no longer resolved, which was treated as an error. These
changes resolve all missing proprties to `undefined`. If a property is
missing during an update, its `undefined` value is marked as known.
2018-05-24 11:22:08 -07:00
Pat Gavlin a16a880518
Discriminate unknown values in the JS runtime. (#1414)
These changes add support for distinguishing an output property with
an unknown value from an output property with a known value that is
undefined.

In a broad sense, the Pulumi property type system is just JSON with the
addition of unknown values. Notably absent, however, are undefined
values. As it stands, our marshalers between JavaScript and Pulumi
property values treat all undefined JavaScript values as unknown Pulumi
values. Unfortunately, this conflates two very different concepts:
unknown Pulumi values are intended to represent values of output
properties that are unknown at time of preview, _not_ values that are
known but undefined. This results in difficulty reasoning about when
transforms are run on output properties as well as confusing output in
the `diff` view of Pulumi preview (user-specifed undefined values are
rendered as unknown values).

As it turns out, we already have a way to decide whether or not an
Output value is known or not: Output.performApply. These changes rename
this property to `isKnown`, clarify its meaning, and take advantage of
the result to decide whether or not an Output value should marshal as
an unknown Pulumi value.

This also allowed these changes to improve the serialization of
undefined object keys and array elements s.t. we better match JavaScript
to JSON serialization behavior (undefined object keys are omitted;
undefined array elements are marshaled as `null`).

Fixes https://github.com/pulumi/pulumi-cloud/issues/483.
2018-05-23 14:47:40 -07:00
joeduffy 5967259795 Add license headers 2018-05-22 15:02:47 -07:00
Sean Gillespie 82ac202139
Improve the promise leak experience (#1374)
* Fix a bug in promise leak detection that leaked promises when errors occur

* Add an opt-in to the super-verbose debug error message on promise leaks

* Fix a bad merge

* was/were grammar improvement in error message

* Fail the deployment if a debuggable promise leaks
2018-05-17 15:32:39 -07:00
CyrusNajmabadi 4807de038c
Capture 'exports' if referenced in user code. (#1359) 2018-05-11 16:35:41 -07:00
CyrusNajmabadi 6de1cead5a
Fix issue where we were not properly serializing out the prototype for an object. (#1352) 2018-05-11 15:53:16 -07:00
CyrusNajmabadi 5387e78cfa
Support async function serialization. (#1311) 2018-05-03 12:25:52 -07:00
Matt Ellis 409477b951 Invoke node directly from the language host
Instead of using a shell script to jump from the language host into
node, just invoke node directly. This makes our start-up path a little
simpler to understand and indirectly fixes pulumi/home#156, where we
would fail on Windows if the `-exec` script was in a folder that had
spaces in it (due to a subtle interaction between how go launches cmd
files and how cmd.exe parses arguments).
2018-05-02 11:16:58 -07:00
Pat Gavlin 16f1930069
Pass "special" properties to Invoke. (#1277)
Rather than filtering out the `id` and `urn` properties when serializing
the inputs to an invoke, pass these properties along. This enables the
use of invoke endpoints that accepts these as inputs (e.g. the endpoint
that backs `aws.ec2.getSubnet`).
2018-05-01 15:05:42 -07:00
joeduffy 6f4423895c Don't use instanceof for RTTI
This change moves us away from using JavaScript RTTI, by way of
`instanceof`, for built-in Pulumi types.  If we use `instanceof`,
then the same logical type loaded from separate copies of the
SDK package -- as will happen in SxS scenarios -- are considered
different.  This isn't actually what we want.  The solution is
simple: implement our own quasi-RTTI solution, using __pulumi*
properties and manual as* and is* functions.  Note that we could
have skipped the as* and is* functions, but I found that they led
to slightly easier to read code.

There is one strange thing in here, which I spoke to
@CyrusNajmabadi about: SerializedOutput<T>, because it implements
Output<T> as an _interface_, did not previously masquerade as an
actual Output<T>.  In other words, `instanceof` would have returned
false, and indeed a few important properties (like promise) are
missing.  This change preserves that behavior, although I'll admit
that this is slightly odd.  I suspect we'll want to revisit this as
part of https://github.com/pulumi/pulumi/issues/1074.

Fixes https://github.com/pulumi/pulumi/issues/1203.
2018-04-16 14:08:10 -07:00
Sean Gillespie 1f5be5f8cd
Bring the magic of Pulumi to Node v8.11.1, v9.11.1, v6.10.3 (#1167)
* Introduce a simple repetition operator to match expected error messages against actual ones

* Convert required and optional objects to use a Map (node v9 compat), improve the error formatting for failed tests

* Test node v6, v8, and v9 in CI

* Get rid of PULUMI_API env in .travis.yml, it's set from the Travis console now
2018-04-14 11:50:01 -07:00
Joe Duffy 150f57168a
Fix SxS config (#1175)
We weren't properly lazily loading everywhere we need to.
2018-04-13 11:26:01 -07:00
CyrusNajmabadi 97c1344035
Disallow capturing 'this' inside a lambda (#1138) 2018-04-09 15:57:39 -07:00
Joe Duffy 62042cd3ed
Simplify resource lookup (#1133)
As I began to write code using the ability to perform resource
lookups, especially in the code-generators, I realized the way it
was surfaced as an argument to the Resource base constructor would
lead to overload explosion.  Instead of doing that, let's pass it
in the ResourceOptions bag.
2018-04-07 10:15:58 -07:00