-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (86 loc) · 3.3 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
98
package main
import (
"flag"
"github.com/bellhops/tfc-cli/app"
"github.com/hashicorp/go-tfe"
"github.com/urfave/cli/v2"
"log"
"os"
)
func main() {
var t, o string
flag.StringVar(&t, "token", os.Getenv("TFC_TOKEN"), "terraform cloud api token")
flag.StringVar(&o, "org", os.Getenv("TFC_ORG"), "terraform cloud org")
flag.Parse()
if t == "" {
log.Fatal("missing access token. Set TFC_TOKEN in the environment or pass --token")
}
if o == "" {
log.Fatal("missing terraform cloud organization. Set TFC_ORG in the environment or pass --org")
}
// Get org and token from env or flag
tfeCFG := &tfe.Config{
Token: t,
}
tfeClient, err := tfe.NewClient(tfeCFG)
if err != nil {
log.Fatal(err)
}
cfg := &app.Config{
TFE: tfeCFG,
OrgName: o,
}
tfc := app.CreateTFCClient(nil, cfg, tfeClient)
a := cli.NewApp()
a.Name = "tfc-cli"
a.Usage = "tfc-client [resource] [action] [options]; tfc-client workspaces list --search=\"api\""
a.UsageText = "Interact with Terraform Cloud via CLI\nRequires Terraform Cloud API Access Token. " +
"Set TFC_TOKEN or pass --token\nRequires Terraform Cloud Organization Name. Set TFC_ORG or pass --org" +
"\nSee https://developer.hashicorp.com/terraform/cloud-docs/api-docs for reference"
verboseFlag := &cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Value: true,
}
a.Flags = []cli.Flag{verboseFlag}
// The App.Commands field contains the top level resource commands:
// tfc-client [resource]; tfc-client workspaces
// The Subcommands field for each resource command contain the action subcommands:
// tfc-client [resource] [action] [options]; tfc-client workspaces list --search="api"
a.Commands = []*cli.Command{
{
Name: "workspaces",
Usage: "Query Workspaces via cli options",
UsageText: "Query Workspaces via cli options\nReference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces",
Subcommands: []*cli.Command{tfc.WorkspaceListCmd()},
},
{
Name: "config-versions",
Usage: "Query Terraform Workspace Configuration Versions",
UsageText: "Query Terraform Workspace Configuration Versions\nReference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/configuration-versions",
Subcommands: []*cli.Command{tfc.ConfigVersionsListCmd()},
},
{
Name: "var-sets",
Usage: "Interact Terraform Variable Sets",
UsageText: "Interact Terraform Variable Sets\nReference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/variable-sets",
Subcommands: []*cli.Command{tfc.VarSetsListCmd(), tfc.VarSetsListForWorkspaceCmd(), tfc.VarSetsReadCmd()},
},
{
Name: "var-set-variables",
Usage: "Interact Terraform Variable Set Variables",
UsageText: "Interact Terraform Variable Set Variables\nReference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/variable-set-variables",
Subcommands: []*cli.Command{tfc.VarSetVariablesListCmd(), tfc.VarSetVariablesUpdateCmd()},
},
{
Name: "runs",
Usage: "Interact with Terraform Cloud runs",
UsageText: "Interact with Terraform Cloud runs\nReference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/runs",
Subcommands: []*cli.Command{tfc.RunsCreateCmd()},
},
}
err = a.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}