-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (70 loc) · 2.06 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
package main
import (
"context"
"fmt"
"os"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optup"
)
func main() {
// to destroy our program, we can run `go run main.go destroy`
destroy := false
argsWithoutProg := os.Args[1:]
if len(argsWithoutProg) > 0 {
if argsWithoutProg[0] == "destroy" {
destroy = true
}
}
ctx := context.Background()
//projectName := "pulumi-azure-helloworld"
stackName := "dev"
repo := auto.GitRepo{
URL: "https://github.com/katasec/library.git",
ProjectPath: "azure-storageaccount-sample",
}
s, err := auto.UpsertStackRemoteSource(ctx, stackName, repo)
if err != nil {
fmt.Printf("Failed to create or select stack: %v\n", err)
os.Exit(1)
}
fmt.Printf("Created/Selected stack %q, and cloned program from git\n", stackName)
s.SetConfig(ctx, "azure:location", auto.ConfigValue{Value: "SouthEastAsia"})
fmt.Println("Successfully set config")
fmt.Println("Starting refresh")
_, err = s.Refresh(ctx)
if err != nil {
fmt.Printf("Failed to refresh stack: %v\n", err)
os.Exit(1)
}
fmt.Println("Refresh succeeded!")
if destroy {
fmt.Println("Starting stack destroy")
// wire up our destroy to stream progress to stdout
stdoutStreamer := optdestroy.ProgressStreams(os.Stdout)
// destroy our stack and exit early
_, err := s.Destroy(ctx, stdoutStreamer)
if err != nil {
fmt.Printf("Failed to destroy stack: %v", err)
}
fmt.Println("Stack successfully destroyed")
os.Exit(0)
}
fmt.Println("Starting update")
// wire up our update to stream progress to stdout
stdoutStreamer := optup.ProgressStreams(os.Stdout)
// run the update to deploy our s3 website
res, err := s.Up(ctx, stdoutStreamer)
if err != nil {
fmt.Printf("Failed to update stack: %v\n\n", err)
os.Exit(1)
}
fmt.Println("Update succeeded!")
// get the URL from the stack outputs
url, ok := res.Outputs["websiteUrl"].Value.(string)
if !ok {
fmt.Println("Failed to unmarshall output URL")
os.Exit(1)
}
fmt.Printf("URL: %s\n", url)
}