@@ -10,7 +10,6 @@ import (
10
10
"path/filepath"
11
11
"strings"
12
12
13
- "github.com/hashicorp/go-version"
14
13
tfjson "github.com/hashicorp/terraform-json"
15
14
16
15
"github.com/Azure/aztfexport/pkg/config"
@@ -78,21 +77,22 @@ type BaseMeta interface {
78
77
var _ BaseMeta = & baseMeta {}
79
78
80
79
type baseMeta struct {
81
- subscriptionId string
82
- azureSDKCred azcore.TokenCredential
83
- azureSDKClientOpt arm.ClientOptions
84
- outdir string
85
- outputFileNames config.OutputFileNames
86
- tf * tfexec.Terraform
87
- resourceClient * armresources.Client
88
- providerVersion string
89
- devProvider bool
90
- providerName string
91
- backendType string
92
- backendConfig []string
93
- providerConfig map [string ]cty.Value
94
- fullConfig bool
95
- parallelism int
80
+ subscriptionId string
81
+ azureSDKCred azcore.TokenCredential
82
+ azureSDKClientOpt arm.ClientOptions
83
+ outdir string
84
+ outputFileNames config.OutputFileNames
85
+ tf * tfexec.Terraform
86
+ resourceClient * armresources.Client
87
+ providerVersion string
88
+ devProvider bool
89
+ providerName string
90
+ backendType string
91
+ backendConfig []string
92
+ providerConfig map [string ]cty.Value
93
+ fullConfig bool
94
+ parallelism int
95
+ generateImportFile bool
96
96
97
97
hclOnly bool
98
98
tfclient tfclient.Client
@@ -202,22 +202,23 @@ func NewBaseMeta(cfg config.CommonConfig) (*baseMeta, error) {
202
202
}
203
203
204
204
meta := & baseMeta {
205
- subscriptionId : cfg .SubscriptionId ,
206
- azureSDKCred : cfg .AzureSDKCredential ,
207
- azureSDKClientOpt : cfg .AzureSDKClientOption ,
208
- outdir : cfg .OutputDir ,
209
- outputFileNames : outputFileNames ,
210
- resourceClient : resClient ,
211
- providerVersion : cfg .ProviderVersion ,
212
- devProvider : cfg .DevProvider ,
213
- backendType : cfg .BackendType ,
214
- backendConfig : cfg .BackendConfig ,
215
- providerConfig : cfg .ProviderConfig ,
216
- providerName : cfg .ProviderName ,
217
- fullConfig : cfg .FullConfig ,
218
- parallelism : cfg .Parallelism ,
219
- hclOnly : cfg .HCLOnly ,
220
- tfclient : cfg .TFClient ,
205
+ subscriptionId : cfg .SubscriptionId ,
206
+ azureSDKCred : cfg .AzureSDKCredential ,
207
+ azureSDKClientOpt : cfg .AzureSDKClientOption ,
208
+ outdir : cfg .OutputDir ,
209
+ outputFileNames : outputFileNames ,
210
+ resourceClient : resClient ,
211
+ providerVersion : cfg .ProviderVersion ,
212
+ devProvider : cfg .DevProvider ,
213
+ backendType : cfg .BackendType ,
214
+ backendConfig : cfg .BackendConfig ,
215
+ providerConfig : cfg .ProviderConfig ,
216
+ providerName : cfg .ProviderName ,
217
+ fullConfig : cfg .FullConfig ,
218
+ parallelism : cfg .Parallelism ,
219
+ generateImportFile : cfg .GenerateImportBlock ,
220
+ hclOnly : cfg .HCLOnly ,
221
+ tfclient : cfg .TFClient ,
221
222
222
223
moduleAddr : moduleAddr ,
223
224
moduleDir : moduleDir ,
@@ -402,18 +403,7 @@ func (meta baseMeta) ExportResourceMapping(ctx context.Context, l ImportList) er
402
403
return fmt .Errorf ("writing the resource mapping to %s: %v" , oMapFile , err )
403
404
}
404
405
405
- // Only generate import.tf when the current using terraform supports plannable import
406
- var supportPlannableImport bool
407
- if meta .tf == nil {
408
- supportPlannableImport = true
409
- } else {
410
- ver , _ , err := meta .tf .Version (ctx , true )
411
- if err != nil {
412
- return fmt .Errorf ("getting terraform version" )
413
- }
414
- supportPlannableImport = ver .GreaterThanOrEqual (version .Must (version .NewVersion ("v1.5.0" )))
415
- }
416
- if supportPlannableImport {
406
+ if meta .generateImportFile {
417
407
f := hclwrite .NewFile ()
418
408
body := f .Body ()
419
409
for _ , item := range l {
@@ -433,6 +423,7 @@ func (meta baseMeta) ExportResourceMapping(ctx context.Context, l ImportList) er
433
423
return fmt .Errorf ("writing the import block to %s: %v" , oImportFile , err )
434
424
}
435
425
}
426
+
436
427
return nil
437
428
}
438
429
0 commit comments