Skip to content

Commit

Permalink
Removed cost command, minor code changes , check cmd is now a method …
Browse files Browse the repository at this point in the history
…of the stacks struct
  • Loading branch information
Shaun authored and Shaun committed Mar 13, 2017
1 parent d9271e1 commit 9d4bc57
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 53 deletions.
22 changes: 0 additions & 22 deletions cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,6 @@ func Exports(session *session.Session) error {
return nil
}

// Check - Validates Cloudformation Templates
func Check(template string, session *session.Session) error {
svc := cloudformation.New(session)
params := &cloudformation.ValidateTemplateInput{
TemplateBody: aws.String(template),
}

Log(fmt.Sprintf("Calling [ValidateTemplate] with parameters:\n%s"+"\n--\n", params), level.debug)
resp, err := svc.ValidateTemplate(params)
if err != nil {
return err
}

fmt.Printf(
"%s\n\n%s"+"\n",
colorString("Valid!", "green"),
resp.GoString(),
)

return nil
}

// DeployHandler - Handles deploying stacks in the corrcet order
func DeployHandler() {
// status - pending, failed, completed
Expand Down
14 changes: 5 additions & 9 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,17 @@ var checkCmd = &cobra.Command{
return
}

stk := stack{name: s}
stk.setStackName()
stk.template = tpl

sess, err := awsSession()
if err != nil {
handleError(err)
return
}

if err := Check(tpl, sess); err != nil {
if err := stk.check(sess); err != nil {
handleError(err)
return
}
Expand Down Expand Up @@ -509,11 +513,3 @@ var tailCmd = &cobra.Command{
wg.Wait() // Will probably wait forevery
},
}

var costCmd = &cobra.Command{
Use: "cost",
Short: "Estimate stack/project Cost based on templates",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(colorString("Coming Soon....", "magenta"))
},
}
32 changes: 10 additions & 22 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,15 @@ func Log(msg, lvl string) {

func init() {

// Define Generate Flags
generateCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")
generateCmd.Flags().StringVarP(&job.tplFile, "template", "t", "template", "path to template file Or stack::url")

// Define Deploy Flags
deployCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")
deployCmd.Flags().StringArrayVarP(&job.tplFiles, "template", "t", []string{`./templates/*`}, "path to template file(s) Or stack::url")

// Define Terminate Flags
terminateCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")
terminateCmd.Flags().BoolVarP(&job.terminateAll, "all", "A", false, "terminate all stacks")

// Define Status Flags
statusCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")

// Define Output Flags
outputsCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path. to config file")
outputsCmd.Flags().StringVarP(&job.profile, "profile", "p", "default", "configured aws profile")

// Define Update Flags
updateCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")
updateCmd.Flags().StringVarP(&job.tplFile, "template", "t", "", "path to template file Or stack::url [Required]")

// Define Check Flags
checkCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")
checkCmd.Flags().StringVarP(&job.tplFile, "template", "t", "template", "path to template file Or stack::url")

// Define Exports Flags
exportsCmd.Flags().StringVarP(&region, "region", "r", "eu-west-1", "AWS Region")

Expand All @@ -86,9 +68,6 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&job.profile, "profile", "p", "default", "configured aws profile")
rootCmd.PersistentFlags().BoolVarP(&job.debug, "debug", "", false, "Run in debug mode...")

// Define Tail Flags
tailCmd.Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")

// Define Invoke Flags
invokeCmd.Flags().StringVarP(&region, "region", "r", "eu-west-1", "AWS Region")

Expand All @@ -99,6 +78,16 @@ func init() {
desc,
)

// Add Config --config common flag
for _, cmd := range []interface{}{tailCmd, checkCmd, updateCmd, outputsCmd, statusCmd, terminateCmd, generateCmd, deployCmd} {
cmd.(*cobra.Command).Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file")
}

// Add Template --template common flag
for _, cmd := range []interface{}{generateCmd, updateCmd, checkCmd} {
cmd.(*cobra.Command).Flags().StringVarP(&job.tplFile, "template", "t", "template", "path to template file Or stack::url")
}

for _, cmd := range []interface{}{create, list, rm, execute, desc} {
cmd.(*cobra.Command).Flags().StringVarP(&job.cfgFile, "config", "c", "config.yml", "path to config file [Required]")
cmd.(*cobra.Command).Flags().StringVarP(&job.stackName, "stack", "s", "", "Qaz local project Stack Name [Required]")
Expand All @@ -112,7 +101,6 @@ func init() {
statusCmd, outputsCmd, initCmd,
updateCmd, checkCmd, exportsCmd,
invokeCmd, tailCmd, changeCmd,
costCmd,
)

// Setup logging
Expand Down
44 changes: 44 additions & 0 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,47 @@ func (s *stack) change(session *session.Session, req string) error {

return nil
}

func (s *stack) cost(session *session.Session) error {
svc := cloudformation.New(session)

params := &cloudformation.EstimateTemplateCostInput{
TemplateBody: aws.String(s.template),
}

// NOTE: Add parameters flag here if params set
if len(s.parameters) > 0 {
params.Parameters = s.parameters
}

resp, err := svc.EstimateTemplateCost(params)
if err != nil {
return err
}

fmt.Println(resp.GoString())

return nil
}

func (s *stack) check(session *session.Session) error {
svc := cloudformation.New(session)

params := &cloudformation.ValidateTemplateInput{
TemplateBody: aws.String(s.template),
}

Log(fmt.Sprintf("Calling [ValidateTemplate] with parameters:\n%s"+"\n--\n", params), level.debug)
resp, err := svc.ValidateTemplate(params)
if err != nil {
return err
}

fmt.Printf(
"%s\n\n%s"+"\n",
colorString("Valid!", "green"),
resp.GoString(),
)

return nil
}

0 comments on commit 9d4bc57

Please sign in to comment.