|
@ -6,6 +6,7 @@ import ( |
|
|
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" |
|
|
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" |
|
|
"github.com/aws/aws-sdk-go/aws/session" |
|
|
"github.com/aws/aws-sdk-go/aws/session" |
|
|
"github.com/aws/aws-sdk-go/service/sts" |
|
|
"github.com/aws/aws-sdk-go/service/sts" |
|
|
|
|
|
"github.com/Sirupsen/logrus" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"os" |
|
|
"os" |
|
|
"os/exec" |
|
|
"os/exec" |
|
@ -13,10 +14,6 @@ import ( |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
buildCommit string |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type ( |
|
|
type ( |
|
|
Config struct { |
|
|
Config struct { |
|
|
Remote Remote |
|
|
Remote Remote |
|
@ -41,8 +38,6 @@ type ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func (p Plugin) Exec() error { |
|
|
func (p Plugin) Exec() error { |
|
|
fmt.Printf("Drone Terraform Plugin built from %s\n", buildCommit) |
|
|
|
|
|
|
|
|
|
|
|
if p.Config.RoleARN != "" { |
|
|
if p.Config.RoleARN != "" { |
|
|
assumeRole(p.Config.RoleARN) |
|
|
assumeRole(p.Config.RoleARN) |
|
|
} |
|
|
} |
|
@ -81,11 +76,11 @@ func (p Plugin) Exec() error { |
|
|
|
|
|
|
|
|
err := c.Run() |
|
|
err := c.Run() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("Error!") |
|
|
logrus.WithFields(logrus.Fields{ |
|
|
fmt.Println(err) |
|
|
"error": err, |
|
|
os.Exit(1) |
|
|
}).Fatal("Failed to execute a command") |
|
|
} |
|
|
} |
|
|
fmt.Println("Command completed successfully") |
|
|
logrus.Debug("Command completed successfully") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
@ -176,9 +171,9 @@ func assumeRole(roleArn string) { |
|
|
|
|
|
|
|
|
value, err := credentials.NewCredentials(stsProvider).Get() |
|
|
value, err := credentials.NewCredentials(stsProvider).Get() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("Error assuming role!") |
|
|
logrus.WithFields(logrus.Fields{ |
|
|
fmt.Println(err) |
|
|
"error": err, |
|
|
os.Exit(1) |
|
|
}).Fatal("Error assuming role!") |
|
|
} |
|
|
} |
|
|
os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID) |
|
|
os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID) |
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey) |
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey) |
|
|