-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (84 loc) · 1.85 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"errors"
"fmt"
"io/fs"
"os"
"strings"
"github.com/econominhas/infra/internal/projects/econominhas"
"github.com/manifoldco/promptui"
)
func getStack(stackName string) ([]byte, error) {
switch stackName {
case "econominhas-global":
return econominhas.Global()
case "econominhas-webapp":
return econominhas.Webapp()
default:
return []byte(""), errors.New("stack not found")
}
}
func getFullStackName(project string, env string, product string) string {
if product == "global" {
return strings.Join([]string{project, product}, "-")
}
return strings.Join([]string{project, env, product}, "-")
}
func main() {
envQuestion := promptui.Select{
Label: "Select Environment",
Items: []string{
"dev",
"prod",
},
}
_, env, err := envQuestion.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
projectQuestion := promptui.Select{
Label: "Select Project",
Items: []string{
"econominhas",
},
}
_, project, err := projectQuestion.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
productQuestion := promptui.Select{
Label: "Select Product",
Items: []string{
"global",
"webapp",
},
}
_, product, err := productQuestion.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
os.Setenv("ENV", env)
stack, err := getStack(project + "-" + product)
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
fullStackName := getFullStackName(project, env, product)
filePath := "./outputs/" + fullStackName + ".yaml"
const perm fs.FileMode = 0770
os.Mkdir("./outputs", perm)
err = os.WriteFile(filePath, stack, perm)
if err != nil {
fmt.Print(err)
panic(1)
}
fmt.Print("Please run the following command:\n")
fmt.Printf(
"aws cloudformation deploy --template-file %s --stack-name %s\n",
filePath,
fullStackName,
)
}