This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (64 loc) · 1.43 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
package main
import (
"log"
"os"
"github.com/hazelops/tflock/dynamodb"
"github.com/urfave/cli/v2"
)
var Version = "deployment"
var (
lockID string
region string
profile string
table string
)
func main() {
app := &cli.App{
Name: "tflock",
Usage: "lock terraform state",
UsageText: `
# Lock terraform state in S3 (DynamoBD)
tflock --lock-id nutcorp-tf-state/env/terraform.tfstate
`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lock-id",
Usage: "specify lock id, usually just a path to the state file in your s3 bucket",
Required: true,
Destination: &lockID,
},
&cli.StringFlag{
Name: "aws-region",
Usage: "AWS region",
Required: true,
EnvVars: []string{"TFLOCK_AWS_REGION", "AWS_REGION"},
Destination: ®ion,
Value: "us-east-1",
},
&cli.StringFlag{
Name: "aws-profile",
Usage: "AWS profile",
Required: true,
EnvVars: []string{"TFLOCK_AWS_PROFILE", "AWS_PROFILE"},
Destination: &profile,
Value: "default",
},
&cli.StringFlag{
Name: "dynamodb-table",
Usage: "specify DynamoDB table",
Required: true,
Destination: &table,
Value: "tf-state-lock",
},
},
Action: func(c *cli.Context) error {
dynamodb.Lock(lockID, region, profile)
return nil
},
Version: Version,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}