-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
48 lines (41 loc) · 1.53 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
package main
import (
"flag"
"fmt"
"terraform-workspace-cleanup/cmd"
)
func main() {
flag.Usage = func() {
fmt.Println("Usage: tf-workspace-cleanup -register-workspace=<workspace> -time-to-protect=2 -aws-account-id=12345678 -aws-iam-role=sirius-ci")
fmt.Println("Usage: tf-workspace-cleanup -protected-workspaces=true -aws-account-id=12345678 -aws-iam-role=sirius-ci")
flag.PrintDefaults()
}
var workspaceName string
var protectedWorkspaces bool
var awsAccountId string
var awsIAMRoleName string
var timeToProtect int64
flag.StringVar(&workspaceName, "register-workspace", "", "Register a workspace to be deleted at a later point")
flag.StringVar(&awsAccountId, "aws-account-id", "", "Account ID for IAM Role")
flag.StringVar(&awsIAMRoleName, "aws-iam-role", "", "AWS IAM Role Name")
flag.Int64Var(&timeToProtect, "time-to-protect", 1 , "Time in hours to protect workspace for")
flag.BoolVar(&protectedWorkspaces, "protected-workspaces", false, "get list of protected workspaces for deletion")
flag.Parse()
if awsAccountId == "" {
fmt.Println("Error: You have not provided an AWS Account ID")
flag.Usage()
}
if awsIAMRoleName == "" {
fmt.Println("Error: You have not provided an AWS IAM Role Name")
flag.Usage()
}
if protectedWorkspaces {
cmd.RetrieveProtectedWorkspaces(&awsAccountId, &awsIAMRoleName)
}
if workspaceName != "" {
cmd.RegisterWorkspace(&workspaceName, &awsAccountId, &awsIAMRoleName, &timeToProtect)
} else if protectedWorkspaces != true {
fmt.Println("Error: Workspace not passed")
flag.Usage()
}
}