0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-22 00:30:40 +00:00

(Mostly) alphabetize functions

This commit is contained in:
Jacob McCann 2018-02-14 09:47:07 -06:00
parent 0faae5eb94
commit 5401f4f43f

160
plugin.go
View File

@ -125,13 +125,6 @@ func (p Plugin) Exec() error {
return nil return nil
} }
func installCaCert(cacert string) *exec.Cmd {
ioutil.WriteFile("/usr/local/share/ca-certificates/ca_cert.crt", []byte(cacert), 0644)
return exec.Command(
"update-ca-certificates",
)
}
// CopyTfEnv creates copies of TF_VAR_ to lowercase // CopyTfEnv creates copies of TF_VAR_ to lowercase
func CopyTfEnv() { func CopyTfEnv() {
tfVar := regexp.MustCompile(`^TF_VAR_.*$`) tfVar := regexp.MustCompile(`^TF_VAR_.*$`)
@ -144,6 +137,27 @@ func CopyTfEnv() {
} }
} }
func assumeRole(roleArn string) {
client := sts.New(session.New())
duration := time.Hour * 1
stsProvider := &stscreds.AssumeRoleProvider{
Client: client,
Duration: duration,
RoleARN: roleArn,
RoleSessionName: "drone",
}
value, err := credentials.NewCredentials(stsProvider).Get()
if err != nil {
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)
os.Setenv("AWS_SESSION_TOKEN", value.SessionToken)
}
func deleteCache() *exec.Cmd { func deleteCache() *exec.Cmd {
return exec.Command( return exec.Command(
"rm", "rm",
@ -152,6 +166,13 @@ func deleteCache() *exec.Cmd {
) )
} }
func getModules() *exec.Cmd {
return exec.Command(
"terraform",
"get",
)
}
func initCommand(config InitOptions) *exec.Cmd { func initCommand(config InitOptions) *exec.Cmd {
args := []string{ args := []string{
"init", "init",
@ -180,64 +201,15 @@ func initCommand(config InitOptions) *exec.Cmd {
) )
} }
func getModules() *exec.Cmd { func installCaCert(cacert string) *exec.Cmd {
ioutil.WriteFile("/usr/local/share/ca-certificates/ca_cert.crt", []byte(cacert), 0644)
return exec.Command( return exec.Command(
"terraform", "update-ca-certificates",
"get",
) )
} }
func tfValidate(config Config) *exec.Cmd { func trace(cmd *exec.Cmd) {
args := []string{ fmt.Println("$", strings.Join(cmd.Args, " "))
"validate",
}
for _, v := range config.VarFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v))
}
for k, v := range config.Vars {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))
}
return exec.Command(
"terraform",
args...,
)
}
func tfPlan(config Config, destroy bool) *exec.Cmd {
args := []string{
"plan",
}
if destroy {
args = append(args, "-destroy")
} else {
args = append(args, "-out=plan.tfout")
}
for _, v := range config.Targets {
args = append(args, "--target", fmt.Sprintf("%s", v))
}
for _, v := range config.VarFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v))
}
for k, v := range config.Vars {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))
}
if config.Parallelism > 0 {
args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism))
}
if config.InitOptions.Lock != nil {
args = append(args, fmt.Sprintf("-lock=%t", *config.InitOptions.Lock))
}
if config.InitOptions.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
return exec.Command(
"terraform",
args...,
)
} }
func tfApply(config Config) *exec.Cmd { func tfApply(config Config) *exec.Cmd {
@ -286,27 +258,55 @@ func tfDestroy(config Config) *exec.Cmd {
) )
} }
func assumeRole(roleArn string) { func tfPlan(config Config, destroy bool) *exec.Cmd {
client := sts.New(session.New()) args := []string{
duration := time.Hour * 1 "plan",
stsProvider := &stscreds.AssumeRoleProvider{
Client: client,
Duration: duration,
RoleARN: roleArn,
RoleSessionName: "drone",
} }
value, err := credentials.NewCredentials(stsProvider).Get() if destroy {
if err != nil { args = append(args, "-destroy")
logrus.WithFields(logrus.Fields{ } else {
"error": err, args = append(args, "-out=plan.tfout")
}).Fatal("Error assuming role!")
}
os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID)
os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey)
os.Setenv("AWS_SESSION_TOKEN", value.SessionToken)
} }
func trace(cmd *exec.Cmd) { for _, v := range config.Targets {
fmt.Println("$", strings.Join(cmd.Args, " ")) args = append(args, "--target", fmt.Sprintf("%s", v))
}
for _, v := range config.VarFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v))
}
for k, v := range config.Vars {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))
}
if config.Parallelism > 0 {
args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism))
}
if config.InitOptions.Lock != nil {
args = append(args, fmt.Sprintf("-lock=%t", *config.InitOptions.Lock))
}
if config.InitOptions.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
return exec.Command(
"terraform",
args...,
)
}
func tfValidate(config Config) *exec.Cmd {
args := []string{
"validate",
}
for _, v := range config.VarFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v))
}
for k, v := range config.Vars {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))
}
return exec.Command(
"terraform",
args...,
)
} }