address comments round 1

This commit is contained in:
Shreyas Goenka 2023-04-20 01:00:53 +02:00
parent f8d3c1d50c
commit 6170289a49
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
6 changed files with 33 additions and 29 deletions

View File

@ -28,10 +28,10 @@ func (w *apply) Name() string {
func (w *apply) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
// return early if plan is empty
if b.Plan.IsEmpty {
if w.goal == ApplyDeploy {
switch w.goal {
case ApplyDeploy:
cmdio.LogString(ctx, "No resource changes to apply. Skipping deploy!")
}
if w.goal == ApplyDestroy {
case ApplyDestroy:
cmdio.LogString(ctx, "No resources to destroy in plan. Skipping destroy!")
}
return nil, nil
@ -72,10 +72,10 @@ func (w *apply) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator,
return nil, fmt.Errorf("no plan found")
}
if w.goal == ApplyDeploy {
switch w.goal {
case ApplyDeploy:
cmdio.LogString(ctx, "\nStarting resource deployment")
}
if w.goal == ApplyDestroy {
case ApplyDestroy:
cmdio.LogString(ctx, "\nStarting resource destruction")
}
@ -85,10 +85,10 @@ func (w *apply) Apply(ctx context.Context, b *bundle.Bundle) ([]bundle.Mutator,
return nil, fmt.Errorf("terraform apply: %w", err)
}
if w.goal == ApplyDeploy {
switch w.goal {
case ApplyDeploy:
cmdio.LogString(ctx, "Successfully deployed resources!")
}
if w.goal == ApplyDestroy {
case ApplyDestroy:
cmdio.LogString(ctx, "Successfully destroyed resources!")
}
return nil, nil

View File

@ -22,11 +22,11 @@ const (
ActionUpdate = Action("update")
ActionDelete = Action("delete")
ActionReplace = Action("replace")
ActionNoop = Action("no-op")
ActionNoOp = Action("no-op")
)
func toAction(actions tfjson.Actions) Action {
action := ActionNoop
action := ActionNoOp
switch {
case actions.Create():
action = ActionCreate

View File

@ -19,9 +19,9 @@ func Deploy() bundle.Mutator {
terraform.Interpolate(),
terraform.Write(),
terraform.StatePull(),
terraform.Plan("deploy"),
terraform.Plan(terraform.PlanDeploy),
terraform.ShowPlan(),
terraform.Apply("deploy"),
terraform.Apply(terraform.ApplyDeploy),
terraform.StatePush(),
lock.Release(),
},

View File

@ -14,9 +14,9 @@ func Destroy() bundle.Mutator {
[]bundle.Mutator{
lock.Acquire(),
terraform.StatePull(),
terraform.Plan("destroy"),
terraform.Plan(terraform.PlanDestroy),
terraform.ShowPlan(),
terraform.Apply("destroy"),
terraform.Apply(terraform.ApplyDestroy),
terraform.StatePush(),
lock.Release(),
files.Delete(),

View File

@ -23,14 +23,14 @@ var deployCmd = &cobra.Command{
b := bundle.Get(cmd.Context())
// If `--force` is specified, force acquisition of the deployment lock.
b.Config.Bundle.Lock.Force = force
b.Config.Bundle.Lock.Force = forceDeploy
// If `--auto-approve`` is specified, we skip confirmation checks
b.AutoApprove = autoApprove
b.AutoApprove = autoApproveDeploy
// we require auto-approve for non tty terminals since interactive consent
// is not possible
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApprove {
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApproveDeploy {
return fmt.Errorf("please specify --auto-approve to skip interactive confirmation checks for non tty consoles")
}
@ -39,7 +39,7 @@ var deployCmd = &cobra.Command{
if !ok {
return fmt.Errorf("progress logger not found")
}
if logger.Mode == flags.ModeJson && !autoApprove {
if logger.Mode == flags.ModeJson && !autoApproveDeploy {
return fmt.Errorf("please specify --auto-approve since selected logging format is json")
}
@ -51,12 +51,12 @@ var deployCmd = &cobra.Command{
},
}
var force bool
var forceDeploy bool
var autoApprove bool
var autoApproveDeploy bool
func init() {
AddCommand(deployCmd)
deployCmd.Flags().BoolVar(&force, "force", false, "Force acquisition of deployment lock.")
deployCmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals")
deployCmd.Flags().BoolVar(&forceDeploy, "force", false, "Force acquisition of deployment lock.")
deployCmd.Flags().BoolVar(&autoApproveDeploy, "auto-approve", false, "Skip interactive approvals")
}

View File

@ -23,14 +23,14 @@ var destroyCmd = &cobra.Command{
b := bundle.Get(ctx)
// If `--force` is specified, force acquisition of the deployment lock.
b.Config.Bundle.Lock.Force = force
b.Config.Bundle.Lock.Force = forceDestroy
// If `--auto-approve`` is specified, we skip confirmation checks
b.AutoApprove = autoApprove
b.AutoApprove = autoApproveDestroy
// we require auto-approve for non tty terminals since interactive consent
// is not possible
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApprove {
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApproveDestroy {
return fmt.Errorf("please specify --auto-approve to skip interactive confirmation checks for non tty consoles")
}
@ -39,7 +39,7 @@ var destroyCmd = &cobra.Command{
if !ok {
return fmt.Errorf("progress logger not found")
}
if logger.Mode == flags.ModeJson && !autoApprove {
if logger.Mode == flags.ModeJson && !autoApproveDestroy {
return fmt.Errorf("please specify --auto-approve since selected logging format is json")
}
@ -51,8 +51,12 @@ var destroyCmd = &cobra.Command{
},
}
var forceDestroy bool
var autoApproveDestroy bool
func init() {
AddCommand(destroyCmd)
destroyCmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals")
destroyCmd.Flags().BoolVar(&force, "force", false, "Force acquisition of deployment lock.")
destroyCmd.Flags().BoolVar(&autoApproveDestroy, "auto-approve", false, "Skip interactive approvals")
destroyCmd.Flags().BoolVar(&forceDestroy, "force", false, "Force acquisition of deployment lock.")
}