Skip to content

Commit

Permalink
update terragrunt path
Browse files Browse the repository at this point in the history
  • Loading branch information
denis256 committed Dec 20, 2024
1 parent 231303f commit a532787
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cli/commands/stack/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ package stack

import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/gruntwork-io/terragrunt/config"
getter "github.com/hashicorp/go-getter/v2"

"github.com/gruntwork-io/terragrunt/internal/errors"
"github.com/gruntwork-io/terragrunt/options"
)

const (
generate = "generate"
generate = "generate"
stackCacheDir = ".terragrunt-stack"
)

func Run(ctx context.Context, opts *options.TerragruntOptions, subCommand string) error {
Expand All @@ -27,6 +34,35 @@ func Run(ctx context.Context, opts *options.TerragruntOptions, subCommand string
}

func generateStack(ctx context.Context, opts *options.TerragruntOptions) error {
//TODO: update stack path
opts.TerragrungStackConfigPath = filepath.Join(opts.WorkingDir, "terragrunt.stack.hcl")
stackFile, err := config.ReadStackConfigFile(ctx, opts)
if err != nil {
return err
}

if err := processStackFile(ctx, stackFile); err != nil {
return err
}

return nil
}
func processStackFile(ctx context.Context, stackFile *config.StackConfigFile) error {
if err := os.MkdirAll(stackCacheDir, 0755); err != nil {
return errors.New(fmt.Errorf("failed to create base directory: %w", err))
}

for _, unit := range stackFile.Units {
destPath := filepath.Join(stackCacheDir, unit.Path)

if err := os.MkdirAll(destPath, 0755); err != nil {
return errors.New(fmt.Errorf("failed to create destination directory '%s': %w", destPath, err))
}

if _, err := getter.GetAny(ctx, unit.Source, destPath); err != nil {
return errors.New(fmt.Errorf("failed to fetch source '%s' to destination '%s': %w", unit.Source, destPath, err))
}
}

return nil
}

0 comments on commit a532787

Please sign in to comment.