Skip to content

Add Down Command #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func Build() *cli.App {
cmd.Modules,
cmd.Workspaces,
cmd.Up(),
cmd.Down(),
cmd.Plan(),
cmd.Apply(),
cmd.Outputs(),
Expand Down
53 changes: 53 additions & 0 deletions cmd/down.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"context"
"fmt"
"github.com/urfave/cli/v2"
"gopkg.in/nullstone-io/go-api-client.v0"
"gopkg.in/nullstone-io/go-api-client.v0/types"
"gopkg.in/nullstone-io/nullstone.v0/runs"
"os"
)

var Down = func() *cli.Command {
return &cli.Command{
Name: "down",
Description: "Destroys the infrastructure for the given block/environment.",
Usage: "Destroy the block infrastructure",
UsageText: "nullstone down [--stack=<stack-name>] --block=<block-name> --env=<env-name> [options]",
Flags: []cli.Flag{
StackFlag,
BlockFlag,
EnvFlag,
&cli.BoolFlag{
Name: "wait",
Aliases: []string{"w"},
Usage: "Wait for the launch to complete and stream the Terraform logs to the console.",
},
},
Action: func(c *cli.Context) error {
return BlockWorkspaceAction(c, func(ctx context.Context, cfg api.Config, stack types.Stack, block types.Block, env types.Environment, workspace types.Workspace) error {
if workspace.Status == types.WorkspaceStatusNotProvisioned {
fmt.Println("workspace is not launched")
return nil
}

f := false
newRun, err := runs.Create(cfg, workspace, &f, true)
if err != nil {
return fmt.Errorf("error creating run: %w", err)
} else if newRun == nil {
return fmt.Errorf("unable to create run")
}
fmt.Printf("created run %q\n", newRun.Uid)
fmt.Fprintln(os.Stdout, runs.GetBrowserUrl(cfg, workspace, *newRun))

if c.IsSet("wait") {
return runs.StreamLogs(ctx, cfg, workspace, newRun)
}
return nil
})
},
}
}