diff --git a/internal/meta/base_meta.go b/internal/meta/base_meta.go index 5373f16..16ec4ee 100644 --- a/internal/meta/base_meta.go +++ b/internal/meta/base_meta.go @@ -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{} @@ -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 @@ -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 { diff --git a/internal/meta/meta_dummy.go b/internal/meta/meta_dummy.go index 7c138b2..afaca0a 100644 --- a/internal/meta/meta_dummy.go +++ b/internal/meta/meta_dummy.go @@ -5,6 +5,8 @@ import ( "io" "log/slog" "time" + + "github.com/Azure/aztfexport/pkg/config" ) type MetaGroupDummy struct { @@ -12,8 +14,8 @@ type MetaGroupDummy struct { 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 { @@ -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) { +} diff --git a/pkg/config/config.go b/pkg/config/config.go index 3a5b2bf..d6d3230 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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) diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index b885f6a..a50f01a 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -3,6 +3,7 @@ package meta import ( "context" "fmt" + "github.com/Azure/aztfexport/internal/meta" "github.com/Azure/aztfexport/pkg/config" )