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

feat: adds --skip-init flag #193

Merged
merged 1 commit into from Sep 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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