Skip to content

Commit

Permalink
feat: adds --skip-init flag
Browse files Browse the repository at this point in the history
fix: adds SkipInitFlag to commonFlags so as to not pass down to command

docs: adds --skip-init to `atmos terraform --help` docs
  • Loading branch information
Gowiem committed Sep 9, 2022
1 parent 9189ae8 commit c2f4781
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/exec/help.go
Expand Up @@ -18,6 +18,8 @@ func processHelp(componentType string, command string) error {
fmt.Println()
u.PrintInfo("Additions and differences from native terraform:")
fmt.Println(" - before executing other 'terraform' commands, 'atmos' calls 'terraform init'")
fmt.Println(" - you can skip over atmos calling 'terraform init' if you know your project is already in a good working state by using " +
"the '--skip-init' flag like so 'atmos terraform <command> <component> -s <stack> --skip-init")
fmt.Println(" - 'atmos terraform deploy' command executes 'terraform plan' and then 'terraform apply'")
fmt.Println(" - 'atmos terraform deploy' command supports '--deploy-run-init=true/false' flag to enable/disable running 'terraform init' " +
"before executing the command")
Expand Down
7 changes: 7 additions & 0 deletions internal/exec/terraform.go
Expand Up @@ -173,6 +173,13 @@ func ExecuteTerraform(cmd *cobra.Command, args []string) error {
(info.SubCommand == "deploy" && !c.Config.Components.Terraform.DeployRunInit) {
runTerraformInit = false
}

if info.SkipInit {
fmt.Println()
u.PrintInfo("Skipping over `terraform init` due to `--skip-init` being passed.")
runTerraformInit = false
}

if runTerraformInit {
initCommandWithArguments := []string{"init"}
if info.SubCommand == "workspace" || c.Config.Components.Terraform.InitRunReconfigure {
Expand Down
8 changes: 8 additions & 0 deletions internal/exec/utils.go
Expand Up @@ -13,10 +13,13 @@ import (
)

var (
// `commonFlags` are a list of flags that atmos understands but the underlying tools do not (e.g. terraform, helmfile, etc.)
// These flags get removed from the arg list after atmos uses them so the underlying tool does not get passed a flag it doesn't accept.
commonFlags = []string{
"--stack",
"-s",
g.DryRunFlag,
g.SkipInitFlag,
g.KubeConfigConfigFlag,
g.TerraformDirFlag,
g.HelmfileDirFlag,
Expand Down Expand Up @@ -175,6 +178,7 @@ func processArgsConfigAndStacks(componentType string, cmd *cobra.Command, args [
configAndStacksInfo.AutoGenerateBackendFile = argsAndFlagsInfo.AutoGenerateBackendFile
configAndStacksInfo.UseTerraformPlan = argsAndFlagsInfo.UseTerraformPlan
configAndStacksInfo.DryRun = argsAndFlagsInfo.DryRun
configAndStacksInfo.SkipInit = argsAndFlagsInfo.SkipInit
configAndStacksInfo.NeedHelp = argsAndFlagsInfo.NeedHelp

// Check if `-h` or `--help` flags are specified
Expand Down Expand Up @@ -566,6 +570,10 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (c.Ar
info.DryRun = true
}

if arg == g.SkipInitFlag {
info.SkipInit = true
}

if arg == g.HelpFlag1 || arg == g.HelpFlag2 {
info.NeedHelp = true
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/schema.go
Expand Up @@ -88,6 +88,7 @@ type ArgsAndFlagsInfo struct {
AutoGenerateBackendFile string
UseTerraformPlan bool
DryRun bool
SkipInit bool
NeedHelp bool
}

Expand Down Expand Up @@ -125,6 +126,7 @@ type ConfigAndStacksInfo struct {
AutoGenerateBackendFile string
UseTerraformPlan bool
DryRun bool
SkipInit bool
ComponentInheritanceChain []string
NeedHelp bool
ComponentIsAbstract bool
Expand Down
1 change: 1 addition & 0 deletions pkg/globals/globals.go
Expand Up @@ -24,6 +24,7 @@ const (

FromPlanFlag = "--from-plan"
DryRunFlag = "--dry-run"
SkipInitFlag = "--skip-init"

HelpFlag1 = "-h"
HelpFlag2 = "--help"
Expand Down

0 comments on commit c2f4781

Please sign in to comment.