Skip to content

Commit

Permalink
restore hooks functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun committed Feb 4, 2025
2 parents baf5b92 + 18197b9 commit d14853c
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 18 deletions.
9 changes: 8 additions & 1 deletion cmd/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
cfg "github.com/cloudposse/atmos/pkg/config"
h "github.com/cloudposse/atmos/pkg/hooks"
u "github.com/cloudposse/atmos/pkg/utils"

l "github.com/charmbracelet/log"
)

// terraformCmd represents the base command for all terraform sub-commands
Expand Down Expand Up @@ -56,7 +58,12 @@ func runHooks(event h.HookEvent, cmd *cobra.Command, args []string) error {
return fmt.Errorf("error getting hooks: %w", err)
}

return hooks.RunAll(event, &atmosConfig, &info, cmd, args)
if hooks.HasHooks() {
l.Info("running hooks", "event", event)
return hooks.RunAll(event, &atmosConfig, &info, cmd, args)
}

return nil
}

func init() {
Expand Down
3 changes: 0 additions & 3 deletions cmd/terraform_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"os"

l "github.com/charmbracelet/log"
h "github.com/cloudposse/atmos/pkg/hooks"
"github.com/spf13/cobra"
)
Expand All @@ -30,7 +29,6 @@ func getTerraformCommands() []*cobra.Command {
"nativeCommand": "true",
},
PostRunE: func(cmd *cobra.Command, args []string) error {
l.Info("running hooks", "event", h.AfterTerraformApply)
return runHooks(h.AfterTerraformApply, cmd, args)
},
},
Expand Down Expand Up @@ -64,7 +62,6 @@ Common use cases:
Short: "Deploy the specified infrastructure using Terraform",
Long: `Deploys infrastructure by running the Terraform apply command with automatic approval. This ensures that the changes defined in your Terraform configuration are applied without requiring manual confirmation, streamlining the deployment process.`,
PostRunE: func(cmd *cobra.Command, args []string) error {
l.Info("running hooks", "event", h.AfterTerraformApply)
return runHooks(h.AfterTerraformApply, cmd, args)
},
},
Expand Down
Loading

0 comments on commit d14853c

Please sign in to comment.