@@ -13,6 +13,7 @@ import (
13
13
"github.com/scaleway/scaleway-cli/v2/internal/gofields"
14
14
"github.com/scaleway/scaleway-cli/v2/internal/human"
15
15
"github.com/scaleway/scaleway-cli/v2/internal/terraform"
16
+ "github.com/scaleway/scaleway-sdk-go/scw"
16
17
)
17
18
18
19
// Type defines an formatter format.
@@ -44,8 +45,12 @@ const (
44
45
// Option to enable pretty output on json printer.
45
46
PrinterOptJSONPretty = "pretty"
46
47
47
- // Option to enable pretty output on json printer.
48
- PrinterOptTerraformWithChildren = "with-children"
48
+ // Option to disable parents output on terraform printer.
49
+ PrinterOptTerraformSkipParents = "skip-parents"
50
+ // Option to disable children output on terraform printer.
51
+ PrinterOptTerraformSkipChildren = "skip-children"
52
+ // Option to disable parents and children output on terraform printer.
53
+ PrinterOptTerraformSkipParentsAndChildren = "skip-parents-and-children"
49
54
)
50
55
51
56
type PrinterConfig struct {
@@ -115,11 +120,16 @@ func setupJSONPrinter(printer *Printer, opts string) error {
115
120
func setupTerraformPrinter (printer * Printer , opts string ) error {
116
121
printer .printerType = PrinterTypeTerraform
117
122
switch opts {
118
- case PrinterOptTerraformWithChildren :
119
- printer .terraformWithChildren = true
123
+ case PrinterOptTerraformSkipParents :
124
+ printer .terraformSkipParents = true
125
+ case PrinterOptTerraformSkipChildren :
126
+ printer .terraformSkipChildren = true
127
+ case PrinterOptTerraformSkipParentsAndChildren :
128
+ printer .terraformSkipParents = true
129
+ printer .terraformSkipChildren = true
120
130
case "" :
121
131
default :
122
- return fmt .Errorf ("invalid option %s for terraform outout. Valid options are: %s" , opts , PrinterOptTerraformWithChildren )
132
+ return fmt .Errorf ("invalid option %s for terraform outout. Valid options are: %s and %s " , opts , PrinterOptTerraformSkipParents , PrinterOptTerraformSkipChildren )
123
133
}
124
134
125
135
terraformVersion , err := terraform .GetLocalClientVersion ()
@@ -173,8 +183,10 @@ type Printer struct {
173
183
// Enable pretty print on json output
174
184
jsonPretty bool
175
185
176
- // Enable children fetching on terraform output
177
- terraformWithChildren bool
186
+ // Disable children fetching on terraform output
187
+ terraformSkipParents bool
188
+ // Disable children fetching on terraform output
189
+ terraformSkipChildren bool
178
190
179
191
// go template to use on template output
180
192
template * template.Template
@@ -183,7 +195,7 @@ type Printer struct {
183
195
humanFields []string
184
196
}
185
197
186
- func (p * Printer ) Print (data interface {}, opt * human.MarshalOpt ) error {
198
+ func (p * Printer ) Print (client * scw. Client , data interface {}, opt * human.MarshalOpt ) error {
187
199
// No matter the printer type if data is a RawResult we should print it as is.
188
200
if rawResult , isRawResult := data .(RawResult ); isRawResult {
189
201
_ , err := p .stdout .Write (rawResult )
@@ -201,7 +213,7 @@ func (p *Printer) Print(data interface{}, opt *human.MarshalOpt) error {
201
213
case PrinterTypeYAML :
202
214
err = p .printYAML (data )
203
215
case PrinterTypeTerraform :
204
- err = p .printTerraform (data )
216
+ err = p .printTerraform (client , data )
205
217
case PrinterTypeTemplate :
206
218
err = p .printTemplate (data )
207
219
default :
@@ -322,13 +334,18 @@ func (p *Printer) printYAML(data interface{}) error {
322
334
return encoder .Encode (data )
323
335
}
324
336
325
- func (p * Printer ) printTerraform (data interface {}) error {
337
+ func (p * Printer ) printTerraform (client * scw. Client , data interface {}) error {
326
338
writer := p .stdout
327
339
if _ , isError := data .(error ); isError {
328
340
return p .printHuman (data , nil )
329
341
}
330
342
331
- hcl , err := terraform .GetHCL (data )
343
+ hcl , err := terraform .GetHCL (& terraform.GetHCLConfig {
344
+ Client : client ,
345
+ Data : data ,
346
+ SkipParents : p .terraformSkipParents ,
347
+ SkipChildren : p .terraformSkipChildren ,
348
+ })
332
349
if err != nil {
333
350
return err
334
351
}
0 commit comments