Browse Source

Use logrus for logging messages

pull/26/head
Jacob McCann 8 years ago
parent
commit
ef64a0f2a3
  1. 2
      .drone.yml
  2. 8
      main.go
  3. 21
      plugin.go

2
.drone.yml

@ -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

@ -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

@ -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…
Cancel
Save