Commit graph

2883 commits

Author SHA1 Message Date
Pat Gavlin 5513f08669
Do not call Read in read steps with unknown IDs. (#1734)
This is consistent with the behavior prior to the introduction of Read
steps. In order to avoid a breaking change we must do this check in the
engine itself, which causes a bit of a layering violation: because IDs
are marshaled as raw strings rather than PropertyValues, the engine must
check against the marshaled form of an unknown directly (i.e.
`plugin.UnknownStringValue`).
2018-08-08 12:06:20 -07:00
CyrusNajmabadi b682777a1f
Don't print out unchanged assets while diffing an archive. (#1730) 2018-08-08 01:10:30 -04:00
Matt Ellis d5e3e8fe9e Move git related warnings back to glog statements
In #1341 we promoted a class of errors in fetching git metadata from
glog messages to warnings printed by the CLI. On the asumption that
when we got warnings here they would be actionable.

The major impact here is that when you are working in a repository
which does not have a remote set to GitHub (common if you have just
`git init`'d a repository for a new project) or you don't call your
remote `origin` or you use some other code provider, we end up
printing a warning during every update.

This change does two things:

- Restructure the way we detect metadata to attempt to make progress
  when it can. We bias towards returning some metadata even when we
  can't determine the complete set of metadata.
- Use a multierror to track all the underlying failures from our
  metadata probing and move it back to a glog message.

Overall, this feels like the right balance to me. We are retaining the
rich diagnostics information for when things go wrong, but we aren't
warning about common cases.

We could, of course, try to tighten our huristics (e.g. don't warn if
we can't find a GitHub remote but do warn if we can't compute if the
worktree is dirty) but it feels like that will be a game of
whack-a-mole over time and when warnings do fire its unlikely they
will be actionable.

Fixes #1443
2018-08-07 18:10:34 -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
Sean Gillespie c82141030d Report initialization errors as warnings during previews as well as updates 2018-08-07 12:02:52 -07:00
Pat Gavlin 94802f5c16
Fix deletes with duplicate URNs. (#1716)
When calculating deletes, we will only issue a single delete step for a
particular URN. This is incorrect in the presence of pending deletes
that share URNs with a live resource if the pending deletes follow the
live resource in the checkpoint: instead of issuing a delete for
every resource with a particular URN, we will only issue deletes for
the pending deletes.

Before first-class providers, this was mostly benigin: any remaining
resources could be deleted by re-running the destroy. With the
first-class provider changes, however, the provider for the undeleted
resources will be deleted, leaving the checkpoint in an invalid state.

These changes fix this issue by allowing the step generator to issue
multiple deletes for a single URN and add a test for this scenario.
2018-08-07 11:01:08 -07:00
Chris Smith 254c83f788
Expand ErrorResponse type (#1720) 2018-08-07 10:43:18 -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
Sean Gillespie 0d0129e400
Execute non-delete step chains in parallel (#1673)
* Execute chains of steps in parallel

Fixes pulumi/pulumi#1624. Since register resource steps are known to be
ready to execute the moment the engine sees them, we can effectively
parallelize all incoming step chains. This commit adds the machinery
necessary to do so - namely a step executor and a plan executor.

* Remove dead code

* CR: use atomic.Value to be explicit about what values are atomically loaded and stored

* CR: Initialize atomics to 'false'

* Add locks around data structures in event callbacks

* CR: Add DegreeOfParallelism method on Options and add comment on select in Execute

* CR: Use context.Context for cancellation instead of cancel.Source

* CR: improve cancellation

* Rebase against master: execute read steps in parallel

* Please gometalinter

* CR: Inline a few methods in stepExecutor

* CR: Feedback and bug fixes

1. Simplify step_executor.go by 'bubbling' up errors as far as possible
and reporting diagnostics and cancellation in one place
2. Fix a bug where the CLI claimed that a plan was cancelled even if it
wasn't (it just has an error)

* Comments

* CR: Add comment around problematic select, move workers.Add outside of goroutine, return instead of break
2018-08-06 16:46:17 -07:00
Matt Ellis 7b2a623ee8
Merge pull request #1569 from pulumi/ellismg/add-typescript-support
Support TypeScript in a more first-class way
2018-08-06 14:34:53 -07:00
Matt Ellis 645ca2eb56 Allow more types for runtimeOptions
Instead of just allowing booleans, type the map as string->interface{}
so in the future we could pass string or number options to the
language host.
2018-08-06 14:00:58 -07:00
Matt Ellis 2a8a54a24b Remove need for tsconfig.json
Set the following compiler defaults:

```
       "target": "es6",
       "module": "commonjs",
       "moduleResolution": "node",
       "sourceMap": true,
```

Which allows us to not even include a tsconfig.json file. If one is
present, `ts-node` will use its options, but the above settings will
override any settings in a local tsconfig.json file. This means if you
want full control over the target, you'll need to go back to the raw
tsc workflow where you explicitly build ahead of time.
2018-08-06 14:00:58 -07:00
Matt Ellis 7074ae8cf3 Use new native typescript support in many tests
We retain a few tests on the RunBuild plan, with `typescript` set to
false in the runtime options, but for the general case, we remove the
build steps and custom entry points for our programs.
2018-08-06 14:00:58 -07:00
Matt Ellis ce5eaa8343 Support TypeScript in a more first-class way
This change lets us set runtime specific options in Pulumi.yaml, which
will flow as arguments to the language hosts. We then teach the nodejs
host that when the `typescript` is set to `true` that it should load
ts-node before calling into user code. This allows using typescript
natively without an explicit compile step outside of Pulumi.

This works even when a tsconfig.json file is not present in the
application and should provide a nicer inner loop for folks writing
typescript (I'm pretty sure everyone has run into the "but I fixed
that bug!  Why isn't it getting picked up?  Oh, I forgot to run tsc"
problem.

Fixes #958
2018-08-06 14:00:58 -07:00
CyrusNajmabadi 5a52c1c080
Actually export function. (#1710) 2018-08-06 15:45:06 -04:00
Chris Smith 8de307b876
1-index error messages printed to the console (#1709)
The `range` operator  returns array indexes that are 0-indexed. This is helpful when working with the computer code, but since we print the error to humans it looks really strange.

e.g. 
```
error: 7 errors occurred:
    0) resource 'urn:pulumi:timer-ex::timer::pulumi:pulumi:Stack::timer-timer-ex' is from a different stack (timer-ex != timer-import)
    1) resource 'urn:pulumi:timer-ex::timer:☁️timer:Timer::test-timer' is from a different stack (timer-ex != timer-import)
    ...
```
2018-08-06 11:58:06 -07:00
CyrusNajmabadi 0614b1d052
Move node_module inclusion logic down to pulumi/pulumi so we can use it from both aws and azure. (#1705) 2018-08-06 14:12:19 -04:00
Joe Duffy 8dca3f7b48
Merge pull request #1703 from pulumi/joeduffy/protobufc_dockerfile
Make Protobuf/gRPC compilation repeatable
2018-08-04 20:30:23 -07:00
joeduffy 95ffe712af Remove build step from build-proto
After making my prior change, I discovered that there's a build target
for this (the missing step). Since cached builds are very quick, it
seems fine to just do this as part of generate.sh, so I'm removing.
2018-08-04 10:29:53 -07:00
joeduffy b0d91ad9a9 Make Protobuf/gRPC compilation repeatable
I tried to re-generate the Protobuf/gRPC files, but generate.sh seems to
have assumed I manually built the Dockerfile ahead-of-time (unless I'm
missing something -- very possible). Unfortunately, when I went to do
that, I ended up with a handful of errors, most of them due to
differences in versions. (We probably want to think about pinning them.)

To remedy both issues, I've fixed up the Dockerfile so that it works for
me at least, and added a build step to the front of generate.sh.
2018-08-04 10:27:36 -07:00
Sean Gillespie 48aa5e73f8
Save resources obtained from ".get" in the snapshot (#1654)
* Protobuf changes to record dependencies for read resources

* Add a number of tests for read resources, especially around replacement

* Place read resources in the snapshot with "external" bit set

Fixes pulumi/pulumi#1521. This commit introduces two new step ops: Read
and ReadReplacement. The engine generates Read and ReadReplacement steps
when servicing ReadResource RPC calls from the language host.

* Fix an omission of OpReadReplace from the step list

* Rebase against master

* Transition to use V2 Resources by default

* Add a semantic "relinquish" operation to the engine

If the engine observes that a resource is read and also that the
resource exists in the snapshot as a non-external resource, it will not
delete the resource if the IDs of the old and new resources match.

* Typo fix

* CR: add missing comments, DeserializeDeployment -> DeserializeDeploymentV2, ID check
2018-08-03 14:06:00 -07:00
Chris Smith a9ff410360
Fix doc comment for ComponentResource (#1700)
The `protect` option was added to `ResourceOptions` a long time ago.
2018-08-03 13:31:19 -07:00
Chris Smith 598e25a100
Wire persist field through CLI (#1667) 2018-08-02 20:13:12 -07:00
CyrusNajmabadi c57aef785b
Ensure we can capture non-built-in modules with 'require'. (#1685) 2018-08-02 16:25:49 -04:00
Luke Hoban 85121274aa
Allow dependsOn to accept a Resource | Resource[] (#1692)
Fixes #1690.
2018-08-02 13:13:33 -07:00
CyrusNajmabadi 58ae413bca
Do not add a newline between a stream of info messages. The contract is that these will just be appended continguously. (#1688) 2018-08-02 10:55:15 -04:00
Joe Duffy b2c91f7c24
Detect secret-like config (#1689)
Previously, we would unconditionally warn anytime you added a non-secret
config:

    $ pulumi config set aws:region us-west-2
    warning: saved config key '%s' value '%s' as plaintext;
        re-run with --secret to encrypt the value instead.
        Use --plaintext to avoid this warning

This was particularly annoying, since it is very common to store
non-secret config. For instance, the AWS region. And it was easy to tune
out because it wasn't actually warning about anything interesting.

This change, which resolves pulumi/pulumi#570, uses an approach similar
to Go's gas linter, to detect high entropy values, and issue an error.
This ensures that we only make noise on things we suspect are actually
secrets being stored in plaintext, and forces the user to pass
--plaintext. For instance, the common case issues no errors:

    $ pulumi config set aws:region us-west-2

And in the event that you store something that is secret-like:

    $ pulumi config set aws:region nq8r4B4xslzrtj0a3
    error: config value 'nq8r4B4xslzrtj0a3' looks like a secret;
        rerun with --secret to encrypt it, or --plaintext if you meant
        to store in plaintext

To suppress this, simply pass --secret (to encrypt) or --plaintext (to
override the warning).
2018-08-02 04:14:16 -07:00
CyrusNajmabadi 3d063e200c
Properly display multi-step replaces in the progress UI. (#1679) 2018-08-02 00:48:14 -04:00
Sean Gillespie c4f08db78b
Fix an issue where we fail to catch duplicate URNs in the same plan (#1687) 2018-08-01 21:32:29 -07:00
Thomas Schersach 9bfea8e5c4 Added brew install instructions for macOS 2018-08-01 14:32:09 -07:00
Thomas Schersach 29090ef848 Added pipenv to development environment required tools 2018-08-01 14:32:09 -07:00
Alex Clemmer b0c383e1e8 Add URN argument to HostClient#Log
This will make it possible to correlate log messages to specific
resources.
2018-08-01 11:00:48 -07:00
Chris Smith 6958ad4073
Merge updates to install-common-toolchain.sh (#1680) 2018-07-31 23:08:19 -07:00
Chris Smith 7aa91d69e0
Add optional CI properties to environment metadata (#1678)
* Add optional CI properties to environment metadata

* Address PR feedback
2018-07-31 21:38:07 -07:00
CyrusNajmabadi aac67f41e3
Tiny tweak to error message. (#1670) 2018-08-01 00:09:47 -04:00
Joe Duffy 76eea4863a
Prefer "up" over "update" (#1672) 2018-07-31 10:22:16 -07:00
CyrusNajmabadi d19942f2b0
Go back to capturing *non-user* modules by 'require' reference. (#1655) 2018-07-31 11:37:46 -04:00
Joe Duffy 091c0e1c23
Upgrade Node.js SDK to TypeScript 3.0 (#1669)
Per pulumi/pulumi#1668. No code changes required, just package.json
and lockfile updates.
2018-07-30 23:19:28 -07:00
Matt Ellis 91247f2e19 Bump versions in compat test
There is not a prebuilt binary for Node 10.7 for the older version of gRPC
that we had locked to, forcing a rebuild when the project was restored.
On some CI workers this does not work out and the test spews a bunch of
output and then appears to hang.

Since this doesn't seem related to Pulumi in any way, just bump our
version.
2018-07-30 10:21:34 -07:00
Matt Ellis f6571980ba Lock to same version of dep as *nix builds 2018-07-30 10:21:34 -07:00
Sean Gillespie ad3b931bea
Merge pull request #1664 from pulumi/swgillespie/resource-break
Round out the breaking changes for ResourceV2
2018-07-27 18:44:37 -07:00
Pat Gavlin d70d36b887
Handle non-{unknown,partial} statuses in Create/Update. (#1663)
For example resource.StatusOK. Unenlightened providers may return errors
that result in this status; we should not crash if this is the case.
2018-07-27 16:08:11 -07:00
Sean Gillespie 48d095d66f Remove "down" operation for migration - it is not semantically valid in
general.
2018-07-27 14:52:28 -07:00
Sean Gillespie 9ca76b65c0
Round out V2 breaking changes for Resource 2018-07-27 13:53:14 -07:00
Joe Duffy f58ea68a7d
Make minor improvements to pulumi new (#1659)
After running `pulumi new`, we print a message to let the user
know the project has been created, along with next steps to actually
perform a deployment. It's easy for this to get lost among the rest
of the output, however. So, wordsmith it a little, and add some color,
to make it pop a little bit more.

Also add SuggestFor annotations so that `init` and `create` direct
you to run the `new` command (I often accidentally type `init`).
2018-07-26 15:49:12 -07:00
CyrusNajmabadi 48df5bfe1e
Update pulumi/pulumi to run on Nodejs v10. (#1658) 2018-07-25 16:55:20 -07:00
CyrusNajmabadi b90235c611
Add license fields to package.json. (#1656) 2018-07-24 16:10:13 -07:00
Alex Clemmer 61324d5540 Print CLI warning for resource init failures
Fixes #1643.

When a resource fails to initialize (i.e., it is successfully created,
but fails to transition to a fully-initialized state), and a user
subsequently runs `pulumi update` without changing that resource, our
CLI will fail to warn the user that this resource is not initialized.

This commit resolves this issue.
2018-07-20 17:59:06 -07:00
Alex Clemmer f037c7d143 Checkpoint resource initialization errors
When a resource fails to initialize (i.e., it is successfully created,
but fails to transition to a fully-initialized state), and a user
subsequently runs `pulumi update` without changing that resource, our
CLI will fail to warn the user that this resource is not initialized.

This commit begins the process of allowing our CLI to report this by
storing a list of initialization errors in the checkpoint.
2018-07-20 17:59:06 -07:00