Commit graph

137 commits

Author SHA1 Message Date
Pat Gavlin 35c60d61eb
Follow up on #2369 (#2397)
- Add support for per-property dependencies to the Go SDK
- Add tests for first-class secret rejection in the checkpoint and RPC
  layers and language SDKs
2019-01-28 17:38:16 -08:00
Pat Gavlin 1ecdc83a33 Implement more precise delete-before-replace semantics. (#2369)
This implements the new algorithm for deciding which resources must be
deleted due to a delete-before-replace operation.

We need to compute the set of resources that may be replaced by a
change to the resource under consideration. We do this by taking the
complete set of transitive dependents on the resource under
consideration and removing any resources that would not be replaced by
changes to their dependencies. We determine whether or not a resource
may be replaced by substituting unknowns for input properties that may
change due to deletion of the resources their value depends on and
calling the resource provider's Diff method.

This is perhaps clearer when described by example. Consider the
following dependency graph:

  A
__|__
B   C
|  _|_
D  E F

In this graph, all of B, C, D, E, and F transitively depend on A. It may
be the case, however, that changes to the specific properties of any of
those resources R that would occur if a resource on the path to A were
deleted and recreated may not cause R to be replaced. For example, the
edge from B to A may be a simple dependsOn edge such that a change to
B does not actually influence any of B's input properties. In that case,
neither B nor D would need to be deleted before A could be deleted.

In order to make the above algorithm a reality, the resource monitor
interface has been updated to include a map that associates an input
property key with the list of resources that input property depends on.
Older clients of the resource monitor will leave this map empty, in
which case all input properties will be treated as depending on all
dependencies of the resource. This is probably overly conservative, but
it is less conservative than what we currently implement, and is
certainly correct.
2019-01-28 09:46:30 -08:00
CyrusNajmabadi bfcb07a164
Add functions to help make strings from values that may include Outputs (#2359) 2019-01-16 11:03:25 -08:00
CyrusNajmabadi 7e7544e27e
Revert https://github.com/pulumi/pulumi/pull/2281 (#2297) 2018-12-15 21:04:53 -08:00
CyrusNajmabadi 05f5311055
Prevent cycles when serializing props. (#2281) 2018-12-10 14:31:54 -08:00
Pat Gavlin 663e5342b0
Inherit custom resource providers (#2264)
If a custom resource has explicitly specified a provider, add that
provider to the resource's provider map under the resource's package.
This allows children of the custom resource to inherit the resource's
provider.

Fixes #2262.
2018-12-05 12:35:19 -08:00
Joe Duffy a337fd7379
Permit dependsOn that are Outputs (of Outputs) (#2198)
This changes the input type for dependsOn from simply
`Resource[] | Resource` to `Input<Input<Resource>[]> | Input<Resource>`.
This permits `Output<Resource>`s, etc in addition to
`Promise<Resource>`s. The logic for dynamically unpicking the right
types and recursing through the data structures isn't straightforward,
but I've written a test for all of the interesting permutations.

This fixes pulumi/pulumi#991.
2018-11-19 11:22:55 -05:00
CyrusNajmabadi cea165615e
Reenable tests. (#2200) 2018-11-13 17:13:27 -08:00
Pat Gavlin 170541546e
Disable the config capture tests (#2183)
These tests fail non-deterministically.
2018-11-08 17:45:51 -08:00
CyrusNajmabadi 901a238fd5
Get closure serialiation working in Node11 (#2101)
* Make v8 primitives async as there is no way to avoid async in node11.

* Simplify API.

* Move processing of well-known globals into the v8 layer.
We'll need this so that we can map from RemoteObjectIds back to these well known values.

* Remove unnecesssary check.

* Cleanup comments and extract helper.

* Introduce helper bridge method for the simple case of making an entry for a string.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Move property access behind helpers so they can move to the Inspector API in the future.

* Only call function when we know we have a Function.  Remove redundant null check.

* Properly serialize certain special JavaScript number values that JSON serialization cannot handle.

* Only marshall across the 'source' and 'flags' for a RegExp when serializing.

* Add a simple test to validate a regex without flags.

* Extract functionality into helper method.

* Add test with complex output scenarios.

* Output serialization needs to avoid recursively trying to serialize a serialized value.

* Introduce indirection for introspecting properties of an object.

* Use our own introspection API for examining an Array.

* Hide direct property access through API indirection.

* Produce values like the v8 Inspector does.

* Compute the module map asynchronously.  Will need that when mapping mirrors instead.

* Cleanup a little code in closure creation.

* Get serialization working on Node11 (except function locations).

* Run tests in the same order on <v11 and >=v11

* Make tests run on multiple versions of node.

* Rename file to make PR simpler to review.

* Cleanup.

* Be more careful with global state.

* Remove commented line.

* Only allow getting a session when on Node11 or above.

* Promisify methods.
2018-11-01 15:46:21 -07:00
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