Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support atmos terraform apply --from-plan with additional flags #684

Merged
Merged
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
23 changes: 14 additions & 9 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,7 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
case "refresh":
allArgsAndFlags = append(allArgsAndFlags, []string{varFileFlag, varFile}...)
case "apply":
if info.UseTerraformPlan {
if info.PlanFile != "" {
// If the planfile name was passed on the command line, use it
allArgsAndFlags = append(allArgsAndFlags, []string{info.PlanFile}...)
} else {
// Otherwise, use the planfile name what is autogenerated by Atmos
allArgsAndFlags = append(allArgsAndFlags, []string{planFile}...)
}
} else {
if !info.UseTerraformPlan {
allArgsAndFlags = append(allArgsAndFlags, []string{varFileFlag, varFile}...)
}
case "init":
Expand All @@ -370,6 +362,19 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {

allArgsAndFlags = append(allArgsAndFlags, info.AdditionalArgsAndFlags...)

// Add any args we're generating -- terraform is picky about ordering flags
// and args, so these args need to go after any flags, including those
// specified in AdditionalArgsAndFlags.
if info.SubCommand == "apply" && info.UseTerraformPlan {
if info.PlanFile != "" {
// If the planfile name was passed on the command line, use it
allArgsAndFlags = append(allArgsAndFlags, []string{info.PlanFile}...)
} else {
// Otherwise, use the planfile name what is autogenerated by Atmos
allArgsAndFlags = append(allArgsAndFlags, []string{planFile}...)
}
}

// Run `terraform workspace` before executing other terraform commands
// only if the `TF_WORKSPACE` environment variable is not set by the caller
if info.SubCommand != "init" && !(info.SubCommand == "workspace" && info.SubCommand2 != "") {
Expand Down
Loading