2018-11-14 21:33:35 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-11-13 02:37:17 +00:00
|
|
|
"errors"
|
2018-11-14 21:33:35 +00:00
|
|
|
"fmt"
|
2020-04-23 22:52:48 +00:00
|
|
|
"sort"
|
2018-11-14 21:33:35 +00:00
|
|
|
|
2020-11-04 03:13:04 +00:00
|
|
|
uuid "github.com/gofrs/uuid"
|
2018-11-14 21:33:35 +00:00
|
|
|
|
2023-12-03 08:46:37 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
|
2018-11-14 21:33:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type builtinProvider struct {
|
2020-11-02 21:36:12 +00:00
|
|
|
context context.Context
|
|
|
|
cancel context.CancelFunc
|
2023-12-03 08:46:37 +00:00
|
|
|
diag diag.Sink
|
2020-11-02 21:36:12 +00:00
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
backendClient BackendClient
|
2020-11-02 21:36:12 +00:00
|
|
|
resources *resourceMap
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 08:46:37 +00:00
|
|
|
func newBuiltinProvider(backendClient BackendClient, resources *resourceMap, d diag.Sink) *builtinProvider {
|
2018-11-14 21:33:35 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
return &builtinProvider{
|
|
|
|
context: ctx,
|
|
|
|
cancel: cancel,
|
2020-11-02 21:36:12 +00:00
|
|
|
backendClient: backendClient,
|
|
|
|
resources: resources,
|
2023-12-03 08:46:37 +00:00
|
|
|
diag: d,
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) Pkg() tokens.Package {
|
|
|
|
return "pulumi"
|
|
|
|
}
|
|
|
|
|
2020-02-28 00:10:47 +00:00
|
|
|
// GetSchema returns the JSON-serialized schema for the provider.
|
|
|
|
func (p *builtinProvider) GetSchema(version int) ([]byte, error) {
|
|
|
|
return []byte("{}"), nil
|
|
|
|
}
|
|
|
|
|
2023-09-21 11:45:07 +00:00
|
|
|
func (p *builtinProvider) GetMapping(key, provider string) ([]byte, string, error) {
|
2022-11-16 17:22:47 +00:00
|
|
|
return nil, "", nil
|
|
|
|
}
|
|
|
|
|
2023-09-21 11:45:07 +00:00
|
|
|
func (p *builtinProvider) GetMappings(key string) ([]string, error) {
|
|
|
|
return []string{}, nil
|
|
|
|
}
|
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
// CheckConfig validates the configuration for this resource provider.
|
2019-05-20 20:56:27 +00:00
|
|
|
func (p *builtinProvider) CheckConfig(urn resource.URN, olds,
|
2023-03-03 16:36:39 +00:00
|
|
|
news resource.PropertyMap, allowUnknowns bool,
|
|
|
|
) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
2018-11-14 21:33:35 +00:00
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiffConfig checks what impacts a hypothetical change to this provider's configuration will have on the provider.
|
2023-05-29 15:41:36 +00:00
|
|
|
func (p *builtinProvider) DiffConfig(urn resource.URN, oldInputs, oldOutputs, newInputs resource.PropertyMap,
|
2023-03-03 16:36:39 +00:00
|
|
|
allowUnknowns bool, ignoreChanges []string,
|
|
|
|
) (plugin.DiffResult, error) {
|
2018-11-14 21:33:35 +00:00
|
|
|
return plugin.DiffResult{Changes: plugin.DiffNone}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) Configure(props resource.PropertyMap) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const stackReferenceType = "pulumi:pulumi:StackReference"
|
|
|
|
|
|
|
|
func (p *builtinProvider) Check(urn resource.URN, state, inputs resource.PropertyMap,
|
2023-03-03 16:36:39 +00:00
|
|
|
allowUnknowns bool, randomSeed []byte,
|
|
|
|
) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
2018-11-14 21:33:35 +00:00
|
|
|
typ := urn.Type()
|
|
|
|
if typ != stackReferenceType {
|
2021-11-13 02:37:17 +00:00
|
|
|
return nil, nil, fmt.Errorf("unrecognized resource type '%v'", urn.Type())
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 08:46:37 +00:00
|
|
|
// We only need to warn about this in Check. This won't be called for Reads but Creates or Updates will
|
|
|
|
// call Check first.
|
|
|
|
msg := "The \"pulumi:pulumi:StackReference\" resource type is deprecated. " +
|
|
|
|
"Update your SDK or if already up to date raise an issue at https://github.com/pulumi/pulumi/issues."
|
|
|
|
p.diag.Warningf(diag.Message(urn, msg))
|
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
for k := range inputs {
|
|
|
|
if k != "name" {
|
|
|
|
return nil, []plugin.CheckFailure{{Property: k, Reason: fmt.Sprintf("unknown property \"%v\"", k)}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
name, ok := inputs["name"]
|
|
|
|
if !ok {
|
|
|
|
return nil, []plugin.CheckFailure{{Property: "name", Reason: `missing required property "name"`}}, nil
|
|
|
|
}
|
|
|
|
if !name.IsString() && !name.IsComputed() {
|
|
|
|
return nil, []plugin.CheckFailure{{Property: "name", Reason: `property "name" must be a string`}}, nil
|
|
|
|
}
|
|
|
|
return inputs, nil, nil
|
|
|
|
}
|
|
|
|
|
2023-05-29 15:41:36 +00:00
|
|
|
func (p *builtinProvider) Diff(urn resource.URN, id resource.ID, oldInputs, oldOutputs, newInputs resource.PropertyMap,
|
2023-03-03 16:36:39 +00:00
|
|
|
allowUnknowns bool, ignoreChanges []string,
|
|
|
|
) (plugin.DiffResult, error) {
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(urn.Type() == stackReferenceType, "expected resource type %v, got %v", stackReferenceType, urn.Type())
|
2018-11-14 21:33:35 +00:00
|
|
|
|
2023-05-29 15:41:36 +00:00
|
|
|
if !newInputs["name"].DeepEquals(oldOutputs["name"]) {
|
2018-11-14 21:33:35 +00:00
|
|
|
return plugin.DiffResult{
|
|
|
|
Changes: plugin.DiffSome,
|
|
|
|
ReplaceKeys: []resource.PropertyKey{"name"},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return plugin.DiffResult{Changes: plugin.DiffNone}, nil
|
|
|
|
}
|
|
|
|
|
2020-10-09 20:13:55 +00:00
|
|
|
func (p *builtinProvider) Create(urn resource.URN, inputs resource.PropertyMap, timeout float64,
|
2023-03-03 16:36:39 +00:00
|
|
|
preview bool,
|
|
|
|
) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(urn.Type() == stackReferenceType, "expected resource type %v, got %v", stackReferenceType, urn.Type())
|
2018-11-14 21:33:35 +00:00
|
|
|
|
|
|
|
state, err := p.readStackReference(inputs)
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, resource.StatusUnknown, err
|
|
|
|
}
|
2020-10-09 20:13:55 +00:00
|
|
|
|
|
|
|
var id resource.ID
|
|
|
|
if !preview {
|
2020-11-04 03:13:04 +00:00
|
|
|
// generate a new uuid
|
|
|
|
uuid, err := uuid.NewV4()
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, resource.StatusOK, err
|
|
|
|
}
|
|
|
|
id = resource.ID(uuid.String())
|
2020-10-09 20:13:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
return id, state, resource.StatusOK, nil
|
|
|
|
}
|
|
|
|
|
2023-05-29 15:41:36 +00:00
|
|
|
func (p *builtinProvider) Update(urn resource.URN, id resource.ID,
|
|
|
|
oldInputs, oldOutputs, newInputs resource.PropertyMap,
|
|
|
|
timeout float64, ignoreChanges []string, preview bool,
|
2023-03-03 16:36:39 +00:00
|
|
|
) (resource.PropertyMap, resource.Status, error) {
|
2018-11-14 21:33:35 +00:00
|
|
|
contract.Failf("unexpected update for builtin resource %v", urn)
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(urn.Type() == stackReferenceType, "expected resource type %v, got %v", stackReferenceType, urn.Type())
|
2018-11-14 21:33:35 +00:00
|
|
|
|
2023-05-29 15:41:36 +00:00
|
|
|
return oldOutputs, resource.StatusOK, errors.New("unexpected update for builtin resource")
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) Delete(urn resource.URN, id resource.ID,
|
2023-10-13 14:12:26 +00:00
|
|
|
oldInputs, oldOutputs resource.PropertyMap, timeout float64,
|
2023-03-03 16:36:39 +00:00
|
|
|
) (resource.Status, error) {
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(urn.Type() == stackReferenceType, "expected resource type %v, got %v", stackReferenceType, urn.Type())
|
2018-11-14 21:33:35 +00:00
|
|
|
|
|
|
|
return resource.StatusOK, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) Read(urn resource.URN, id resource.ID,
|
2023-03-03 16:36:39 +00:00
|
|
|
inputs, state resource.PropertyMap,
|
|
|
|
) (plugin.ReadResult, resource.Status, error) {
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Requiref(urn != "", "urn", "must not be empty")
|
|
|
|
contract.Requiref(id != "", "id", "must not be empty")
|
|
|
|
contract.Assertf(urn.Type() == stackReferenceType, "expected resource type %v, got %v", stackReferenceType, urn.Type())
|
2018-11-14 21:33:35 +00:00
|
|
|
|
2023-12-03 08:46:37 +00:00
|
|
|
for k := range inputs {
|
|
|
|
if k != "name" {
|
|
|
|
return plugin.ReadResult{}, resource.StatusUnknown, fmt.Errorf("unknown property \"%v\"", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 20:50:00 +00:00
|
|
|
outputs, err := p.readStackReference(state)
|
2018-11-14 21:33:35 +00:00
|
|
|
if err != nil {
|
2019-03-11 20:50:00 +00:00
|
|
|
return plugin.ReadResult{}, resource.StatusUnknown, err
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 20:50:00 +00:00
|
|
|
return plugin.ReadResult{
|
|
|
|
Inputs: inputs,
|
|
|
|
Outputs: outputs,
|
|
|
|
}, resource.StatusOK, nil
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
2023-11-20 08:59:00 +00:00
|
|
|
func (p *builtinProvider) Construct(info plugin.ConstructInfo, typ tokens.Type, name string, parent resource.URN,
|
2023-03-03 16:36:39 +00:00
|
|
|
inputs resource.PropertyMap, options plugin.ConstructOptions,
|
|
|
|
) (plugin.ConstructResult, error) {
|
Initial support for remote component construction. (#5280)
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 #2430.
2020-09-08 02:33:55 +00:00
|
|
|
return plugin.ConstructResult{}, errors.New("builtin resources may not be constructed")
|
|
|
|
}
|
|
|
|
|
2023-03-03 16:36:39 +00:00
|
|
|
const (
|
|
|
|
readStackOutputs = "pulumi:pulumi:readStackOutputs"
|
2023-08-31 18:26:04 +00:00
|
|
|
readStackResourceOutputs = "pulumi:pulumi:readStackResourceOutputs" //nolint:gosec // not a credential
|
2023-03-03 16:36:39 +00:00
|
|
|
getResource = "pulumi:pulumi:getResource"
|
|
|
|
)
|
2019-02-15 22:29:55 +00:00
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
func (p *builtinProvider) Invoke(tok tokens.ModuleMember,
|
2023-03-03 16:36:39 +00:00
|
|
|
args resource.PropertyMap,
|
|
|
|
) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
2019-11-19 20:51:14 +00:00
|
|
|
switch tok {
|
|
|
|
case readStackOutputs:
|
|
|
|
outs, err := p.readStackReference(args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return outs, nil, nil
|
|
|
|
case readStackResourceOutputs:
|
|
|
|
outs, err := p.readStackResourceOutputs(args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return outs, nil, nil
|
2020-11-02 21:36:12 +00:00
|
|
|
case getResource:
|
|
|
|
outs, err := p.getResource(args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return outs, nil, nil
|
2019-11-19 20:51:14 +00:00
|
|
|
default:
|
2021-11-13 02:37:17 +00:00
|
|
|
return nil, nil, fmt.Errorf("unrecognized function name: '%v'", tok)
|
2019-02-15 22:29:55 +00:00
|
|
|
}
|
2018-11-14 21:33:35 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 07:20:26 +00:00
|
|
|
func (p *builtinProvider) StreamInvoke(
|
|
|
|
tok tokens.ModuleMember, args resource.PropertyMap,
|
2023-03-03 16:36:39 +00:00
|
|
|
onNext func(resource.PropertyMap) error,
|
|
|
|
) ([]plugin.CheckFailure, error) {
|
2023-12-12 12:19:42 +00:00
|
|
|
return nil, errors.New("the builtin provider does not implement streaming invokes")
|
2019-10-22 07:20:26 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 14:48:56 +00:00
|
|
|
func (p *builtinProvider) Call(tok tokens.ModuleMember, args resource.PropertyMap, info plugin.CallInfo,
|
2023-03-03 16:36:39 +00:00
|
|
|
options plugin.CallOptions,
|
|
|
|
) (plugin.CallResult, error) {
|
2023-12-12 12:19:42 +00:00
|
|
|
return plugin.CallResult{}, errors.New("the builtin provider does not implement call")
|
2021-06-30 14:48:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
func (p *builtinProvider) GetPluginInfo() (workspace.PluginInfo, error) {
|
|
|
|
// return an error: this should not be called for the builtin provider
|
|
|
|
return workspace.PluginInfo{}, errors.New("the builtin provider does not report plugin info")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) SignalCancellation() error {
|
|
|
|
p.cancel()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *builtinProvider) readStackReference(inputs resource.PropertyMap) (resource.PropertyMap, error) {
|
|
|
|
name, ok := inputs["name"]
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(ok, "missing required property 'name'")
|
|
|
|
contract.Assertf(name.IsString(), "expected 'name' to be a string")
|
2018-11-14 21:33:35 +00:00
|
|
|
|
|
|
|
if p.backendClient == nil {
|
|
|
|
return nil, errors.New("no backend client is available")
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs, err := p.backendClient.GetStackOutputs(p.context, name.StringValue())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
Do not taint all stack outputs as secrets if just one is
When using StackReference, if the stack you reference contains any
secret outputs, we have to mark the entire `outputs` member as a
secret output. This is because we only track secretness on a per
`Output<T>` basis.
For `getSecret` and friends, however, we know the name of the output
you are looking up and we can be smarter about if the returned
`Output<T>` should be treated as a secret or not.
This change augments the provider for StackReference such that it also
returns a list of top level stack output names who's values contain
secrets. In the language SDKs, we use this information, when present,
to decide if we should return an `Output<T>` that is marked as a
secret or not. Since the SDK and CLI are independent components, care
is taken to ensure that when the CLI does not return this information,
we behave as we did before (i.e. if any output is a secret, we treat
every output as a secret).
Fixes #2744
2019-08-13 00:02:30 +00:00
|
|
|
secretOutputs := make([]resource.PropertyValue, 0)
|
|
|
|
for k, v := range outputs {
|
|
|
|
if v.ContainsSecrets() {
|
|
|
|
secretOutputs = append(secretOutputs, resource.NewStringProperty(string(k)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 19:37:05 +00:00
|
|
|
// Sort the secret outputs so the order is deterministic, to avoid spurious diffs during updates.
|
2020-04-23 22:52:48 +00:00
|
|
|
sort.Slice(secretOutputs, func(i, j int) bool {
|
|
|
|
return secretOutputs[i].String() < secretOutputs[j].String()
|
|
|
|
})
|
|
|
|
|
2018-11-14 21:33:35 +00:00
|
|
|
return resource.PropertyMap{
|
2019-08-14 19:12:23 +00:00
|
|
|
"name": name,
|
|
|
|
"outputs": resource.NewObjectProperty(outputs),
|
|
|
|
"secretOutputNames": resource.NewArrayProperty(secretOutputs),
|
2018-11-14 21:33:35 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2019-02-15 22:29:55 +00:00
|
|
|
|
|
|
|
func (p *builtinProvider) readStackResourceOutputs(inputs resource.PropertyMap) (resource.PropertyMap, error) {
|
|
|
|
name, ok := inputs["stackName"]
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(ok, "missing required property 'stackName'")
|
|
|
|
contract.Assertf(name.IsString(), "expected 'stackName' to be a string")
|
2019-02-15 22:29:55 +00:00
|
|
|
|
|
|
|
if p.backendClient == nil {
|
|
|
|
return nil, errors.New("no backend client is available")
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs, err := p.backendClient.GetStackResourceOutputs(p.context, name.StringValue())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resource.PropertyMap{
|
|
|
|
"name": name,
|
|
|
|
"outputs": resource.NewObjectProperty(outputs),
|
|
|
|
}, nil
|
|
|
|
}
|
2020-11-02 21:36:12 +00:00
|
|
|
|
|
|
|
func (p *builtinProvider) getResource(inputs resource.PropertyMap) (resource.PropertyMap, error) {
|
|
|
|
urn, ok := inputs["urn"]
|
2023-02-17 20:05:48 +00:00
|
|
|
contract.Assertf(ok, "missing required property 'urn'")
|
|
|
|
contract.Assertf(urn.IsString(), "expected 'urn' to be a string")
|
2020-11-02 21:36:12 +00:00
|
|
|
|
|
|
|
state, ok := p.resources.get(resource.URN(urn.StringValue()))
|
|
|
|
if !ok {
|
2021-11-13 02:37:17 +00:00
|
|
|
return nil, fmt.Errorf("unknown resource %v", urn.StringValue())
|
2020-11-02 21:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return resource.PropertyMap{
|
|
|
|
"urn": urn,
|
|
|
|
"id": resource.NewStringProperty(string(state.ID)),
|
|
|
|
"state": resource.NewObjectProperty(state.Outputs),
|
|
|
|
}, nil
|
|
|
|
}
|