Skip to content

Commit

Permalink
Actually execute terraform plan
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS-ovm committed Feb 28, 2024
1 parent 90b9a66 commit 9db5990
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions cmd/terraform_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -55,7 +57,7 @@ var terraformPlanCmd = &cobra.Command{
},
}

func TerraformPlan(ctx context.Context, files []string, ready chan bool) int {
func TerraformPlan(ctx context.Context, args []string, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
Expand Down Expand Up @@ -151,7 +153,6 @@ func TerraformPlan(ctx context.Context, files []string, ready chan bool) int {
return 1
}
// reset the environment to the requested value
os.Setenv("AWS_PROFILE", aws_profile)
awsAuthConfig.Strategy = "sso-profile"
awsAuthConfig.Profile = aws_profile

Check failure on line 157 in cmd/terraform_plan.go

View workflow job for this annotation

GitHub Actions / Run Tests

awsAuthConfig.Profile undefined (type "github.com/overmindtech/aws-source/cmd".AwsAuthConfig has no field or method Profile)
case "aws_profile":
Expand Down Expand Up @@ -216,21 +217,40 @@ func TerraformPlan(ctx context.Context, files []string, ready chan bool) int {
}
defer stdlibEngine.Stop()

prompt := `# Doing something
NATS connection: %v
args = append([]string{"plan", "-out", "overmind.plan"}, args...)

prompt := `
* AWS Source: running
* stdlib Source: running
This will be doing something: %vAWS_PROFILE=%v terraform plan -out overmind_plan.out%v
# Planning Changes
Running ` + "`" + `terraform %v` + "`" + `
`
out, err := r.Render(fmt.Sprintf(prompt, awsEngine.IsNATSConnected(), "`", aws_profile, "`"))

out, err := r.Render(fmt.Sprintf(prompt, strings.Join(args, " ")))
if err != nil {
panic(err)
}
fmt.Print(out)

// TODO: remove this debugging aid
err = os.Chdir("/workspace/deploy")
if err != nil {
panic(err)
}

tfPlanCmd := exec.CommandContext(ctx, "terraform", args...)
tfPlanCmd.Stderr = os.Stderr
tfPlanCmd.Stdout = os.Stdout
tfPlanCmd.Stdin = os.Stdin

err = tfPlanCmd.Run()
if err != nil {
log.WithError(err).Error("failed to run terraform plan")
return 1
}

return 0
}

Expand Down

0 comments on commit 9db5990

Please sign in to comment.