@@ -298,7 +298,7 @@ func (meta *baseMeta) ParallelImport(ctx context.Context, items []*ImportItem) e
298
298
// Ensure the state file is removed after this round import, preparing for the next round.
299
299
defer os .Remove (stateFile )
300
300
301
- log .Printf ( "[DEBUG] Merging terraform state file %s (tfmerge)" , stateFile )
301
+ log .Debug ( " Merging terraform state file (tfmerge)" , "file " , stateFile )
302
302
newState , err := tfmerge .Merge (ctx , meta .tf , meta .baseState , stateFile )
303
303
if err != nil {
304
304
return fmt .Errorf ("failed to merge state file: %v" , err )
@@ -667,12 +667,12 @@ func (meta *baseMeta) initImportDirs() error {
667
667
}
668
668
669
669
func (meta * baseMeta ) initTF (ctx context.Context ) error {
670
- log .Printf ( "[INFO] Init Terraform" )
670
+ log .Info ( " Init Terraform" )
671
671
execPath , err := FindTerraform (ctx )
672
672
if err != nil {
673
673
return fmt .Errorf ("error finding a terraform exectuable: %w" , err )
674
674
}
675
- log .Printf ( "[INFO] Find terraform binary at %s " , execPath )
675
+ log .Info ( "Found terraform binary" , "path " , execPath )
676
676
677
677
newTF := func (dir string ) (* tfexec.Terraform , error ) {
678
678
tf , err := tfexec .NewTerraform (dir , execPath )
@@ -708,7 +708,7 @@ func (meta *baseMeta) initTF(ctx context.Context) error {
708
708
}
709
709
710
710
func (meta * baseMeta ) initProvider (ctx context.Context ) error {
711
- log .Printf ( "[INFO] Init provider" )
711
+ log .Info ( " Init provider" )
712
712
713
713
module , diags := tfconfig .LoadModule (meta .outdir )
714
714
if diags .HasErrors () {
@@ -721,7 +721,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
721
721
}
722
722
723
723
if module .ProviderConfigs [meta .providerName ] == nil {
724
- log .Printf ( "[INFO] Output directory doesn't contain provider setting, create one then" )
724
+ log .Info ( " Output directory doesn't contain provider setting, create one then" )
725
725
cfgFile := filepath .Join (meta .outdir , meta .outputFileNames .ProviderFileName )
726
726
// #nosec G306
727
727
if err := os .WriteFile (cfgFile , []byte (meta .buildProviderConfig ()), 0644 ); err != nil {
@@ -730,7 +730,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
730
730
}
731
731
732
732
if tfblock == nil {
733
- log .Printf ( "[INFO] Output directory doesn't contain terraform block, create one then" )
733
+ log .Info ( " Output directory doesn't contain terraform block, create one then" )
734
734
cfgFile := filepath .Join (meta .outdir , meta .outputFileNames .TerraformFileName )
735
735
// #nosec G306
736
736
if err := os .WriteFile (cfgFile , []byte (meta .buildTerraformConfig (meta .backendType )), 0644 ); err != nil {
@@ -744,7 +744,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
744
744
opts = append (opts , tfexec .BackendConfig (opt ))
745
745
}
746
746
747
- log .Printf ( `[DEBUG] Run "terraform init" for the output directory %s` , meta .outdir )
747
+ log .Debug ( ` Run "terraform init" for the output directory` , "dir" , meta .outdir )
748
748
if err := meta .tf .Init (ctx , opts ... ); err != nil {
749
749
return fmt .Errorf ("error running terraform init for the output directory: %s" , err )
750
750
}
@@ -766,9 +766,9 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
766
766
return nil , fmt .Errorf ("error creating terraform config: %w" , err )
767
767
}
768
768
if meta .devProvider {
769
- log .Printf ( `[DEBUG] Skip running "terraform init" for the import directory (dev provider): %s` , meta .importBaseDirs [i ])
769
+ log .Debug ( ` Skip running "terraform init" for the import directory (dev provider)` , "dir" , meta .importBaseDirs [i ])
770
770
} else {
771
- log .Printf ( `[DEBUG] Run "terraform init" for the import directory %s` , meta .importBaseDirs [i ])
771
+ log .Debug ( ` Run "terraform init" for the import directory` , "dir" , meta .importBaseDirs [i ])
772
772
if err := meta .importTFs [i ].Init (ctx ); err != nil {
773
773
return nil , fmt .Errorf ("error running terraform init: %s" , err )
774
774
}
@@ -785,7 +785,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
785
785
786
786
func (meta * baseMeta ) importItem (ctx context.Context , item * ImportItem , importIdx int ) {
787
787
if item .Skip () {
788
- log .Printf ( "[INFO] Skipping %s " , item .TFResourceId )
788
+ log .Info ( " Skipping resource" , "tf_id " , item .TFResourceId )
789
789
return
790
790
}
791
791
@@ -807,7 +807,7 @@ func (meta *baseMeta) importItem_tf(ctx context.Context, item *ImportItem, impor
807
807
// #nosec G306
808
808
if err := os .WriteFile (cfgFile , []byte (tpl ), 0644 ); err != nil {
809
809
err := fmt .Errorf ("generating resource template file for %s: %w" , item .TFAddr , err )
810
- log .Printf ( "[ERROR] %v " , err )
810
+ log .Error ( "Failed to generate resource template file " , "error" , err , "tf_addr" , item . TFAddr )
811
811
item .ImportError = err
812
812
return
813
813
}
@@ -819,13 +819,13 @@ func (meta *baseMeta) importItem_tf(ctx context.Context, item *ImportItem, impor
819
819
addr = meta .moduleAddr + "." + addr
820
820
}
821
821
822
- log .Printf ( "[INFO] Importing %s as %s" , item .TFResourceId , addr )
822
+ log .Info ( " Importing a resource" , "tf_id" , item .TFResourceId , "tf_addr" , addr )
823
823
// The actual resource type names in telemetry is redacted
824
824
meta .tc .Trace (telemetry .Info , fmt .Sprintf ("Importing %s as %s" , item .AzureResourceID .TypeString (), addr ))
825
825
826
826
err := tf .Import (ctx , addr , item .TFResourceId )
827
827
if err != nil {
828
- log .Printf ( "[ERROR] Importing %s: %v" , item .TFAddr , err )
828
+ log .Error ( "Terraform import failed" , "tf_addr" , item .TFAddr , "error" , err )
829
829
meta .tc .Trace (telemetry .Error , fmt .Sprintf ("Importing %s failed" , item .AzureResourceID .TypeString ()))
830
830
meta .tc .Trace (telemetry .Error , fmt .Sprintf ("Error detail: %v" , err ))
831
831
} else {
@@ -838,7 +838,7 @@ func (meta *baseMeta) importItem_tf(ctx context.Context, item *ImportItem, impor
838
838
func (meta * baseMeta ) importItem_notf (ctx context.Context , item * ImportItem , importIdx int ) {
839
839
// Import resources
840
840
addr := item .TFAddr .String ()
841
- log .Printf ( "[INFO] Importing %s as %s" , item .TFResourceId , addr )
841
+ log .Info ( " Importing a resource" , "tf_id" , item .TFResourceId , "tf_addr" , addr )
842
842
// The actual resource type names in telemetry is redacted
843
843
meta .tc .Trace (telemetry .Info , fmt .Sprintf ("Importing %s as %s" , item .AzureResourceID .TypeString (), addr ))
844
844
@@ -847,7 +847,7 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
847
847
ID : item .TFResourceId ,
848
848
})
849
849
if diags .HasErrors () {
850
- log .Printf ( "[ERROR] Importing %s: %v" , item .TFAddr , diags )
850
+ log .Error ( "Terraform import failed" , "tf_addr" , item .TFAddr , "error" , diags . Err () )
851
851
meta .tc .Trace (telemetry .Error , fmt .Sprintf ("Importing %s failed" , item .AzureResourceID .TypeString ()))
852
852
meta .tc .Trace (telemetry .Error , fmt .Sprintf ("Error detail: %v" , diags .Err ()))
853
853
item .ImportError = diags .Err ()
@@ -856,7 +856,7 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
856
856
}
857
857
if len (importResp .ImportedResources ) != 1 {
858
858
err := fmt .Errorf ("expect 1 resource being imported, got=%d" , len (importResp .ImportedResources ))
859
- log .Printf ( "[ERROR] %s" , err )
859
+ log .Error ( err . Error () )
860
860
meta .tc .Trace (telemetry .Error , err .Error ())
861
861
item .ImportError = err
862
862
item .Imported = false
@@ -869,7 +869,7 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
869
869
Private : res .Private ,
870
870
})
871
871
if diags .HasErrors () {
872
- log .Printf ( "[ERROR] Reading %s: %v " , item .TFAddr , diags )
872
+ log .Error ( "Terraform read a resource failed " , "tf_addr" , item .TFAddr , "error" , diags . Err () )
873
873
meta .tc .Trace (telemetry .Error , fmt .Sprintf ("Reading %s failed" , item .AzureResourceID .TypeString ()))
874
874
meta .tc .Trace (telemetry .Error , fmt .Sprintf ("Error detail: %v" , diags .Err ()))
875
875
item .ImportError = diags .Err ()
0 commit comments