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

feat(gruntwork-io/terragrunt): add output and refresh cmds #142

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions gruntwork-io/terragrunt/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, cache cache.Cache, op
Args: stackArgs,
Execute: inst.execute,
},
{
Name: "refresh",
Description: "Update the state to match remote systems",
Args: stackArgs,
Execute: inst.execute,
},
{
Name: "output",
Description: "Show output values from your root module",
Args: stackArgs,
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Default().String("raw", "", "Print the raw string directly")
return nil
},
Execute: inst.execute,
},
// {
// Name: "command",
// Values: func(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
Expand Down Expand Up @@ -229,11 +245,11 @@ func (c *Command) Help(ctx context.Context, r *readline.Readline) string {
// ------------------------------------------------------------------------------------------------

func (c *Command) secrets(ctx context.Context, r *readline.Readline) error {
env := r.Args().At(0)
site := r.Args().At(1)
envName := r.Args().At(0)
siteName := r.Args().At(1)

// validate stack & change dir
values, err := files.Find(ctx, c.cfg.StacksPath(env, site), "secrets.tpl.yaml", files.FindWithIsFile(true))
values, err := files.Find(ctx, c.cfg.StacksPath(envName, siteName), "secrets.tpl.yaml", files.FindWithIsFile(true))
if err != nil {
return err
}
Expand All @@ -249,8 +265,8 @@ func (c *Command) secrets(ctx context.Context, r *readline.Readline) error {
}

func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
environment := r.Args().At(0)
site := r.Args().At(1)
envName := r.Args().At(0)
siteName := r.Args().At(1)
command := r.Args().At(2)
stacks := r.Args().From(3)

Expand All @@ -259,7 +275,7 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
c.l.Info("└ " + stack)
if err := shell.New(ctx, c.l, "terragrunt", command).
Args(r.AdditionalFlags()...).
Dir(path.Join(c.cfg.StacksPath(environment, site), stack)).
Dir(path.Join(c.cfg.StacksPath(envName, siteName), stack)).
Run(); err != nil {
return err
}
Expand All @@ -275,17 +291,17 @@ func (c *Command) getEnvs(ctx context.Context, r *readline.Readline) []goprompt.
}

func (c *Command) getSites(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
env := r.Args().At(0)
return c.cache.GetSuggests("sites-"+env, func() any {
return suggests.List(c.cfg.SiteNames(env))
envName := r.Args().At(0)
return c.cache.GetSuggests("sites-"+envName, func() any {
return suggests.List(c.cfg.SiteNames(envName))
})
}

func (c *Command) getStacks(ctx context.Context, r *readline.Readline) []goprompt.Suggest {
env := r.Args().At(0)
envName := r.Args().At(0)
site := r.Args().At(1)
return c.cache.GetSuggests("stacks-"+env+"-"+site, func() any {
stacks, err := c.cfg.StackNames(ctx, env, site)
return c.cache.GetSuggests("stacks-"+envName+"-"+site, func() any {
stacks, err := c.cfg.StackNames(ctx, envName, site)
if err != nil {
c.l.Debug("failed to retrieve stacks", zap.Error(err))
}
Expand Down