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

destroy existing infrastructure #9

Merged
merged 4 commits into from
Oct 24, 2019
Merged

destroy existing infrastructure #9

merged 4 commits into from
Oct 24, 2019

Conversation

razzkumar
Copy link
Contributor

No description provided.


import "github.com/leapfrogtechnology/shift/cli/internals/destroy"

// Destroy delete existing infrastructure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deletes*

"github.com/leapfrogtechnology/shift/infrastructure/internals/terraform"
)

// Run initializes new environment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destroys*

os.Exit(1)
}

slack.Notify(project.SlackURL, fmt.Sprintf(" 🎉 🎉 🎉Successfully destroyed *%s* env of *%s* from *%s*. 🎉 🎉 🎉", environment, project.Name, project.Platform), "#04EBB8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not send slack notifications when we are destroying the environment

@@ -17,3 +18,11 @@ func GetFileContentType(filename string) string {

return mime.TypeByExtension("." + ext)
}

// IsExist check existence of file
func IsExist(filepath string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this function Exists instead of IsExist

cmd := exec.Command("terraform", "destroy", "--auto-approve")
cmd.Dir = workspaceDir
// var stdout bytes.Buffer
// var stderr bytes.Buffer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unwanted code

// DestroyInfrastructure destroy existing infrastructure
func DestroyInfrastructure(workspaceDir string) error {
fmt.Println("Distroying Infrastructure...")
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond) // Build our new spinner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create a new spinner?
There's a spinner in the utility as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried but unable to import due to other spinner module that is already imported but now i will modify it and use it


// Run initializes destruction of infrastructure
func Run(environment string) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unwanted line

exit.Error(errors.New("Unknown Environment type "+"'"+environment+"'"), "Error")
}

workspaceRoot := "/tmp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this as constant


if isExist {
terraform.DestroyInfrastructure(workspaceDir)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unwanted line


terraformFile := workspaceDir + "/infrastructure.tf"

isExist := file.Exists(terraformFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name this variable as exists as well

err := cmd.Run()
if err != nil {
fmt.Println()
s.Stop()
fmt.Println(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets avoid using fmt directly and use logger instead.

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
message := " ERROR While Destroying Infrastructure"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be constant as well


spinner.Stop()
return nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unwanted line here


// MakeTempAndDestroy create infrastructure template and distroy the infrastructure
func MakeTempAndDestroy(project structs.Project, environment, workspaceDir string) error {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unwanted line


// DestroyInfrastructure destroys existing infrastructure
func DestroyInfrastructure(workspaceDir string) error {
logger.LogInfo("Distroying Infrastructure...")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destroying*

// Run initializes destruction of infrastructure
func Run(environment string) {

project := storage.Read()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets ask the user Are you sure you want to destroy ${environment} for ${projectName}?
Only after the user types in y, the destruction will take place, otherwise the program should exit.

@pratishshr pratishshr merged commit 6bebf94 into dev Oct 24, 2019
@razzkumar razzkumar deleted the destroy-infra branch October 24, 2019 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants