-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy.go
65 lines (55 loc) · 1.7 KB
/
deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"fmt"
"log"
"os"
"strings"
"github.com/santiago-labs/telophasecli/cmd/runner"
"github.com/santiago-labs/telophasecli/resourceoperation"
"golang.org/x/sync/errgroup"
"github.com/spf13/cobra"
)
var (
tag string
targets string
stacks string
// TUI
useTUI bool
)
func init() {
rootCmd.AddCommand(deployCmd)
deployCmd.Flags().StringVar(&stacks, "stacks", "", "Filter stacks to deploy")
deployCmd.Flags().StringVar(&tag, "tag", "", "Filter accounts and organization units to deploy")
deployCmd.Flags().StringVar(&targets, "targets", "", "Filter resource types to deploy. Options: organization, scp, stacks")
deployCmd.Flags().StringVar(&orgFile, "org", "organization.yml", "Path to the organization.yml file")
deployCmd.Flags().BoolVar(&useTUI, "tui", false, "use the TUI for deploy")
}
var deployCmd = &cobra.Command{
Use: "deploy",
Short: "deploy - Deploy a CDK and/or TF stacks to your AWS account(s). Accounts in organization.yml will be created if they do not exist.",
Run: func(cmd *cobra.Command, args []string) {
if err := validateTargets(); err != nil {
log.Fatal("error validating targets err:", err)
}
var consoleUI runner.ConsoleUI
parsedTargets := filterEmptyStrings(strings.Split(targets, ","))
var g errgroup.Group
if useTUI {
consoleUI = runner.NewTUI()
g.Go(func() error {
return ProcessOrgEndToEnd(consoleUI, resourceoperation.Deploy, parsedTargets)
})
} else {
consoleUI = runner.NewSTDOut()
if err := ProcessOrgEndToEnd(consoleUI, resourceoperation.Deploy, parsedTargets); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
consoleUI.Start()
if err := g.Wait(); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}