briefercloud / layerform

Layerform helps engineers create reusable environment stacks using plain .tf files. Ideal for multiple "staging" environments.

Home Page:https://layerform.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a `--auto-approve` flag to `layerform kill`

vieiralucas opened this issue · comments

Problem:

When using layerform in a script, or CI environment, I want to be able to kill layer instances without having to answer yes to the "are you sure?" question.

Proposal:

Add a --auto-approve flag to the kill command that makes the cli skip the confirmation when killing a layer instance.

This should be an easy one, first thing is to add the flag here:
https://github.com/ergomake/layerform/blob/a4a1cefa32b826efd07900e1b05a9f03c7a3f55f/cmd/cli/kill.go#L17-L21
Something like this

  killCmd.Flags().Bool("auto-approve", false, "skip interactive approval before killing layer instance")

Then, do an if statement over here:
https://github.com/ergomake/layerform/blob/a4a1cefa32b826efd07900e1b05a9f03c7a3f55f/internal/command/kill.go#L185-L194
Something like this:

	if !autoApprove {
		var answer string
		fmt.Print("Are you sure? This can't be undone. [yes/no]: ")
		_, err = fmt.Scan(&answer)
		if err != nil {
			return errors.Wrap(err, "fail to read asnwer")
		}

		if strings.ToLower(strings.TrimSpace(answer)) != "yes" {
			return nil
		}
	}

Besides that, you'll need to pass some arguments around. I'm happy to further assist.

Hi, is this issue still available to been worked on? Can i try to fixed with your suggestions? =]

Hey @hi-hi-ray, yes please. Let me know if you want some help.
I'll assign to you just to let other people know ok?
Thank you in advance!

Hi, I created the PR it worked here, but to ensure that everything it's ok I strongly advise that you test in your local environments. =]