-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
73 lines (62 loc) · 2.05 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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"strings"
"time"
"github.com/tombuildsstuff/azurerm-dalek/clients"
"github.com/tombuildsstuff/azurerm-dalek/dalek"
"github.com/tombuildsstuff/azurerm-dalek/dalek/options"
)
func main() {
log.Print("Starting Azure Dalek..")
prefix := flag.String("prefix", "acctest", "-prefix=acctest")
flag.Parse()
credentials := clients.Credentials{
ClientID: os.Getenv("ARM_CLIENT_ID"),
ClientSecret: os.Getenv("ARM_CLIENT_SECRET"),
SubscriptionID: os.Getenv("ARM_SUBSCRIPTION_ID"),
TenantID: os.Getenv("ARM_TENANT_ID"),
EnvironmentName: os.Getenv("ARM_ENVIRONMENT"),
Endpoint: os.Getenv("ARM_ENDPOINT"),
}
opts := options.Options{
ActuallyDelete: strings.EqualFold(os.Getenv("YES_I_REALLY_WANT_TO_DELETE_THINGS"), "true"),
NumberOfResourceGroupsToDelete: int64(1000),
Prefix: *prefix,
}
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Hour)
defer cancel()
if err := run(ctx, credentials, opts); err != nil {
log.Print(err.Error())
os.Exit(1)
}
}
func run(ctx context.Context, credentials clients.Credentials, opts options.Options) error {
sdkClient, err := clients.BuildAzureClient(ctx, credentials)
if err != nil {
return fmt.Errorf("building Azure Clients: %+v", err)
}
log.Printf("[DEBUG] Options: %s", opts)
client := dalek.NewDalek(sdkClient, opts)
log.Printf("[DEBUG] Processing Resource Manager..")
if errors := client.ResourceManager(ctx); len(errors) != 0 {
errList := make([]string, 0)
for _, e := range errors {
errList = append(errList, e.Error())
}
return fmt.Errorf("processing Resource Manager: %+v", strings.Join(errList, "\n"))
}
log.Printf("[DEBUG] Processing Microsoft Graph..")
if err := client.MicrosoftGraph(ctx); err != nil {
return fmt.Errorf("processing Microsoft Graph: %+v", err)
}
log.Printf("[DEBUG] Processing Management Groups..")
if err := client.ManagementGroups(ctx); err != nil {
return fmt.Errorf("processing Management Groups: %+v", err)
}
return nil
}