-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
cli/cmd/destroy.go
Outdated
|
||
import "github.com/leapfrogtechnology/shift/cli/internals/destroy" | ||
|
||
// Destroy delete existing infrastructure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deletes*
cli/internals/destroy/destroy.go
Outdated
"github.com/leapfrogtechnology/shift/infrastructure/internals/terraform" | ||
) | ||
|
||
// Run initializes new environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destroys*
cli/internals/destroy/destroy.go
Outdated
os.Exit(1) | ||
} | ||
|
||
slack.Notify(project.SlackURL, fmt.Sprintf(" 🎉 🎉 🎉Successfully destroyed *%s* env of *%s* from *%s*. 🎉 🎉 🎉", environment, project.Name, project.Platform), "#04EBB8") |
There was a problem hiding this comment.
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
core/utils/file/file.go
Outdated
@@ -17,3 +18,11 @@ func GetFileContentType(filename string) string { | |||
|
|||
return mime.TypeByExtension("." + ext) | |||
} | |||
|
|||
// IsExist check existence of file | |||
func IsExist(filepath string) bool { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
cli/internals/destroy/destroy.go
Outdated
|
||
// Run initializes destruction of infrastructure | ||
func Run(environment string) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unwanted line
cli/internals/destroy/destroy.go
Outdated
exit.Error(errors.New("Unknown Environment type "+"'"+environment+"'"), "Error") | ||
} | ||
|
||
workspaceRoot := "/tmp" |
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unwanted line
cli/internals/destroy/destroy.go
Outdated
|
||
terraformFile := workspaceDir + "/infrastructure.tf" | ||
|
||
isExist := file.Exists(terraformFile) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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 { | ||
|
There was a problem hiding this comment.
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...") |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
No description provided.