mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-22 00:30:40 +00:00
Use logrus for logging messages
This commit is contained in:
parent
5f6ed41c05
commit
ef64a0f2a3
@ -9,7 +9,7 @@ pipeline:
|
||||
- CGO_ENABLED=0
|
||||
commands:
|
||||
- go test -cover -coverprofile=coverage.out
|
||||
- go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a
|
||||
- go build -ldflags "-s -w -X main.revision=$(git rev-parse HEAD)" -a
|
||||
|
||||
coverage:
|
||||
image: coverage
|
||||
|
8
main.go
8
main.go
@ -9,14 +9,14 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var version string // build number set at compile-time
|
||||
var revision string // build number set at compile-time
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "terraform plugin"
|
||||
app.Usage = "terraform plugin"
|
||||
app.Action = run
|
||||
app.Version = version
|
||||
app.Version = revision
|
||||
app.Flags = []cli.Flag{
|
||||
|
||||
//
|
||||
@ -81,6 +81,10 @@ func main() {
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"Revision": revision,
|
||||
}).Info("Drone Terraform Plugin Version")
|
||||
|
||||
if c.String("env-file") != "" {
|
||||
_ = godotenv.Load(c.String("env-file"))
|
||||
}
|
||||
|
21
plugin.go
21
plugin.go
@ -6,6 +6,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/sts"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -13,10 +14,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
buildCommit string
|
||||
)
|
||||
|
||||
type (
|
||||
Config struct {
|
||||
Remote Remote
|
||||
@ -41,8 +38,6 @@ type (
|
||||
)
|
||||
|
||||
func (p Plugin) Exec() error {
|
||||
fmt.Printf("Drone Terraform Plugin built from %s\n", buildCommit)
|
||||
|
||||
if p.Config.RoleARN != "" {
|
||||
assumeRole(p.Config.RoleARN)
|
||||
}
|
||||
@ -81,11 +76,11 @@ func (p Plugin) Exec() error {
|
||||
|
||||
err := c.Run()
|
||||
if err != nil {
|
||||
fmt.Println("Error!")
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Fatal("Failed to execute a command")
|
||||
}
|
||||
fmt.Println("Command completed successfully")
|
||||
logrus.Debug("Command completed successfully")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -176,9 +171,9 @@ func assumeRole(roleArn string) {
|
||||
|
||||
value, err := credentials.NewCredentials(stsProvider).Get()
|
||||
if err != nil {
|
||||
fmt.Println("Error assuming role!")
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Fatal("Error assuming role!")
|
||||
}
|
||||
os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID)
|
||||
os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey)
|
||||
|
Loading…
Reference in New Issue
Block a user