2018-05-22 19:43:36 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
package diy
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
|
|
|
|
import (
|
2018-05-08 01:23:03 +00:00
|
|
|
"context"
|
2023-05-08 13:54:43 +00:00
|
|
|
"sync/atomic"
|
2018-09-14 03:54:42 +00:00
|
|
|
"time"
|
2018-05-08 01:23:03 +00:00
|
|
|
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
2023-01-12 15:33:17 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
|
2019-03-14 22:32:10 +00:00
|
|
|
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/backend"
|
2023-09-18 11:01:28 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/display"
|
2023-12-05 08:32:40 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/engine"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/operations"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
|
2022-08-18 14:31:34 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/secrets"
|
2023-01-04 15:45:21 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/secrets/passphrase"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
|
2023-02-10 12:24:28 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
)
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
// diyStack is a diy stack descriptor.
|
|
|
|
type diyStack struct {
|
2023-05-08 13:54:43 +00:00
|
|
|
// the stack's reference (qualified name).
|
2024-01-30 15:53:10 +00:00
|
|
|
ref *diyBackendReference
|
2023-05-08 13:54:43 +00:00
|
|
|
// a snapshot representing the latest deployment state, allocated on first use. It's valid for the
|
|
|
|
// snapshot itself to be nil.
|
|
|
|
snapshot atomic.Pointer[*deploy.Snapshot]
|
|
|
|
// a pointer to the backend this stack belongs to.
|
2024-01-30 15:53:10 +00:00
|
|
|
b *diyBackend
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func newStack(ref *diyBackendReference, b *diyBackend) backend.Stack {
|
2023-02-10 12:24:28 +00:00
|
|
|
contract.Requiref(ref != nil, "ref", "ref was nil")
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
return &diyStack{
|
2023-05-08 13:54:43 +00:00
|
|
|
ref: ref,
|
|
|
|
b: b,
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Ref() backend.StackReference { return s.ref }
|
|
|
|
func (s *diyStack) Snapshot(ctx context.Context, secretsProvider secrets.Provider) (*deploy.Snapshot, error) {
|
2023-05-08 13:54:43 +00:00
|
|
|
if v := s.snapshot.Load(); v != nil {
|
|
|
|
return *v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
snap, err := s.b.getSnapshot(ctx, secretsProvider, s.ref)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.snapshot.Store(&snap)
|
|
|
|
return snap, nil
|
2023-01-11 16:04:14 +00:00
|
|
|
}
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Backend() backend.Backend { return s.b }
|
|
|
|
func (s *diyStack) Tags() map[apitype.StackTagName]string { return nil }
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Remove(ctx context.Context, force bool) (bool, error) {
|
2018-05-08 01:23:03 +00:00
|
|
|
return backend.RemoveStack(ctx, s, force)
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Rename(ctx context.Context, newName tokens.QName) (backend.StackReference, error) {
|
2019-03-14 22:32:10 +00:00
|
|
|
return backend.RenameStack(ctx, s, newName)
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Preview(
|
2022-01-31 10:31:51 +00:00
|
|
|
ctx context.Context,
|
2023-12-05 08:32:40 +00:00
|
|
|
op backend.UpdateOperation, events chan<- engine.Event,
|
2023-03-03 16:36:39 +00:00
|
|
|
) (*deploy.Plan, display.ResourceChanges, result.Result) {
|
2023-12-05 08:32:40 +00:00
|
|
|
return backend.PreviewStack(ctx, s, op, events)
|
2018-05-05 18:57:09 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Update(ctx context.Context, op backend.UpdateOperation) (display.ResourceChanges, result.Result) {
|
2018-09-05 14:20:25 +00:00
|
|
|
return backend.UpdateStack(ctx, s, op)
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Import(ctx context.Context, op backend.UpdateOperation,
|
2023-03-03 16:36:39 +00:00
|
|
|
imports []deploy.Import,
|
|
|
|
) (display.ResourceChanges, result.Result) {
|
2020-10-14 11:51:53 +00:00
|
|
|
return backend.ImportStack(ctx, s, op, imports)
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Refresh(ctx context.Context, op backend.UpdateOperation) (display.ResourceChanges, result.Result) {
|
2018-09-05 14:20:25 +00:00
|
|
|
return backend.RefreshStack(ctx, s, op)
|
Implement a refresh command
This change implements a `pulumi refresh` command. It operates a bit
like `pulumi update`, and friends, in that it supports `--preview` and
`--diff`, along with the usual flags, and will update your checkpoint.
It works through substitution of the deploy.Source abstraction, which
generates a sequence of resource registration events. This new
deploy.RefreshSource takes in a prior checkpoint and will walk it,
refreshing the state via the associated resource providers by invoking
Read for each resource encountered, and merging the resulting state with
the prior checkpoint, to yield a new resource.Goal state. This state is
then fed through the engine in the usual ways with a few minor caveats:
namely, although the engine must generate steps for the logical
operations (permitting us to get nice summaries, progress, and diffs),
it mustn't actually carry them out because the state being imported
already reflects reality (a deleted resource has *already* been deleted,
so of course the engine need not perform the deletion). The diffing
logic also needs to know how to treat the case of refresh slightly
differently, because we are going to be diffing outputs and not inputs.
Note that support for managed stacks is not yet complete, since that
requires updates to the service to support a refresh endpoint. That
will be coming soon ...
2018-04-10 18:22:39 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Destroy(ctx context.Context, op backend.UpdateOperation) (display.ResourceChanges, result.Result) {
|
2018-09-05 14:20:25 +00:00
|
|
|
return backend.DestroyStack(ctx, s, op)
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) Watch(ctx context.Context, op backend.UpdateOperation, paths []string) result.Result {
|
2021-06-21 07:34:21 +00:00
|
|
|
return backend.WatchStack(ctx, s, op, paths)
|
2019-11-06 20:56:29 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) GetLogs(ctx context.Context, secretsProvider secrets.Provider, cfg backend.StackConfiguration,
|
2023-03-03 16:36:39 +00:00
|
|
|
query operations.LogQuery,
|
|
|
|
) ([]operations.LogEntry, error) {
|
2023-01-11 16:04:14 +00:00
|
|
|
return backend.GetStackLogs(ctx, secretsProvider, s, cfg, query)
|
Make some updates based on CR feedback
This change implements some feedback from @ellismg.
* Make backend.Stack an interface and let backends implement it,
enabling dynamic type testing/casting to access information
specific to that backend. For instance, the cloud.Stack conveys
the cloud URL, org name, and PPC name, for each stack.
* Similarly expose specialized backend.Backend interfaces,
local.Backend and cloud.Backend, to convey specific information.
* Redo a bunch of the commands in terms of these.
* Keeping with this theme, turn the CreateStack options into an
opaque interface{}, and let the specific backends expose their
own structures with their own settings (like PPC name in cloud).
* Show both the org and PPC names in the cloud column printed in
the stack ls command, in addition to the Pulumi Cloud URL.
Unrelated, but useful:
* Special case the 401 HTTP response and make a friendly error,
to tell the developer they must use `pulumi login`. This is
better than tossing raw "401: Unauthorized" errors in their face.
* Change the "Updating stack '..' in the Pulumi Cloud" message to
use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 15:51:18 +00:00
|
|
|
}
|
2018-01-05 20:46:13 +00:00
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) ExportDeployment(ctx context.Context) (*apitype.UntypedDeployment, error) {
|
2018-05-08 01:23:03 +00:00
|
|
|
return backend.ExportStackDeployment(ctx, s)
|
2018-01-05 20:46:13 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) ImportDeployment(ctx context.Context, deployment *apitype.UntypedDeployment) error {
|
2018-05-08 01:23:03 +00:00
|
|
|
return backend.ImportStackDeployment(ctx, s, deployment)
|
2018-01-05 20:46:13 +00:00
|
|
|
}
|
2018-09-14 03:54:42 +00:00
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (s *diyStack) DefaultSecretManager(info *workspace.ProjectStack) (secrets.Manager, error) {
|
2023-01-12 15:33:17 +00:00
|
|
|
return passphrase.NewPromptingPassphraseSecretsManager(info, false /* rotatePassphraseSecretsProvider */)
|
2022-08-18 14:31:34 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
type diyStackSummary struct {
|
2021-07-28 01:37:25 +00:00
|
|
|
name backend.StackReference
|
|
|
|
chk *apitype.CheckpointV3
|
2018-09-14 03:54:42 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func newDIYStackSummary(name backend.StackReference, chk *apitype.CheckpointV3) diyStackSummary {
|
|
|
|
return diyStackSummary{name: name, chk: chk}
|
2018-09-14 03:54:42 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (lss diyStackSummary) Name() backend.StackReference {
|
2021-07-28 01:37:25 +00:00
|
|
|
return lss.name
|
2018-09-14 03:54:42 +00:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (lss diyStackSummary) LastUpdate() *time.Time {
|
2021-07-28 01:37:25 +00:00
|
|
|
if lss.chk != nil && lss.chk.Latest != nil {
|
|
|
|
if t := lss.chk.Latest.Manifest.Time; !t.IsZero() {
|
2018-09-14 03:54:42 +00:00
|
|
|
return &t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:53:10 +00:00
|
|
|
func (lss diyStackSummary) ResourceCount() *int {
|
2021-07-28 01:37:25 +00:00
|
|
|
if lss.chk != nil && lss.chk.Latest != nil {
|
|
|
|
count := len(lss.chk.Latest.Resources)
|
2018-09-14 03:54:42 +00:00
|
|
|
return &count
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|