Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cmd/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var terraformCmd = &cobra.Command{
Use: "terraform",
GroupID: "iac",
Short: "Run Terrafrom with Overmind's risk analysis and change tracking",
Short: "Run Terraform with Overmind's risk analysis and change tracking",
Long: `By using 'overmind terraform plan/apply' in place of your normal
'terraform plan/apply' commands, you can get a risk analysis and change
tracking for your Terraform changes with no extra effort.
Expand All @@ -36,6 +36,11 @@ var applyOnlyArgs = []string{
"auto-approve",
}

var planOnlyArgs = []string{
"var",
"var-file",
}

// planArgsFromApplyArgs filters out all apply-specific arguments from arguments
// to `terraform apply`, so that we can run the corresponding `terraform plan`
// command
Expand All @@ -55,3 +60,21 @@ append:
}
return planArgs
}

// applyArgsFromApplyArgs filters out all plan-specific arguments from arguments to `terraform apply`, so that we can run the corresponding `terraform apply` command
func applyArgsFromApplyArgs(args []string) []string {
applyArgs := []string{}
append:
for _, arg := range args {
for _, planOnlyArg := range planOnlyArgs {
if strings.HasPrefix(arg, "-"+planOnlyArg) {
continue append
}
if strings.HasPrefix(arg, "--"+planOnlyArg) {
continue append
}
}
applyArgs = append(applyArgs, arg)
}
return applyArgs
}
4 changes: 3 additions & 1 deletion cmd/terraform_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ func TerraformApplyImpl(ctx context.Context, cmd *cobra.Command, oi sdp.Overmind
return err
}

err = RunApply(ctx, args)
// apply the args filtering here, after providers have been configured above
// (which might still need --var and --var-file information)
err = RunApply(ctx, applyArgsFromApplyArgs(args))
if err != nil {
return err
}
Expand Down
Loading