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

Add Set[Pre|Post]ImportHook to BaseMeta interface #548

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions internal/meta/base_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type BaseMeta interface {
// CleanUpWorkspace is a weired method that is only meant to be used internally by aztfexport, which under the hood will remove everything in the output directory, except the generated TF config.
// This method does nothing if HCLOnly in the Config is not set.
CleanUpWorkspace(ctx context.Context) error

SetPreImportHook(config.ImportCallback)
SetPostImportHook(config.ImportCallback)
}

var _ BaseMeta = &baseMeta{}
Expand Down Expand Up @@ -334,11 +337,11 @@ func (meta *baseMeta) ParallelImport(ctx context.Context, items []*ImportItem) e
}
startTime := time.Now()
if meta.preImportHook != nil {
meta.preImportHook(startTime, total, iitem)
meta.preImportHook(startTime, iitem)
}
meta.importItem(ctx, item, i)
if meta.postImportHook != nil {
meta.postImportHook(startTime, total, iitem)
meta.postImportHook(startTime, iitem)
}
}
return i, nil
Expand Down Expand Up @@ -532,6 +535,14 @@ func (meta baseMeta) CleanUpWorkspace(_ context.Context) error {
return nil
}

func (meta *baseMeta) SetPreImportHook(cb config.ImportCallback) {
meta.preImportHook = cb
}

func (meta *baseMeta) SetPostImportHook(cb config.ImportCallback) {
meta.postImportHook = cb
}

func (meta baseMeta) generateCfg(ctx context.Context, l ImportList, cfgTrans ...TFConfigTransformer) error {
cfginfos, err := meta.stateToConfig(ctx, l)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions internal/meta/meta_dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
"io"
"log/slog"
"time"

"github.com/Azure/aztfexport/pkg/config"
)

type MetaGroupDummy struct {
rg string
providerName string
}

func NewGroupMetaDummy(rg string, providerName string) MetaGroupDummy {
return MetaGroupDummy{rg: rg, providerName: providerName}
func NewGroupMetaDummy(rg string, providerName string) *MetaGroupDummy {
return &MetaGroupDummy{rg: rg, providerName: providerName}
}

func (m MetaGroupDummy) Logger() *slog.Logger {
Expand Down Expand Up @@ -96,3 +98,9 @@ func (m MetaGroupDummy) CleanUpWorkspace(_ context.Context) error {
time.Sleep(500 * time.Millisecond)
return nil
}

func (meta *MetaGroupDummy) SetPreImportHook(cb config.ImportCallback) {
}

func (meta *MetaGroupDummy) SetPostImportHook(cb config.ImportCallback) {
}
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ImportItem struct {
TFAddr tfaddr.TFAddr
}

type ImportCallback func(startTime time.Time, total int, item ImportItem)
type ImportCallback func(startTime time.Time, item ImportItem)

type OutputFileNames struct {
// The filename for the generated "terraform.tf" (default)
Expand Down
1 change: 1 addition & 0 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meta
import (
"context"
"fmt"

"github.com/Azure/aztfexport/internal/meta"
"github.com/Azure/aztfexport/pkg/config"
)
Expand Down
Loading