@@ -13,6 +13,7 @@ import (
1313 "github.com/scaleway/scaleway-cli/v2/internal/gofields"
1414 "github.com/scaleway/scaleway-cli/v2/internal/human"
1515 "github.com/scaleway/scaleway-cli/v2/internal/terraform"
16+ "github.com/scaleway/scaleway-sdk-go/scw"
1617)
1718
1819// Type defines an formatter format.
@@ -44,8 +45,12 @@ const (
4445 // Option to enable pretty output on json printer.
4546 PrinterOptJSONPretty = "pretty"
4647
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"
4954)
5055
5156type PrinterConfig struct {
@@ -115,11 +120,16 @@ func setupJSONPrinter(printer *Printer, opts string) error {
115120func setupTerraformPrinter (printer * Printer , opts string ) error {
116121 printer .printerType = PrinterTypeTerraform
117122 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
120130 case "" :
121131 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 )
123133 }
124134
125135 terraformVersion , err := terraform .GetLocalClientVersion ()
@@ -173,8 +183,10 @@ type Printer struct {
173183 // Enable pretty print on json output
174184 jsonPretty bool
175185
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
178190
179191 // go template to use on template output
180192 template * template.Template
@@ -183,7 +195,7 @@ type Printer struct {
183195 humanFields []string
184196}
185197
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 {
187199 // No matter the printer type if data is a RawResult we should print it as is.
188200 if rawResult , isRawResult := data .(RawResult ); isRawResult {
189201 _ , err := p .stdout .Write (rawResult )
@@ -201,7 +213,7 @@ func (p *Printer) Print(data interface{}, opt *human.MarshalOpt) error {
201213 case PrinterTypeYAML :
202214 err = p .printYAML (data )
203215 case PrinterTypeTerraform :
204- err = p .printTerraform (data )
216+ err = p .printTerraform (client , data )
205217 case PrinterTypeTemplate :
206218 err = p .printTemplate (data )
207219 default :
@@ -322,13 +334,18 @@ func (p *Printer) printYAML(data interface{}) error {
322334 return encoder .Encode (data )
323335}
324336
325- func (p * Printer ) printTerraform (data interface {}) error {
337+ func (p * Printer ) printTerraform (client * scw. Client , data interface {}) error {
326338 writer := p .stdout
327339 if _ , isError := data .(error ); isError {
328340 return p .printHuman (data , nil )
329341 }
330342
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+ })
332349 if err != nil {
333350 return err
334351 }
0 commit comments